Skip to content

Commit

Permalink
fix: Send the values not the Values (#197)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
kentquirk authored May 16, 2023
1 parent 5862f43 commit c4bfcfe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions otlp/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions otlp/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
})
Expand Down

0 comments on commit c4bfcfe

Please sign in to comment.