From fd38e34240ba2fe767ea2595c02952268b719c4c Mon Sep 17 00:00:00 2001 From: Keaton Cross Date: Tue, 23 Apr 2024 14:01:46 -0500 Subject: [PATCH] fix: flatten ValueTypeSlice to ValueTypeString (#831) * fix: flatten ValueTypeSlice to ValueTypeString * fix: use json marshalling for non-primitive values * fix: validate returned errors in tests Co-authored-by: David Ashpole Signed-off-by: Keaton Cross * fix: regenerate test fixtures --------- Signed-off-by: Keaton Cross Co-authored-by: David Ashpole --- .../traces/traces_basic_expected.json | 100 ++++++++++++++++++ .../traces/traces_user_agent_expected.json | 100 ++++++++++++++++++ exporter/collector/spandata.go | 2 + exporter/collector/spandata_test.go | 10 ++ 4 files changed, 212 insertions(+) diff --git a/exporter/collector/integrationtest/testdata/fixtures/traces/traces_basic_expected.json b/exporter/collector/integrationtest/testdata/fixtures/traces/traces_basic_expected.json index 91473dcd6..9cc6e4c1d 100644 --- a/exporter/collector/integrationtest/testdata/fixtures/traces/traces_basic_expected.json +++ b/exporter/collector/integrationtest/testdata/fixtures/traces/traces_basic_expected.json @@ -119,6 +119,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -298,6 +303,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -477,6 +487,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -656,6 +671,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -786,6 +806,11 @@ "value": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -911,6 +936,11 @@ "value": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1036,6 +1066,11 @@ "value": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1161,6 +1196,11 @@ "value": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1257,6 +1297,11 @@ "value": "demo-client-tracer" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1353,6 +1398,11 @@ "value": "demo-client-tracer" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1449,6 +1499,11 @@ "value": "demo-client-tracer" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1545,6 +1600,11 @@ "value": "demo-client-tracer" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1719,6 +1779,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1898,6 +1963,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -2077,6 +2147,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -2212,6 +2287,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -2342,6 +2422,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -2472,6 +2557,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -2602,6 +2692,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -2698,6 +2793,11 @@ "value": "demo-client-tracer" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" diff --git a/exporter/collector/integrationtest/testdata/fixtures/traces/traces_user_agent_expected.json b/exporter/collector/integrationtest/testdata/fixtures/traces/traces_user_agent_expected.json index 44fe89b8a..d5df4d6f1 100644 --- a/exporter/collector/integrationtest/testdata/fixtures/traces/traces_user_agent_expected.json +++ b/exporter/collector/integrationtest/testdata/fixtures/traces/traces_user_agent_expected.json @@ -119,6 +119,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -298,6 +303,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -477,6 +487,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -656,6 +671,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -786,6 +806,11 @@ "value": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -911,6 +936,11 @@ "value": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1036,6 +1066,11 @@ "value": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1161,6 +1196,11 @@ "value": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1257,6 +1297,11 @@ "value": "demo-client-tracer" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1353,6 +1398,11 @@ "value": "demo-client-tracer" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1449,6 +1499,11 @@ "value": "demo-client-tracer" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1545,6 +1600,11 @@ "value": "demo-client-tracer" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1719,6 +1779,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -1898,6 +1963,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -2077,6 +2147,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -2212,6 +2287,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -2342,6 +2422,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -2472,6 +2557,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -2602,6 +2692,11 @@ "value": "semver:0.33.0" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" @@ -2698,6 +2793,11 @@ "value": "demo-client-tracer" } }, + "process.command_args": { + "stringValue": { + "value": "[\"./main\"]" + } + }, "process.executable.name": { "stringValue": { "value": "main" diff --git a/exporter/collector/spandata.go b/exporter/collector/spandata.go index 86b434d68..7e951de89 100644 --- a/exporter/collector/spandata.go +++ b/exporter/collector/spandata.go @@ -149,6 +149,8 @@ func pdataAttributesToOTAttributes(attrs pcommon.Map, resource pcommon.Resource) otAttrs = append(otAttrs, attribute.Int64(k, v.Int())) case pcommon.ValueTypeDouble: otAttrs = append(otAttrs, attribute.Float64(k, v.Double())) + default: + otAttrs = append(otAttrs, attribute.String(k, v.AsString())) } return true }) diff --git a/exporter/collector/spandata_test.go b/exporter/collector/spandata_test.go index f09c314ba..879e3b615 100644 --- a/exporter/collector/spandata_test.go +++ b/exporter/collector/spandata_test.go @@ -15,6 +15,7 @@ package collector import ( + "encoding/json" "testing" "time" @@ -82,9 +83,17 @@ func TestPDataResourceSpansToOTSpanData_endToEnd(t *testing.T) { span.Attributes().PutInt("timeout_ns", 12e9) span.Attributes().PutInt("ping_count", 25) span.Attributes().PutStr("agent", "ocagent") + span.Attributes().PutEmptySlice("header") + strArr := []any{"value1", "value2"} + headerValue, found := span.Attributes().Get("header") + assert.True(t, found) + err := headerValue.Slice().FromRaw(strArr) + assert.NoError(t, err) gotOTSpanData := pdataResourceSpansToOTSpanData(rs) + jsonStr, err := json.Marshal(strArr) + assert.NoError(t, err) wantOTSpanData := &spanSnapshot{ spanContext: apitrace.NewSpanContext(apitrace.SpanContextConfig{ TraceID: apitrace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, @@ -136,6 +145,7 @@ func TestPDataResourceSpansToOTSpanData_endToEnd(t *testing.T) { attribute.String("agent", "ocagent"), attribute.Bool("cache_hit", true), attribute.Int64("timeout_ns", 12e9), + attribute.String("header", string(jsonStr)), }, instrumentationLibrary: instrumentation.Library{ Name: "test_il_name",