Skip to content

Commit 169686d

Browse files
authored
[pkg/experimentalmetricmetadata] Add missing otel.entity.type fields to delete events (#40279)
Add missing `otel.entity.type` field to the delete events. The type along with the set of identifying attributes forms an entity identity. So it has to be present in all types of entity events. This change adds new fields to the `EntityDeleteDetails`, but the entity type fields will be moved to the event level in the next PR to avoid redundancy in the API
1 parent 54dded5 commit 169686d

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: "bug_fix"
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: pkg/experimentalmetricmetadata
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add missing otel.entity.type field to the delete events
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [40279]
14+
15+
# If your change doesn't affect end users or the exported elements of any package,
16+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
17+
# Optional: The change log or logs in which this entry should be included.
18+
# e.g. '[user]' or '[user, api]'
19+
# Include 'user' if the change is relevant to end users.
20+
# Include 'api' if there is a change to a library API.
21+
# Default: '[user]'
22+
change_logs: [api]

pkg/experimentalmetricmetadata/entity_events.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,18 @@ func (s EntityStateDetails) Interval() time.Duration {
195195
type EntityDeleteDetails struct {
196196
orig plog.LogRecord
197197
}
198+
199+
// EntityType returns the type of the entity.
200+
// TODO: Move the entity type methods to EntityEvent as they are needed for both EntityState and EntityDelete events.
201+
func (d EntityDeleteDetails) EntityType() string {
202+
t, ok := d.orig.Attributes().Get(semconvOtelEntityType)
203+
if !ok {
204+
return ""
205+
}
206+
return t.Str()
207+
}
208+
209+
// SetEntityType sets the type of the entity.
210+
func (d EntityDeleteDetails) SetEntityType(t string) {
211+
d.orig.Attributes().PutStr(semconvOtelEntityType, t)
212+
}

pkg/experimentalmetricmetadata/entity_events_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ func Test_Entity_Delete(t *testing.T) {
4444

4545
event := slice.AppendEmpty()
4646
event.ID().PutStr("k8s.node.uid", "abc")
47-
event.SetEntityDelete()
47+
deleteEvent := event.SetEntityDelete()
48+
deleteEvent.SetEntityType("k8s.node")
4849

4950
actual := slice.At(0)
5051

5152
assert.Equal(t, EventTypeDelete, actual.EventType())
53+
assert.Equal(t, "k8s.node", event.EntityDeleteDetails().EntityType())
5254
v, ok := actual.ID().Get("k8s.node.uid")
5355
assert.True(t, ok)
5456
assert.Equal(t, "abc", v.Str())
@@ -75,7 +77,8 @@ func Test_EntityEventsSlice_ConvertAndMoveToLogs(t *testing.T) {
7577

7678
event = slice.AppendEmpty()
7779
event.ID().PutStr("k8s.node.uid", "abc")
78-
event.SetEntityDelete()
80+
deleteEvent := event.SetEntityDelete()
81+
deleteEvent.SetEntityType("k8s.node")
7982

8083
// Convert to logs.
8184
logs := slice.ConvertAndMoveToLogs()
@@ -112,6 +115,7 @@ func Test_EntityEventsSlice_ConvertAndMoveToLogs(t *testing.T) {
112115
assert.Equal(
113116
t, map[string]any{
114117
semconvOtelEntityEventName: semconvEventEntityEventDelete,
118+
semconvOtelEntityType: "k8s.node",
115119
semconvOtelEntityID: map[string]any{"k8s.node.uid": "abc"},
116120
}, attrs,
117121
)

0 commit comments

Comments
 (0)