Skip to content

Commit 07a8d19

Browse files
MrAliasAneurysm9
andauthored
Fix Jaeger span status reporting and unify tag keys (#1761)
* Fix Jaeger span status reporting and unify tag keys Move all tag key strings to be consts defined in a unified location. Fix the status code and message tag keys to conform with the specification. Do not set the span status message if it is not set to conform with the specification. * Add changes to changelog * Update CHANGELOG.md Co-authored-by: Anthony Mirabella <[email protected]> * Fix misspell Co-authored-by: Anthony Mirabella <[email protected]>
1 parent 4fa35c9 commit 07a8d19

File tree

3 files changed

+57
-17
lines changed

3 files changed

+57
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2626
### Fixed
2727

2828
- The `Span.IsRecording` implementation from `go.opentelemetry.io/otel/sdk/trace` always returns false when not being sampled. (#1750)
29+
- The Jaeger exporter now correctly sets tags for the Span status code and message.
30+
This means it uses the correct tag keys (`"otel.status_code"`, `"otel.status_description"`) and does not set the status message as a tag unless it is set on the span. (#1761)
2931

3032
### Changed
3133

exporters/trace/jaeger/jaeger.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ import (
3737
const (
3838
keyInstrumentationLibraryName = "otel.library.name"
3939
keyInstrumentationLibraryVersion = "otel.library.version"
40+
keyError = "error"
41+
keySpanKind = "span.kind"
42+
keyStatusCode = "otel.status_code"
43+
keyStatusMessage = "otel.status_description"
4044
)
4145

4246
type Option func(*options)
@@ -269,18 +273,18 @@ func spanSnapshotToThrift(ss *export.SpanSnapshot) *gen.Span {
269273

270274
if ss.SpanKind != trace.SpanKindInternal {
271275
tags = append(tags,
272-
getStringTag("span.kind", ss.SpanKind.String()),
276+
getStringTag(keySpanKind, ss.SpanKind.String()),
273277
)
274278
}
275279

276280
if ss.StatusCode != codes.Unset {
277-
tags = append(tags,
278-
getInt64Tag("status.code", int64(ss.StatusCode)),
279-
getStringTag("status.message", ss.StatusMessage),
280-
)
281+
tags = append(tags, getInt64Tag(keyStatusCode, int64(ss.StatusCode)))
282+
if ss.StatusMessage != "" {
283+
tags = append(tags, getStringTag(keyStatusMessage, ss.StatusMessage))
284+
}
281285

282286
if ss.StatusCode == codes.Error {
283-
tags = append(tags, getBoolTag("error", true))
287+
tags = append(tags, getBoolTag(keyError, true))
284288
}
285289
}
286290

exporters/trace/jaeger/jaeger_test.go

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,40 @@ func Test_spanSnapshotToThrift(t *testing.T) {
363363
data *export.SpanSnapshot
364364
want *gen.Span
365365
}{
366+
{
367+
name: "no status description",
368+
data: &export.SpanSnapshot{
369+
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{
370+
TraceID: traceID,
371+
SpanID: spanID,
372+
}),
373+
Name: "/foo",
374+
StartTime: now,
375+
EndTime: now,
376+
StatusCode: codes.Error,
377+
SpanKind: trace.SpanKindClient,
378+
InstrumentationLibrary: instrumentation.Library{
379+
Name: instrLibName,
380+
Version: instrLibVersion,
381+
},
382+
},
383+
want: &gen.Span{
384+
TraceIdLow: 651345242494996240,
385+
TraceIdHigh: 72623859790382856,
386+
SpanId: 72623859790382856,
387+
OperationName: "/foo",
388+
StartTime: now.UnixNano() / 1000,
389+
Duration: 0,
390+
Tags: []*gen.Tag{
391+
{Key: keyError, VType: gen.TagType_BOOL, VBool: &boolTrue},
392+
{Key: keyInstrumentationLibraryName, VType: gen.TagType_STRING, VStr: &instrLibName},
393+
{Key: keyInstrumentationLibraryVersion, VType: gen.TagType_STRING, VStr: &instrLibVersion},
394+
{Key: keyStatusCode, VType: gen.TagType_LONG, VLong: &statusCodeValue},
395+
// Should not have a status message because it was unset
396+
{Key: keySpanKind, VType: gen.TagType_STRING, VStr: &spanKind},
397+
},
398+
},
399+
},
366400
{
367401
name: "no parent",
368402
data: &export.SpanSnapshot{
@@ -408,12 +442,12 @@ func Test_spanSnapshotToThrift(t *testing.T) {
408442
{Key: "double", VType: gen.TagType_DOUBLE, VDouble: &doubleValue},
409443
{Key: "key", VType: gen.TagType_STRING, VStr: &keyValue},
410444
{Key: "int", VType: gen.TagType_LONG, VLong: &intValue},
411-
{Key: "error", VType: gen.TagType_BOOL, VBool: &boolTrue},
412-
{Key: "otel.library.name", VType: gen.TagType_STRING, VStr: &instrLibName},
413-
{Key: "otel.library.version", VType: gen.TagType_STRING, VStr: &instrLibVersion},
414-
{Key: "status.code", VType: gen.TagType_LONG, VLong: &statusCodeValue},
415-
{Key: "status.message", VType: gen.TagType_STRING, VStr: &statusMessage},
416-
{Key: "span.kind", VType: gen.TagType_STRING, VStr: &spanKind},
445+
{Key: keyError, VType: gen.TagType_BOOL, VBool: &boolTrue},
446+
{Key: keyInstrumentationLibraryName, VType: gen.TagType_STRING, VStr: &instrLibName},
447+
{Key: keyInstrumentationLibraryVersion, VType: gen.TagType_STRING, VStr: &instrLibVersion},
448+
{Key: keyStatusCode, VType: gen.TagType_LONG, VLong: &statusCodeValue},
449+
{Key: keyStatusMessage, VType: gen.TagType_STRING, VStr: &statusMessage},
450+
{Key: keySpanKind, VType: gen.TagType_STRING, VStr: &spanKind},
417451
},
418452
References: []*gen.SpanRef{
419453
{
@@ -486,8 +520,8 @@ func Test_spanSnapshotToThrift(t *testing.T) {
486520
Tags: []*gen.Tag{
487521
// status code, message and span kind should NOT be populated
488522
{Key: "arr", VType: gen.TagType_STRING, VStr: &arrValue},
489-
{Key: "otel.library.name", VType: gen.TagType_STRING, VStr: &instrLibName},
490-
{Key: "otel.library.version", VType: gen.TagType_STRING, VStr: &instrLibVersion},
523+
{Key: keyInstrumentationLibraryName, VType: gen.TagType_STRING, VStr: &instrLibName},
524+
{Key: keyInstrumentationLibraryVersion, VType: gen.TagType_STRING, VStr: &instrLibVersion},
491525
},
492526
References: []*gen.SpanRef{
493527
{
@@ -535,8 +569,8 @@ func Test_spanSnapshotToThrift(t *testing.T) {
535569
StartTime: now.UnixNano() / 1000,
536570
Duration: 0,
537571
Tags: []*gen.Tag{
538-
{Key: "otel.library.name", VType: gen.TagType_STRING, VStr: &instrLibName},
539-
{Key: "otel.library.version", VType: gen.TagType_STRING, VStr: &instrLibVersion},
572+
{Key: keyInstrumentationLibraryName, VType: gen.TagType_STRING, VStr: &instrLibName},
573+
{Key: keyInstrumentationLibraryVersion, VType: gen.TagType_STRING, VStr: &instrLibVersion},
540574
},
541575
},
542576
},
@@ -649,7 +683,7 @@ func TestJaegerBatchList(t *testing.T) {
649683
{
650684
OperationName: "s1",
651685
Tags: []*gen.Tag{
652-
{Key: "span.kind", VType: gen.TagType_STRING, VStr: &spanKind},
686+
{Key: keySpanKind, VType: gen.TagType_STRING, VStr: &spanKind},
653687
},
654688
StartTime: now.UnixNano() / 1000,
655689
},

0 commit comments

Comments
 (0)