| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
// Package migration provides interfaces and functions that are useful for |
| 5 |
// providing a cooperation of the OpenTelemetry tracers with the |
| 6 |
// OpenTracing API. |
| 7 |
package migration // import "go.opentelemetry.io/otel/bridge/opentracing/migration" |
| 8 |
|
| 9 |
import ( |
| 10 |
"context" |
| 11 |
|
| 12 |
"go.opentelemetry.io/otel/trace" |
| 13 |
) |
| 14 |
|
| 15 |
// DeferredContextSetupTracerExtension is an interface an |
| 16 |
// OpenTelemetry tracer may implement in order to cooperate with the |
| 17 |
// calls to the OpenTracing API. |
| 18 |
// |
| 19 |
// Tracers implementing this interface should also use the |
| 20 |
// SkipContextSetup() function during creation of the span in the |
| 21 |
// Start() function to skip the configuration of the context. |
| 22 |
type DeferredContextSetupTracerExtension interface { |
| 23 |
// DeferredContextSetupHook is called by the bridge |
| 24 |
// OpenTracing tracer when opentracing.ContextWithSpan is |
| 25 |
// called. This allows the OpenTelemetry tracer to set up the |
| 26 |
// context in a way it would normally do during the Start() |
| 27 |
// function. Since OpenTracing API does not support |
| 28 |
// configuration of the context during span creation, it needs |
| 29 |
// to be deferred until the call to the |
| 30 |
// opentracing.ContextWithSpan happens. When bridge |
| 31 |
// OpenTracing tracer calls OpenTelemetry tracer's Start() |
| 32 |
// function, it passes a context that shouldn't be modified. |
| 33 |
DeferredContextSetupHook(ctx context.Context, span trace.Span) context.Context |
| 34 |
} |
| 35 |
|
| 36 |
// OverrideTracerSpanExtension is an interface an OpenTelemetry span |
| 37 |
// may implement in order to cooperate with the calls to the |
| 38 |
// OpenTracing API. |
| 39 |
// |
| 40 |
// TODO(krnowak): I'm actually not so sold on the idea… The reason for |
| 41 |
// introducing this interface was to have a span "created" by the |
| 42 |
// WrapperTracer return WrapperTracer from the Tracer() function, not |
| 43 |
// the real OpenTelemetry tracer that actually created the span. I'm |
| 44 |
// thinking that I could create a wrapperSpan type that wraps an |
| 45 |
// OpenTelemetry Span object and have WrapperTracer to alter the |
| 46 |
// current OpenTelemetry span in the context so it points to the |
| 47 |
// wrapped object, so the code in the tracer like |
| 48 |
// `trace.SpanFromContent().(*realSpan)` would still work. Another |
| 49 |
// argument for getting rid of this interface is that is only called |
| 50 |
// by the WrapperTracer - WrapperTracer likely shouldn't require any |
| 51 |
// changes in the underlying OpenTelemetry tracer to have things |
| 52 |
// somewhat working. |
| 53 |
// |
| 54 |
// See the "tracer mess" test in mix_test.go. |
| 55 |
type OverrideTracerSpanExtension interface { |
| 56 |
// OverrideTracer makes the span to return the passed tracer |
| 57 |
// from its Tracer() function. |
| 58 |
// |
| 59 |
// You don't need to implement this function if your |
| 60 |
// OpenTelemetry tracer cooperates well with the OpenTracing |
| 61 |
// API calls. In such case, there is no need to use the |
| 62 |
// WrapperTracer and thus no need to override the result of |
| 63 |
// the Tracer() function. |
| 64 |
OverrideTracer(tracer trace.Tracer) |
| 65 |
} |