Skip to content

Commit 9766573

Browse files
committed
feat(otel-2647): add tests and update setAttributes logic
1 parent 41fbab6 commit 9766573

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

receiver/datadogrumreceiver/internal/translator/rum_translator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func setAttributes(flatPayload map[string]any, attributes pcommon.Map) {
494494
if o, ok := val.(map[string]any); ok {
495495
objVal := attributes.PutEmptyMap(meta.OTLPName)
496496
for k, v := range o {
497-
objVal.PutStr(meta.OTLPName+k, v.(string))
497+
objVal.PutStr(k, fmt.Sprintf("%v", v))
498498
}
499499
}
500500
case ArrayAttribute:

receiver/datadogrumreceiver/internal/translator/rum_translator_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,26 @@ func TestParseW3CTraceContext(t *testing.T) {
1818
assert.Equal(t, traceID, pcommon.TraceID([16]byte{0x4b, 0xf9, 0x2f, 0x35, 0x77, 0xb3, 0x4d, 0xa6, 0xa3, 0xce, 0x92, 0x9d, 0x0e, 0x0e, 0x47, 0x36}))
1919
assert.Equal(t, spanID, pcommon.SpanID([8]byte{0x00, 0xf0, 0x67, 0xaa, 0x0b, 0xa9, 0x02, 0xb7}))
2020
}
21+
22+
func TestSetAttributes(t *testing.T) {
23+
payload := map[string]any{
24+
"action.id": []any{"123", "456"},
25+
"view.loading_time": 123,
26+
"view.in_foreground": true,
27+
"context": map[string]any{"browser.name": "chrome"},
28+
}
29+
attributes := pcommon.NewMap()
30+
setAttributes(payload, attributes)
31+
32+
actionID, _ := attributes.Get("datadog.action.id")
33+
assert.Equal(t, []any{"123", "456"}, actionID.Slice().AsRaw())
34+
35+
viewLoadingTime, _ := attributes.Get("datadog.view.loading_time")
36+
assert.Equal(t, 123, int(viewLoadingTime.AsRaw().(int64)))
37+
38+
viewInForeground, _ := attributes.Get("datadog.view.in_foreground")
39+
assert.Equal(t, true, viewInForeground.AsRaw().(bool))
40+
41+
context, _ := attributes.Get("datadog.context")
42+
assert.Equal(t, "chrome", context.Map().AsRaw()["browser.name"])
43+
}

0 commit comments

Comments
 (0)