Skip to content

Commit 7da7886

Browse files
authored
Change semantic conventions for status (code, msg) as per specifications (#3872)
Deprecate the old values and replace with the new value defined by the specification. This may be a breaking change for backends that expect this value. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/non-otlp.md Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 95145ff commit 7da7886

18 files changed

+91
-76
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## 🛑 Breaking changes 🛑
6+
7+
- Change semantic conventions for status (code, msg) as per specifications (#3872)
8+
59
## v0.33.0 Beta
610

711
## 🛑 Breaking changes 🛑

receiver/jaegerreceiver/trace_receiver_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import (
5353
"go.opentelemetry.io/collector/obsreport"
5454
"go.opentelemetry.io/collector/testutil"
5555
conventions "go.opentelemetry.io/collector/translator/conventions/v1.5.0"
56-
tracetranslator "go.opentelemetry.io/collector/translator/trace"
5756
"go.opentelemetry.io/collector/translator/trace/jaeger"
5857
)
5958

@@ -355,8 +354,8 @@ func grpcFixture(t1 time.Time, d1, d2 time.Duration) *api_v2.PostSpansRequest {
355354
StartTime: t1,
356355
Duration: d1,
357356
Tags: []model.KeyValue{
358-
model.String(tracetranslator.TagStatusMsg, "Stale indices"),
359-
model.Int64(tracetranslator.TagStatusCode, int64(pdata.StatusCodeError)),
357+
model.String(conventions.OtelStatusDescription, "Stale indices"),
358+
model.Int64(conventions.OtelStatusCode, int64(pdata.StatusCodeError)),
360359
model.Bool("error", true),
361360
},
362361
References: []model.SpanRef{
@@ -374,8 +373,8 @@ func grpcFixture(t1 time.Time, d1, d2 time.Duration) *api_v2.PostSpansRequest {
374373
StartTime: t1.Add(d1),
375374
Duration: d2,
376375
Tags: []model.KeyValue{
377-
model.String(tracetranslator.TagStatusMsg, "Frontend crash"),
378-
model.Int64(tracetranslator.TagStatusCode, int64(pdata.StatusCodeError)),
376+
model.String(conventions.OtelStatusDescription, "Frontend crash"),
377+
model.Int64(conventions.OtelStatusCode, int64(pdata.StatusCodeError)),
379378
model.Bool("error", true),
380379
},
381380
},

receiver/zipkinreceiver/trace_receiver_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func TestConversionRoundtrip(t *testing.T) {
170170
"tags": {
171171
"http.path": "/api",
172172
"clnt/finagle.version": "6.45.0",
173-
"status.code": "STATUS_CODE_UNSET"
173+
"otel.status_code": "STATUS_CODE_UNSET"
174174
}
175175
},
176176
{
@@ -203,7 +203,7 @@ func TestConversionRoundtrip(t *testing.T) {
203203
"tags": {
204204
"http.path": "/api",
205205
"clnt/finagle.version": "6.45.0",
206-
"status.code": "STATUS_CODE_UNSET"
206+
"otel.status_code": "STATUS_CODE_UNSET"
207207
}
208208
}]`)
209209

translator/conventions/v1.5.0/nonstandard.go

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ const (
1919
InstrumentationLibraryVersion = "otel.library.version"
2020
)
2121

22+
const (
23+
OtelStatusCode = "otel.status_code"
24+
OtelStatusDescription = "otel.status_description"
25+
)
26+
2227
const (
2328
AttributeMessageType = "message.type"
2429
AttributeHTTPStatusText = "http.status_text"

translator/internaldata/oc_to_traces.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ func ocStatusToInternal(ocStatus *octrace.Status, ocAttrs *octrace.Span_Attribut
175175
}
176176

177177
if ocAttrs != nil {
178-
// tracetranslator.TagStatusCode is set it must override the status code value.
178+
// If conventions.OtelStatusCode is set, it must override the status code value.
179179
// See the reverse translation in traces_to_oc.go:statusToOC().
180-
if attr, ok := ocAttrs.AttributeMap[tracetranslator.TagStatusCode]; ok {
180+
if attr, ok := ocAttrs.AttributeMap[conventions.OtelStatusCode]; ok {
181181
code = pdata.StatusCode(attr.GetIntValue())
182-
delete(ocAttrs.AttributeMap, tracetranslator.TagStatusCode)
182+
delete(ocAttrs.AttributeMap, conventions.OtelStatusCode)
183183
}
184184
}
185185

translator/internaldata/traces_to_oc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func spanToOC(span pdata.Span) *octrace.Span {
7878
DroppedAttributesCount: 0,
7979
}
8080
}
81-
attributes.AttributeMap[tracetranslator.TagStatusCode] = statusAttr
81+
attributes.AttributeMap[conventions.OtelStatusCode] = statusAttr
8282
}
8383

8484
return &octrace.Span{

translator/trace/jaeger/jaegerproto_to_traces.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,15 @@ func setInternalSpanStatus(attrs pdata.AttributeMap, dest pdata.SpanStatus) {
221221
}
222222
}
223223

224-
if codeAttr, ok := attrs.Get(tracetranslator.TagStatusCode); ok {
224+
if codeAttr, ok := attrs.Get(conventions.OtelStatusCode); ok {
225225
statusExists = true
226226
if code, err := getStatusCodeValFromAttr(codeAttr); err == nil {
227227
statusCode = pdata.StatusCode(code)
228-
attrs.Delete(tracetranslator.TagStatusCode)
228+
attrs.Delete(conventions.OtelStatusCode)
229229
}
230-
if msgAttr, ok := attrs.Get(tracetranslator.TagStatusMsg); ok {
230+
if msgAttr, ok := attrs.Get(conventions.OtelStatusDescription); ok {
231231
statusMessage = msgAttr.StringVal()
232-
attrs.Delete(tracetranslator.TagStatusMsg)
232+
attrs.Delete(conventions.OtelStatusDescription)
233233
}
234234
} else if httpCodeAttr, ok := attrs.Get(conventions.AttributeHTTPStatusCode); ok {
235235
statusExists = true

translator/trace/jaeger/jaegerproto_to_traces_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -365,17 +365,17 @@ func TestSetInternalSpanStatus(t *testing.T) {
365365
{
366366
name: "status.code is set as int",
367367
attrs: pdata.NewAttributeMap().InitFromMap(map[string]pdata.AttributeValue{
368-
tracetranslator.TagStatusCode: pdata.NewAttributeValueInt(1),
368+
conventions.OtelStatusCode: pdata.NewAttributeValueInt(1),
369369
}),
370370
status: okStatus,
371371
attrsModifiedLen: 0,
372372
},
373373
{
374374
name: "status.code, status.message and error tags are set",
375375
attrs: pdata.NewAttributeMap().InitFromMap(map[string]pdata.AttributeValue{
376-
tracetranslator.TagError: pdata.NewAttributeValueBool(true),
377-
tracetranslator.TagStatusCode: pdata.NewAttributeValueInt(int64(pdata.StatusCodeError)),
378-
tracetranslator.TagStatusMsg: pdata.NewAttributeValueString("Error: Invalid argument"),
376+
tracetranslator.TagError: pdata.NewAttributeValueBool(true),
377+
conventions.OtelStatusCode: pdata.NewAttributeValueInt(int64(pdata.StatusCodeError)),
378+
conventions.OtelStatusDescription: pdata.NewAttributeValueString("Error: Invalid argument"),
379379
}),
380380
status: errorStatusWithMessage,
381381
attrsModifiedLen: 0,
@@ -401,7 +401,7 @@ func TestSetInternalSpanStatus(t *testing.T) {
401401
{
402402
name: "status.code has precedence over http.status_code.",
403403
attrs: pdata.NewAttributeMap().InitFromMap(map[string]pdata.AttributeValue{
404-
tracetranslator.TagStatusCode: pdata.NewAttributeValueInt(1),
404+
conventions.OtelStatusCode: pdata.NewAttributeValueInt(1),
405405
conventions.AttributeHTTPStatusCode: pdata.NewAttributeValueInt(500),
406406
tracetranslator.TagHTTPStatusMsg: pdata.NewAttributeValueString("Server Error"),
407407
}),
@@ -606,7 +606,7 @@ func generateProtoSpan() *model.Span {
606606
VStr: string(tracetranslator.OpenTracingSpanKindClient),
607607
},
608608
{
609-
Key: tracetranslator.TagStatusCode,
609+
Key: conventions.OtelStatusCode,
610610
VType: model.ValueType_INT64,
611611
VInt64: int64(pdata.StatusCodeError),
612612
},
@@ -616,7 +616,7 @@ func generateProtoSpan() *model.Span {
616616
VType: model.ValueType_BOOL,
617617
},
618618
{
619-
Key: tracetranslator.TagStatusMsg,
619+
Key: conventions.OtelStatusDescription,
620620
VType: model.ValueType_STRING,
621621
VStr: "status-cancelled",
622622
},
@@ -684,7 +684,7 @@ func generateProtoSpanWithTraceState() *model.Span {
684684
VStr: string(tracetranslator.OpenTracingSpanKindClient),
685685
},
686686
{
687-
Key: tracetranslator.TagStatusCode,
687+
Key: conventions.OtelStatusCode,
688688
VType: model.ValueType_INT64,
689689
VInt64: int64(pdata.StatusCodeError),
690690
},
@@ -694,7 +694,7 @@ func generateProtoSpanWithTraceState() *model.Span {
694694
VType: model.ValueType_BOOL,
695695
},
696696
{
697-
Key: tracetranslator.TagStatusMsg,
697+
Key: conventions.OtelStatusDescription,
698698
VType: model.ValueType_STRING,
699699
VStr: "status-cancelled",
700700
},
@@ -797,12 +797,12 @@ func generateProtoFollowerSpan() *model.Span {
797797
VStr: string(tracetranslator.OpenTracingSpanKindConsumer),
798798
},
799799
{
800-
Key: tracetranslator.TagStatusCode,
800+
Key: conventions.OtelStatusCode,
801801
VType: model.ValueType_INT64,
802802
VInt64: int64(pdata.StatusCodeOk),
803803
},
804804
{
805-
Key: tracetranslator.TagStatusMsg,
805+
Key: conventions.OtelStatusDescription,
806806
VType: model.ValueType_STRING,
807807
VStr: "status-ok",
808808
},

translator/trace/jaeger/jaegerthrift_to_traces_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,12 @@ func generateThriftSpan() *jaeger.Span {
195195
},
196196
Tags: []*jaeger.Tag{
197197
{
198-
Key: tracetranslator.TagStatusCode,
198+
Key: conventions.OtelStatusCode,
199199
VType: jaeger.TagType_LONG,
200200
VLong: &statusCode,
201201
},
202202
{
203-
Key: tracetranslator.TagStatusMsg,
203+
Key: conventions.OtelStatusDescription,
204204
VType: jaeger.TagType_STRING,
205205
VStr: &statusMsg,
206206
},
@@ -256,12 +256,12 @@ func generateThriftFollowerSpan() *jaeger.Span {
256256
Duration: 1000,
257257
Tags: []*jaeger.Tag{
258258
{
259-
Key: tracetranslator.TagStatusCode,
259+
Key: conventions.OtelStatusCode,
260260
VType: jaeger.TagType_LONG,
261261
VLong: &statusCode,
262262
},
263263
{
264-
Key: tracetranslator.TagStatusMsg,
264+
Key: conventions.OtelStatusDescription,
265265
VType: jaeger.TagType_STRING,
266266
VStr: &statusMsg,
267267
},

translator/trace/jaeger/traces_to_jaegerproto.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func getTagFromSpanKind(spanKind pdata.SpanKind) (model.KeyValue, bool) {
382382

383383
func getTagFromStatusCode(statusCode pdata.StatusCode) (model.KeyValue, bool) {
384384
return model.KeyValue{
385-
Key: tracetranslator.TagStatusCode,
385+
Key: conventions.OtelStatusCode,
386386
VInt64: int64(statusCode),
387387
VType: model.ValueType_INT64,
388388
}, true
@@ -405,7 +405,7 @@ func getTagFromStatusMsg(statusMsg string) (model.KeyValue, bool) {
405405
return model.KeyValue{}, false
406406
}
407407
return model.KeyValue{
408-
Key: tracetranslator.TagStatusMsg,
408+
Key: conventions.OtelStatusDescription,
409409
VStr: statusMsg,
410410
VType: model.ValueType_STRING,
411411
}, true

translator/trace/jaeger/traces_to_jaegerproto_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestGetTagFromStatusCode(t *testing.T) {
3737
name: "ok",
3838
code: pdata.StatusCodeOk,
3939
tag: model.KeyValue{
40-
Key: tracetranslator.TagStatusCode,
40+
Key: conventions.OtelStatusCode,
4141
VInt64: int64(pdata.StatusCodeOk),
4242
VType: model.ValueType_INT64,
4343
},
@@ -47,7 +47,7 @@ func TestGetTagFromStatusCode(t *testing.T) {
4747
name: "error",
4848
code: pdata.StatusCodeError,
4949
tag: model.KeyValue{
50-
Key: tracetranslator.TagStatusCode,
50+
Key: conventions.OtelStatusCode,
5151
VInt64: int64(pdata.StatusCodeError),
5252
VType: model.ValueType_INT64,
5353
},
@@ -88,7 +88,7 @@ func TestGetTagFromStatusMsg(t *testing.T) {
8888
got, ok := getTagFromStatusMsg("test-error")
8989
assert.True(t, ok)
9090
assert.EqualValues(t, model.KeyValue{
91-
Key: tracetranslator.TagStatusMsg,
91+
Key: conventions.OtelStatusDescription,
9292
VStr: "test-error",
9393
VType: model.ValueType_STRING,
9494
}, got)
@@ -339,7 +339,7 @@ func TestInternalTracesToJaegerProtoBatchesAndBack(t *testing.T) {
339339
func generateProtoChildSpanWithErrorTags() *model.Span {
340340
span := generateProtoChildSpan()
341341
span.Tags = append(span.Tags, model.KeyValue{
342-
Key: tracetranslator.TagStatusCode,
342+
Key: conventions.OtelStatusCode,
343343
VType: model.ValueType_INT64,
344344
VInt64: int64(pdata.StatusCodeError),
345345
})

translator/trace/protospan_translation.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package tracetranslator
1616

1717
import (
1818
"go.opentelemetry.io/collector/model/pdata"
19+
conventions "go.opentelemetry.io/collector/translator/conventions/v1.5.0"
1920
)
2021

2122
// Some of the keys used to represent OTLP constructs as tags or annotations in other formats.
@@ -24,14 +25,19 @@ const (
2425

2526
TagSpanKind = "span.kind"
2627

27-
TagStatusCode = "status.code"
28-
TagStatusMsg = "status.message"
2928
TagError = "error"
3029
TagHTTPStatusMsg = "http.status_message"
3130

3231
TagW3CTraceState = "w3c.tracestate"
3332
)
3433

34+
const (
35+
// Deprecated: Use conventions.OtelStatusCode
36+
TagStatusCode = conventions.OtelStatusCode
37+
// Deprecated: Use conventions.OtelStatusDescription
38+
TagStatusMsg = conventions.OtelStatusDescription
39+
)
40+
3541
// Constants used for signifying batch-level attribute values where not supplied by OTLP data but required
3642
// by other protocols.
3743
const (

0 commit comments

Comments
 (0)