Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: map OTEL's span.status: Unset to event.outcome: success #188

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions input/elasticapm/internal/modeldecoder/v2/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,16 @@ func TestDecodeMapToSpanModel(t *testing.T) {
assert.Equal(t, "failure", out.Event.Outcome)
// derive from other fields - unknown
input.Outcome.Reset()
input.OTel.Reset()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change was only made to OTel input for now, so I needed to reset the Otel attributes here so we don't get confused why it affects also elasticapm input

input.Context.HTTP.StatusCode.Reset()
mapToSpanModel(&input, &out)
assert.Equal(t, "unknown", out.Event.Outcome)
// outcome is success when not assigned and it's otel
input.Outcome.Reset()
input.OTel.SpanKind.Set(spanKindInternal)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change was only made to OTel input for now, if otel attributes are set, it will use the same logic for mapping the Unset status to success outcome

input.Context.HTTP.StatusCode.Reset()
mapToSpanModel(&input, &out)
assert.Equal(t, "success", out.Event.Outcome)
})

t.Run("timestamp", func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,16 @@ func TestDecodeMapToTransactionModel(t *testing.T) {
assert.Equal(t, "failure", out.Event.Outcome)
// derive from other fields - unknown
input.Outcome.Reset()
input.OTel.Reset()
input.Context.Response.StatusCode.Reset()
mapToTransactionModel(&input, &out)
assert.Equal(t, "unknown", out.Event.Outcome)
// outcome is success when not assigned and it's otel
input.Outcome.Reset()
input.OTel.SpanKind.Set(spanKindInternal)
input.Context.Response.StatusCode.Reset()
mapToTransactionModel(&input, &out)
assert.Equal(t, "success", out.Event.Outcome)
})

t.Run("session", func(t *testing.T) {
Expand Down
10 changes: 6 additions & 4 deletions input/otlp/test_approved/jaeger_sampling_rate.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"event": {
"duration": 79000000000,
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-abc"
Expand All @@ -24,6 +24,7 @@
},
"transaction": {
"representative_count": 1.25,
"result": "Success",
"sampled": true,
"type": "unknown"
}
Expand All @@ -36,7 +37,7 @@
},
"event": {
"duration": 79000000000,
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-abc"
Expand Down Expand Up @@ -69,7 +70,7 @@
},
"event": {
"duration": 79000000000,
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-abc"
Expand All @@ -91,6 +92,7 @@
},
"transaction": {
"sampled": true,
"result": "Success",
"type": "unknown"
}
},
Expand All @@ -102,7 +104,7 @@
},
"event": {
"duration": 79000000000,
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-abc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"version": "3.4.12"
},
"event": {
"outcome": "unknown"
"outcome": "success"
},
"service": {
"language": {
Expand All @@ -28,6 +28,7 @@
"id": "0000000041414646",
"representative_count": 1,
"sampled": true,
"result": "Success",
"type": "unknown"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"version": "3.4.12"
},
"event": {
"outcome": "unknown"
"outcome": "success"
},
"service": {
"language": {
Expand All @@ -28,6 +28,7 @@
"id": "0000000041414646",
"representative_count": 1,
"sampled": true,
"result": "Success",
"type": "unknown"
}
}
Expand Down
3 changes: 2 additions & 1 deletion input/otlp/test_approved/metadata_jaeger.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"version": "3.2.1"
},
"event": {
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-foo",
Expand Down Expand Up @@ -39,6 +39,7 @@
"id": "0000000041414646",
"representative_count": 1,
"sampled": true,
"result": "Success",
"type": "unknown"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"event": {
"duration": 79000000000,
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-abc"
Expand Down
2 changes: 1 addition & 1 deletion input/otlp/test_approved/span_jaeger_db.approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"event": {
"duration": 79000000000,
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-abc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"event": {
"duration": 79000000000,
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-abc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"event": {
"duration": 79000000000,
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-abc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"event": {
"duration": 79000000000,
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-abc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"version": "unknown"
},
"event": {
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-abc"
Expand All @@ -27,6 +27,7 @@
"transaction": {
"representative_count": 1,
"sampled": true,
"result": "Success",
"type": "unknown"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"version": "unknown"
},
"event": {
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-abc"
Expand All @@ -27,6 +27,7 @@
"transaction": {
"representative_count": 1,
"sampled": true,
"result": "Success",
"type": "unknown"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"version": "unknown"
},
"event": {
"outcome": "unknown"
"outcome": "success"
},
"host": {
"hostname": "host-abc"
Expand All @@ -31,6 +31,7 @@
}
},
"representative_count": 1,
"result": "Success",
"sampled": true,
"type": "messaging"
}
Expand Down
13 changes: 13 additions & 0 deletions input/otlp/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,14 @@ func TranslateTransaction(
event.Service.Framework.Name = name
event.Service.Framework.Version = library.Version()
}

// if outcome and result are still not assigned, assign success
if event.Event.Outcome == outcomeUnknown {
event.Event.Outcome = outcomeSuccess
if event.Transaction.Result == "" {
event.Transaction.Result = "Success"
}
}
}

// TranslateSpan converts incoming otlp/otel trace data into the
Expand Down Expand Up @@ -945,6 +953,11 @@ func TranslateSpan(spanKind ptrace.SpanKind, attributes pcommon.Map, event *mode
// The client has reported its sampling rate, so we can use it to extrapolate transaction metrics.
parseSamplerAttributes(samplerType, samplerParam, event)
}

// if outcome is still not assigned, assign success
if event.Event.Outcome == outcomeUnknown {
event.Event.Outcome = outcomeSuccess
}
}

func parseSamplerAttributes(samplerType, samplerParam pcommon.Value, event *modelpb.APMEvent) {
Expand Down
2 changes: 1 addition & 1 deletion input/otlp/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestOutcome(t *testing.T) {
assert.Equal(t, expectedOutcome, (*batch)[1].GetEvent().GetOutcome())
}

test(t, "unknown", "", ptrace.StatusCodeUnset)
test(t, "success", "Success", ptrace.StatusCodeUnset)
test(t, "success", "Success", ptrace.StatusCodeOk)
test(t, "failure", "Error", ptrace.StatusCodeError)
}
Expand Down
Loading