Skip to content

Commit e2435ee

Browse files
committed
[OTEL-2540] update SpanContext JSON tags to match OTel API Specification
1 parent 008f338 commit e2435ee

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
3434
- `go.opentelemetry.io/otel/sdk/log/logtest` is now a separate Go module. (#6466)
3535
- `Recorder` in `go.opentelemetry.io/otel/log/logtest` no longer separately stores records emitted by loggers with the same instrumentation scope. (#6507)
3636
- Improve performance of `BatchProcessor` in `go.opentelemetry.io/otel/sdk/log` by not exporting when exporter cannot accept more. (#6569, #6641)
37+
- Update JSON tags for `TraceId`, `SpanId`, and `IsRemote` in `go.opentelemetry.io/otel/trace` to match [OpenTelemetry API specification for SpanContext items](https://github.com/open-telemetry/opentelemetry-specification/blob/815598814f3cf461ad5493ccbddd53633fb5cf24/specification/trace/api.md#spancontext) (#6738)
3738

3839
### Deprecated
3940

exporters/stdout/stdouttrace/trace_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,18 @@ func expectedJSON(now time.Time) string {
106106
return `{
107107
"Name": "/foo",
108108
"SpanContext": {
109-
"TraceID": "0102030405060708090a0b0c0d0e0f10",
110-
"SpanID": "0102030405060708",
109+
"TraceId": "0102030405060708090a0b0c0d0e0f10",
110+
"SpanId": "0102030405060708",
111111
"TraceFlags": "00",
112112
"TraceState": "key=val",
113-
"Remote": false
113+
"IsRemote": false
114114
},
115115
"Parent": {
116-
"TraceID": "00000000000000000000000000000000",
117-
"SpanID": "0000000000000000",
116+
"TraceId": "00000000000000000000000000000000",
117+
"SpanId": "0000000000000000",
118118
"TraceFlags": "00",
119119
"TraceState": "",
120-
"Remote": false
120+
"IsRemote": false
121121
},
122122
"SpanKind": 1,
123123
"StartTime": ` + string(serializedNow) + `,

trace/trace.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,14 @@ func (tf *TraceFlags) UnmarshalJSON(data []byte) error {
230230

231231
// SpanContextConfig contains mutable fields usable for constructing
232232
// an immutable SpanContext.
233+
// JSON tags match OTel API Specification:
234+
// https://github.com/open-telemetry/opentelemetry-specification/blob/815598814f3cf461ad5493ccbddd53633fb5cf24/specification/trace/api.md#spancontext
233235
type SpanContextConfig struct {
234-
TraceID TraceID
235-
SpanID SpanID
236-
TraceFlags TraceFlags
237-
TraceState TraceState
238-
Remote bool
236+
TraceID TraceID `json:"TraceId"`
237+
SpanID SpanID `json:"SpanId"`
238+
TraceFlags TraceFlags `json:"TraceFlags"`
239+
TraceState TraceState `json:"TraceState"`
240+
Remote bool `json:"IsRemote"`
239241
}
240242

241243
// NewSpanContext constructs a SpanContext using values from the provided

trace/trace_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func TestSpanContextMarshalJSON(t *testing.T) {
151151
name: "SpanContext.MarshalJSON() returns json with partial data",
152152
tid: [16]byte{1},
153153
sid: [8]byte{42},
154-
want: []byte(`{"TraceID":"01000000000000000000000000000000","SpanID":"2a00000000000000","TraceFlags":"00","TraceState":"","Remote":false}`),
154+
want: []byte(`{"TraceId":"01000000000000000000000000000000","SpanId":"2a00000000000000","TraceFlags":"00","TraceState":"","IsRemote":false}`),
155155
},
156156
{
157157
name: "SpanContext.MarshalJSON() returns json with full data",
@@ -162,7 +162,7 @@ func TestSpanContextMarshalJSON(t *testing.T) {
162162
tstate: TraceState{list: []member{
163163
{Key: "foo", Value: "1"},
164164
}},
165-
want: []byte(`{"TraceID":"01000000000000000000000000000000","SpanID":"2a00000000000000","TraceFlags":"01","TraceState":"foo=1","Remote":true}`),
165+
want: []byte(`{"TraceId":"01000000000000000000000000000000","SpanId":"2a00000000000000","TraceFlags":"01","TraceState":"foo=1","IsRemote":true}`),
166166
},
167167
} {
168168
t.Run(testcase.name, func(t *testing.T) {
@@ -761,7 +761,7 @@ func TestSpanContextUnmarshalJSON(t *testing.T) {
761761
}{
762762
{
763763
name: "valid full SpanContext",
764-
input: `{"TraceID":"01000000000000000000000000000000","SpanID":"2a00000000000000","TraceFlags":"01","TraceState":"foo=1","Remote":true}`,
764+
input: `{"TraceId":"01000000000000000000000000000000","SpanId":"2a00000000000000","TraceFlags":"01","TraceState":"foo=1","IsRemote":true}`,
765765
want: NewSpanContext(SpanContextConfig{
766766
TraceID: TraceID{0x01},
767767
SpanID: SpanID{0x2a},
@@ -772,20 +772,20 @@ func TestSpanContextUnmarshalJSON(t *testing.T) {
772772
},
773773
{
774774
name: "valid partial SpanContext",
775-
input: `{"TraceID":"01000000000000000000000000000000","SpanID":"2a00000000000000"}`,
775+
input: `{"TraceId":"01000000000000000000000000000000","SpanId":"2a00000000000000"}`,
776776
want: NewSpanContext(SpanContextConfig{
777777
TraceID: TraceID{0x01},
778778
SpanID: SpanID{0x2a},
779779
}),
780780
},
781781
{
782782
name: "invalid TraceID",
783-
input: `{"TraceID":"00000000000000000000000000000000","SpanID":"2a00000000000000"}`,
783+
input: `{"TraceId":"00000000000000000000000000000000","SpanId":"2a00000000000000"}`,
784784
wantErr: true,
785785
},
786786
{
787787
name: "invalid JSON",
788-
input: `{"TraceID:123}`,
788+
input: `{"TraceId:123}`,
789789
wantErr: true,
790790
},
791791
}

0 commit comments

Comments
 (0)