diff options
author | Sebastian Jug <sejug@redhat.com> | 2018-10-16 16:30:53 -0400 |
---|---|---|
committer | Sebastian Jug <seb@stianj.ug> | 2019-02-18 09:57:08 -0500 |
commit | 7141f972700ed454438d8539dd0bec79c0b61cf4 (patch) | |
tree | bfa2e524b71757a514a02ef68661b46dca9a3dfe /vendor/github.com/opentracing/opentracing-go/gocontext.go | |
parent | e738ef16225395f5f5e4b93ba1a43ae9449ae11b (diff) | |
download | podman-7141f972700ed454438d8539dd0bec79c0b61cf4.tar.gz podman-7141f972700ed454438d8539dd0bec79c0b61cf4.tar.bz2 podman-7141f972700ed454438d8539dd0bec79c0b61cf4.zip |
OpenTracing support added to start, stop, run, create, pull, and ps
Drop context.Context field from cli.Context
Signed-off-by: Sebastian Jug <sejug@redhat.com>
Diffstat (limited to 'vendor/github.com/opentracing/opentracing-go/gocontext.go')
-rw-r--r-- | vendor/github.com/opentracing/opentracing-go/gocontext.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/github.com/opentracing/opentracing-go/gocontext.go b/vendor/github.com/opentracing/opentracing-go/gocontext.go new file mode 100644 index 000000000..05a62e70b --- /dev/null +++ b/vendor/github.com/opentracing/opentracing-go/gocontext.go @@ -0,0 +1,54 @@ +package opentracing + +import "context" + +type contextKey struct{} + +var activeSpanKey = contextKey{} + +// ContextWithSpan returns a new `context.Context` that holds a reference to +// `span`'s SpanContext. +func ContextWithSpan(ctx context.Context, span Span) context.Context { + return context.WithValue(ctx, activeSpanKey, span) +} + +// SpanFromContext returns the `Span` previously associated with `ctx`, or +// `nil` if no such `Span` could be found. +// +// NOTE: context.Context != SpanContext: the former is Go's intra-process +// context propagation mechanism, and the latter houses OpenTracing's per-Span +// identity and baggage information. +func SpanFromContext(ctx context.Context) Span { + val := ctx.Value(activeSpanKey) + if sp, ok := val.(Span); ok { + return sp + } + return nil +} + +// StartSpanFromContext starts and returns a Span with `operationName`, using +// any Span found within `ctx` as a ChildOfRef. If no such parent could be +// found, StartSpanFromContext creates a root (parentless) Span. +// +// The second return value is a context.Context object built around the +// returned Span. +// +// Example usage: +// +// SomeFunction(ctx context.Context, ...) { +// sp, ctx := opentracing.StartSpanFromContext(ctx, "SomeFunction") +// defer sp.Finish() +// ... +// } +func StartSpanFromContext(ctx context.Context, operationName string, opts ...StartSpanOption) (Span, context.Context) { + return startSpanFromContextWithTracer(ctx, GlobalTracer(), operationName, opts...) +} + +// startSpanFromContextWithTracer is factored out for testing purposes. +func startSpanFromContextWithTracer(ctx context.Context, tracer Tracer, operationName string, opts ...StartSpanOption) (Span, context.Context) { + if parentSpan := SpanFromContext(ctx); parentSpan != nil { + opts = append(opts, ChildOf(parentSpan.Context())) + } + span := tracer.StartSpan(operationName, opts...) + return span, ContextWithSpan(ctx, span) +} |