From c4bfcfe1e87b92347d2f9086c890bc297fe8d5ee Mon Sep 17 00:00:00 2001 From: Kent Quirk Date: Tue, 16 May 2023 14:47:47 -0400 Subject: [PATCH] fix: Send the values not the Values (#197) ## Which problem is this PR solving? - The new exception code was sending stringized json data for Value objects, instead of the actual values. This fixes that. ## Short description of the changes - Decode the values into the right types - Fix the tests. --- otlp/traces.go | 9 +++++++-- otlp/traces_test.go | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/otlp/traces.go b/otlp/traces.go index 5db1083..1007bc9 100644 --- a/otlp/traces.go +++ b/otlp/traces.go @@ -131,10 +131,15 @@ func TranslateTraceRequest(request *collectorTrace.ExportTraceServiceRequest, ri if sevent.Name == "exception" { for _, seventAttr := range sevent.Attributes { switch seventAttr.Key { - case "exception.message", "exception.type", "exception.stacktrace", "exception.escaped": + case "exception.message", "exception.type", "exception.stacktrace": // don't overwrite if the value is already on the span if _, present := eventAttrs[seventAttr.Key]; !present { - eventAttrs[seventAttr.Key] = seventAttr.Value + eventAttrs[seventAttr.Key] = seventAttr.Value.GetStringValue() + } + case "exception.escaped": + // don't overwrite if the value is already on the span + if _, present := eventAttrs[seventAttr.Key]; !present { + eventAttrs[seventAttr.Key] = seventAttr.Value.GetBoolValue() } } } diff --git a/otlp/traces_test.go b/otlp/traces_test.go index 5850c71..6ed61f7 100644 --- a/otlp/traces_test.go +++ b/otlp/traces_test.go @@ -341,6 +341,10 @@ func TestTranslateException(t *testing.T) { assert.Equal(t, int(trace.Status_STATUS_CODE_OK), ev.Attributes["status_code"]) assert.Equal(t, "span_attr_val", ev.Attributes["span_attr"]) assert.Equal(t, "resource_attr_val", ev.Attributes["resource_attr"]) + assert.Equal(t, true, ev.Attributes["exception.escaped"]) + assert.Equal(t, "aaaaaaa!!", ev.Attributes["exception.message"]) + assert.Equal(t, "something_broke", ev.Attributes["exception.type"]) + assert.Equal(t, "this stacktrace should be long", ev.Attributes["exception.stacktrace"]) assert.Equal(t, 0, ev.Attributes["span.num_links"]) assert.Equal(t, 1, ev.Attributes["span.num_events"]) })