mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-20 03:30:02 +02:00
Use trace.SetCurrentSpan to store the span in the context in SDK. (#129)
This commit is contained in:
parent
3362421c9b
commit
8af3bfcdc2
@ -15,7 +15,6 @@
|
||||
package trace
|
||||
|
||||
import (
|
||||
"context"
|
||||
crand "crypto/rand"
|
||||
"encoding/binary"
|
||||
"math/rand"
|
||||
@ -62,14 +61,3 @@ func Register() apitrace.Tracer {
|
||||
})
|
||||
return tr
|
||||
}
|
||||
|
||||
type contextKey struct{}
|
||||
|
||||
func fromContext(ctx context.Context) *span {
|
||||
s, _ := ctx.Value(contextKey{}).(*span)
|
||||
return s
|
||||
}
|
||||
|
||||
func newContext(parent context.Context, s *span) context.Context {
|
||||
return context.WithValue(parent, contextKey{}, s)
|
||||
}
|
||||
|
@ -52,9 +52,11 @@ func (tr *tracer) Start(ctx context.Context, name string, o ...apitrace.SpanOpti
|
||||
parent = opts.Reference.SpanContext
|
||||
remoteParent = true
|
||||
} else {
|
||||
if p := fromContext(ctx); p != nil {
|
||||
p.addChild()
|
||||
parent = p.spanContext
|
||||
if p := apitrace.CurrentSpan(ctx); p != nil {
|
||||
if sdkSpan, ok := p.(*span); ok {
|
||||
sdkSpan.addChild()
|
||||
parent = sdkSpan.spanContext
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +72,7 @@ func (tr *tracer) Start(ctx context.Context, name string, o ...apitrace.SpanOpti
|
||||
|
||||
ctx, end := startExecutionTracerTask(ctx, name)
|
||||
span.executionTracerTaskEnd = end
|
||||
return newContext(ctx, span), span
|
||||
return apitrace.SetCurrentSpan(ctx, span), span
|
||||
}
|
||||
|
||||
func (tr *tracer) WithSpan(ctx context.Context, name string, body func(ctx context.Context) error) error {
|
||||
|
Loading…
x
Reference in New Issue
Block a user