Skip to content

Commit 3a432e9

Browse files
committed
Merge branch '1618-ForceFlushAborts' of https://github.com/humivo/opentelemetry-go into 1618-ForceFlushAborts
2 parents 65cf934 + 23908b4 commit 3a432e9

File tree

16 files changed

+191
-236
lines changed

16 files changed

+191
-236
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1313
- Jaeger exporter was updated to use thrift v0.14.1. (#1712)
1414
- Migrate from using internally built and maintained version of the OTLP to the one hosted at `go.opentelemetry.io/proto/otlp`. (#1713)
1515
- Migrate from using `github.com/gogo/protobuf` to `google.golang.org/protobuf` to match `go.opentelemetry.io/proto/otlp`. (#1713)
16+
- The storage of a local or remote Span in a `context.Context` using its SpanContext is unified to store just the current Span.
17+
The Span's SpanContext can now self-identify as being remote or not.
18+
This means that `"go.opentelemetry.io/otel/trace".ContextWithRemoteSpanContext` will now overwrite any existing current Span, not just existing remote Spans, and make it the current Span in a `context.Context`. (#1731)
1619
- Modify `BatchSpanProcessor.ForceFlush` to abort after timeout/cancellation (#TBD)
1720

1821
### Removed
@@ -21,6 +24,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2124
This is unspecified behavior that the OpenTelemetry community plans to standardize in the future.
2225
To prevent backwards incompatible changes when it is specified, these links are removed. (#1726)
2326
- Setting error status while recording error with Span from oteltest package. (#1729)
27+
- The concept of a remote and local Span stored in a context is unified to just the current Span.
28+
Because of this `"go.opentelemetry.io/otel/trace".RemoteSpanContextFromContext` is removed as it is no longer needed.
29+
Instead, `"go.opentelemetry.io/otel/trace".SpanContextFromContex` can be used to return the current Span.
30+
If needed, that Span's `SpanContext.IsRemote()` can then be used to determine if it is remote or not. (#1731)
2431

2532
## [0.19.0] - 2021-03-18
2633

bridge/opentracing/bridge.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"go.opentelemetry.io/otel/codes"
3232
"go.opentelemetry.io/otel/internal/baggage"
3333
"go.opentelemetry.io/otel/internal/trace/noop"
34-
otelparent "go.opentelemetry.io/otel/internal/trace/parent"
3534
"go.opentelemetry.io/otel/propagation"
3635
"go.opentelemetry.io/otel/trace"
3736
)
@@ -657,7 +656,7 @@ func (t *BridgeTracer) Extract(format interface{}, carrier interface{}) (ot.Span
657656
baggage := baggage.MapFromContext(ctx)
658657
bridgeSC := &bridgeSpanContext{
659658
baggageItems: baggage,
660-
otelSpanContext: otelparent.SpanContext(ctx),
659+
otelSpanContext: trace.SpanContextFromContext(ctx),
661660
}
662661
if !bridgeSC.otelSpanContext.IsValid() {
663662
return nil, ot.ErrSpanContextNotFound

bridge/opentracing/internal/mock.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"go.opentelemetry.io/otel/attribute"
2525
"go.opentelemetry.io/otel/codes"
2626
"go.opentelemetry.io/otel/internal/baggage"
27-
otelparent "go.opentelemetry.io/otel/internal/trace/parent"
2827
"go.opentelemetry.io/otel/trace"
2928

3029
"go.opentelemetry.io/otel/bridge/opentracing/migration"
@@ -138,7 +137,7 @@ func (t *MockTracer) getParentSpanID(ctx context.Context, config *trace.SpanConf
138137

139138
func (t *MockTracer) getParentSpanContext(ctx context.Context, config *trace.SpanConfig) trace.SpanContext {
140139
if !config.NewRoot {
141-
return otelparent.SpanContext(ctx)
140+
return trace.SpanContextFromContext(ctx)
142141
}
143142
return trace.SpanContext{}
144143
}

oteltest/config.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ func defaultSpanContextFunc() func(context.Context) trace.SpanContext {
2828
var traceID, spanID uint64 = 1, 1
2929
return func(ctx context.Context) trace.SpanContext {
3030
var sc trace.SpanContext
31-
if lsc := trace.SpanContextFromContext(ctx); lsc.IsValid() {
32-
sc = lsc
33-
} else if rsc := trace.RemoteSpanContextFromContext(ctx); rsc.IsValid() {
34-
sc = rsc
31+
if current := trace.SpanContextFromContext(ctx); current.IsValid() {
32+
sc = current
3533
} else {
3634
var tid trace.TraceID
3735
binary.BigEndian.PutUint64(tid[:], atomic.AddUint64(&traceID, 1))

oteltest/tracer.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,9 @@ func (t *Tracer) Start(ctx context.Context, name string, opts ...trace.SpanOptio
5555
span.spanContext = trace.SpanContext{}
5656
} else {
5757
span.spanContext = t.config.SpanContextFunc(ctx)
58-
if lsc := trace.SpanContextFromContext(ctx); lsc.IsValid() {
59-
span.spanContext = span.spanContext.WithTraceID(lsc.TraceID())
60-
span.parentSpanID = lsc.SpanID()
61-
} else if rsc := trace.RemoteSpanContextFromContext(ctx); rsc.IsValid() {
62-
span.spanContext = span.spanContext.WithTraceID(rsc.TraceID())
63-
span.parentSpanID = rsc.SpanID()
58+
if current := trace.SpanContextFromContext(ctx); current.IsValid() {
59+
span.spanContext = span.spanContext.WithTraceID(current.TraceID())
60+
span.parentSpanID = current.SpanID()
6461
}
6562
}
6663

oteltest/tracer_test.go

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,19 @@ func TestTracer(t *testing.T) {
102102
e.Expect(testSpan.ParentSpanID()).ToEqual(parentSpanContext.SpanID())
103103
})
104104

105-
t.Run("uses the current span from context as parent, even if it has remote span context", func(t *testing.T) {
105+
t.Run("uses the current span from context as parent, even if it is remote", func(t *testing.T) {
106106
t.Parallel()
107107

108108
e := matchers.NewExpecter(t)
109109

110110
subject := tp.Tracer(t.Name())
111111

112-
parent, parentSpan := subject.Start(context.Background(), "parent")
113-
_, remoteParentSpan := subject.Start(context.Background(), "remote not-a-parent")
114-
parent = trace.ContextWithRemoteSpanContext(parent, remoteParentSpan.SpanContext())
115-
parentSpanContext := parentSpan.SpanContext()
112+
ctx, _ := subject.Start(context.Background(), "local grandparent")
113+
_, s := subject.Start(ctx, "remote parent")
114+
ctx = trace.ContextWithRemoteSpanContext(ctx, s.SpanContext())
115+
parentSpanContext := trace.SpanContextFromContext(ctx)
116116

117-
_, span := subject.Start(parent, "child")
117+
_, span := subject.Start(ctx, "child")
118118

119119
testSpan, ok := span.(*oteltest.Span)
120120
e.Expect(ok).ToBeTrue()
@@ -125,78 +125,44 @@ func TestTracer(t *testing.T) {
125125
e.Expect(testSpan.ParentSpanID()).ToEqual(parentSpanContext.SpanID())
126126
})
127127

128-
t.Run("uses the remote span context from context as parent, if current span is missing", func(t *testing.T) {
128+
t.Run("creates new root when context does not have a current span", func(t *testing.T) {
129129
t.Parallel()
130130

131131
e := matchers.NewExpecter(t)
132132

133133
subject := tp.Tracer(t.Name())
134134

135-
_, remoteParentSpan := subject.Start(context.Background(), "remote parent")
136-
parent := trace.ContextWithRemoteSpanContext(context.Background(), remoteParentSpan.SpanContext())
137-
remoteParentSpanContext := remoteParentSpan.SpanContext()
138-
139-
_, span := subject.Start(parent, "child")
140-
141-
testSpan, ok := span.(*oteltest.Span)
142-
e.Expect(ok).ToBeTrue()
143-
144-
childSpanContext := testSpan.SpanContext()
145-
e.Expect(childSpanContext.TraceID()).ToEqual(remoteParentSpanContext.TraceID())
146-
e.Expect(childSpanContext.SpanID()).NotToEqual(remoteParentSpanContext.SpanID())
147-
e.Expect(testSpan.ParentSpanID()).ToEqual(remoteParentSpanContext.SpanID())
148-
})
149-
150-
t.Run("creates new root when both current span and remote span context are missing", func(t *testing.T) {
151-
t.Parallel()
152-
153-
e := matchers.NewExpecter(t)
154-
155-
subject := tp.Tracer(t.Name())
156-
157-
_, parentSpan := subject.Start(context.Background(), "not-a-parent")
158-
_, remoteParentSpan := subject.Start(context.Background(), "remote not-a-parent")
159-
parentSpanContext := parentSpan.SpanContext()
160-
remoteParentSpanContext := remoteParentSpan.SpanContext()
135+
_, napSpan := subject.Start(context.Background(), "not-a-parent")
136+
napSpanContext := napSpan.SpanContext()
161137

162138
_, span := subject.Start(context.Background(), "child")
163139

164140
testSpan, ok := span.(*oteltest.Span)
165141
e.Expect(ok).ToBeTrue()
166142

167143
childSpanContext := testSpan.SpanContext()
168-
e.Expect(childSpanContext.TraceID()).NotToEqual(parentSpanContext.TraceID())
169-
e.Expect(childSpanContext.TraceID()).NotToEqual(remoteParentSpanContext.TraceID())
170-
e.Expect(childSpanContext.SpanID()).NotToEqual(parentSpanContext.SpanID())
171-
e.Expect(childSpanContext.SpanID()).NotToEqual(remoteParentSpanContext.SpanID())
144+
e.Expect(childSpanContext.TraceID()).NotToEqual(napSpanContext.TraceID())
145+
e.Expect(childSpanContext.SpanID()).NotToEqual(napSpanContext.SpanID())
172146
e.Expect(testSpan.ParentSpanID().IsValid()).ToBeFalse()
173147
})
174148

175-
t.Run("creates new root when requested, even if both current span and remote span context are in context", func(t *testing.T) {
149+
t.Run("creates new root when requested, even if context has current span", func(t *testing.T) {
176150
t.Parallel()
177151

178152
e := matchers.NewExpecter(t)
179153

180154
subject := tp.Tracer(t.Name())
181155

182-
parentCtx, parentSpan := subject.Start(context.Background(), "not-a-parent")
183-
_, remoteParentSpan := subject.Start(context.Background(), "remote not-a-parent")
184-
parentSpanContext := parentSpan.SpanContext()
185-
remoteParentSpanContext := remoteParentSpan.SpanContext()
186-
parentCtx = trace.ContextWithRemoteSpanContext(parentCtx, remoteParentSpanContext)
187-
// remote SpanContexts will be marked as remote
188-
remoteParentSpanContext = remoteParentSpanContext.WithRemote(true)
189-
190-
_, span := subject.Start(parentCtx, "child", trace.WithNewRoot())
156+
ctx, napSpan := subject.Start(context.Background(), "not-a-parent")
157+
napSpanContext := napSpan.SpanContext()
158+
_, span := subject.Start(ctx, "child", trace.WithNewRoot())
191159

192160
testSpan, ok := span.(*oteltest.Span)
193161
e.Expect(ok).ToBeTrue()
194162

195163
childSpanContext := testSpan.SpanContext()
196-
e.Expect(childSpanContext.TraceID()).NotToEqual(parentSpanContext.TraceID())
197-
e.Expect(childSpanContext.TraceID()).NotToEqual(remoteParentSpanContext.TraceID())
198-
e.Expect(childSpanContext.SpanID()).NotToEqual(parentSpanContext.SpanID())
199-
e.Expect(childSpanContext.SpanID()).NotToEqual(remoteParentSpanContext.SpanID())
164+
e.Expect(childSpanContext.TraceID()).NotToEqual(napSpanContext.TraceID())
165+
e.Expect(childSpanContext.SpanID()).NotToEqual(napSpanContext.SpanID())
200166
e.Expect(testSpan.ParentSpanID().IsValid()).ToBeFalse()
201167
})
202168

propagation/propagators_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,24 @@ func TestMultiplePropagators(t *testing.T) {
100100
// generates the valid span context out of thin air
101101
{
102102
ctx := ootaProp.Extract(bg, ns)
103-
sc := trace.RemoteSpanContextFromContext(ctx)
103+
sc := trace.SpanContextFromContext(ctx)
104104
require.True(t, sc.IsValid(), "oota prop failed sanity check")
105+
require.True(t, sc.IsRemote(), "oota prop is remote")
105106
}
106107
// sanity check for real propagators, ensuring that they
107108
// really are not putting any valid span context into an empty
108109
// go context in absence of the HTTP headers.
109110
for _, prop := range testProps {
110111
ctx := prop.Extract(bg, ns)
111-
sc := trace.RemoteSpanContextFromContext(ctx)
112+
sc := trace.SpanContextFromContext(ctx)
112113
require.Falsef(t, sc.IsValid(), "%#v failed sanity check", prop)
114+
require.Falsef(t, sc.IsRemote(), "%#v prop set a remote", prop)
113115
}
114116
for _, prop := range testProps {
115117
props := propagation.NewCompositeTextMapPropagator(ootaProp, prop)
116118
ctx := props.Extract(bg, ns)
117-
sc := trace.RemoteSpanContextFromContext(ctx)
119+
sc := trace.SpanContextFromContext(ctx)
120+
assert.Truef(t, sc.IsRemote(), "%#v prop is remote", prop)
118121
assert.Truef(t, sc.IsValid(), "%#v clobbers span context", prop)
119122
}
120123
}

propagation/trace_context_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestExtractValidTraceContextFromHTTPReq(t *testing.T) {
121121

122122
ctx := context.Background()
123123
ctx = prop.Extract(ctx, propagation.HeaderCarrier(req.Header))
124-
gotSc := trace.RemoteSpanContextFromContext(ctx)
124+
gotSc := trace.SpanContextFromContext(ctx)
125125
if diff := cmp.Diff(gotSc, tt.wantSc, cmp.Comparer(func(sc, other trace.SpanContext) bool { return sc.Equal(other) })); diff != "" {
126126
t.Errorf("Extract Tracecontext: %s: -got +want %s", tt.name, diff)
127127
}
@@ -209,7 +209,7 @@ func TestExtractInvalidTraceContextFromHTTPReq(t *testing.T) {
209209

210210
ctx := context.Background()
211211
ctx = prop.Extract(ctx, propagation.HeaderCarrier(req.Header))
212-
gotSc := trace.RemoteSpanContextFromContext(ctx)
212+
gotSc := trace.SpanContextFromContext(ctx)
213213
if diff := cmp.Diff(gotSc, wantSc, cmp.AllowUnexported(trace.TraceState{})); diff != "" {
214214
t.Errorf("Extract Tracecontext: %s: -got +want %s", tt.name, diff)
215215
}
@@ -350,7 +350,7 @@ func TestTraceStatePropagation(t *testing.T) {
350350

351351
ctx := prop.Extract(context.Background(), propagation.HeaderCarrier(inReq.Header))
352352
if diff := cmp.Diff(
353-
trace.RemoteSpanContextFromContext(ctx),
353+
trace.SpanContextFromContext(ctx),
354354
tt.wantSc,
355355
cmp.AllowUnexported(attribute.Value{}),
356356
cmp.AllowUnexported(trace.TraceState{}),

sdk/trace/span.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"go.opentelemetry.io/otel/attribute"
2626
"go.opentelemetry.io/otel/codes"
27-
"go.opentelemetry.io/otel/internal/trace/parent"
2827
"go.opentelemetry.io/otel/trace"
2928

3029
export "go.opentelemetry.io/otel/sdk/export/trace"
@@ -523,7 +522,7 @@ func startSpanInternal(ctx context.Context, tr *tracer, name string, o *trace.Sp
523522
// as a parent which contains an invalid trace ID and is not remote.
524523
var psc trace.SpanContext
525524
if !o.NewRoot {
526-
psc = parent.SpanContext(ctx)
525+
psc = trace.SpanContextFromContext(ctx)
527526
}
528527

529528
// If there is a valid parent trace ID, use it to ensure the continuity of

sdk/trace/span_processor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type testSpanProcessor struct {
3131
}
3232

3333
func (t *testSpanProcessor) OnStart(parent context.Context, s sdktrace.ReadWriteSpan) {
34-
psc := trace.RemoteSpanContextFromContext(parent)
34+
psc := trace.SpanContextFromContext(parent)
3535
kv := []attribute.KeyValue{
3636
{
3737
Key: "SpanProcessorName",

0 commit comments

Comments
 (0)