1
0
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:
rghetia 2019-09-19 12:23:07 -07:00 committed by GitHub
parent 3362421c9b
commit 8af3bfcdc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 16 deletions

View File

@ -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)
}

View File

@ -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 {