swarm: codebase split from go-ethereum (#1405)

This commit is contained in:
Rafael Matias
2019-06-03 12:28:18 +02:00
committed by Anton Evangelatov
parent 7a22da98b9
commit b046760db1
1540 changed files with 4654 additions and 129393 deletions

View File

@ -0,0 +1,49 @@
package spancontext
import (
"context"
opentracing "github.com/opentracing/opentracing-go"
)
func WithContext(ctx context.Context, sctx opentracing.SpanContext) context.Context {
return context.WithValue(ctx, "span_context", sctx)
}
func FromContext(ctx context.Context) opentracing.SpanContext {
sctx, ok := ctx.Value("span_context").(opentracing.SpanContext)
if ok {
return sctx
}
return nil
}
func StartSpan(ctx context.Context, name string) (context.Context, opentracing.Span) {
tracer := opentracing.GlobalTracer()
sctx := FromContext(ctx)
var sp opentracing.Span
if sctx != nil {
sp = tracer.StartSpan(
name,
opentracing.ChildOf(sctx))
} else {
sp = tracer.StartSpan(name)
}
nctx := context.WithValue(ctx, "span_context", sp.Context())
return nctx, sp
}
func StartSpanFrom(name string, sctx opentracing.SpanContext) opentracing.Span {
tracer := opentracing.GlobalTracer()
sp := tracer.StartSpan(
name,
opentracing.ChildOf(sctx))
return sp
}