Skip to content

Commit

Permalink
feat: map OTEL's span.status: Unset to event.outcome: success (#188)
Browse files Browse the repository at this point in the history
* feat: set success outcome for Unset status
  • Loading branch information
kyungeunni authored Dec 12, 2023
1 parent 95a858f commit b2a4dab
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 16 deletions.
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()
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)
input.Context.HTTP.StatusCode.Reset()
mapToSpanModel(&input, &out)
assert.Equal(t, "success", out.Event.Outcome)
})

t.Run("timestamp", func(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions input/elasticapm/internal/modeldecoder/v2/transaction_test.go
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
2 changes: 1 addition & 1 deletion input/otlp/test_approved/span_jaeger_custom.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 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

0 comments on commit b2a4dab

Please sign in to comment.