Documentation ¶
Overview ¶
This package implements a bridge that forwards OpenTracing API calls to the OpenTelemetry SDK.
To use the bridge, first create an OpenTelemetry tracer of choice. Then use the NewTracerPair() function to create two tracers - one implementing OpenTracing API (BridgeTracer) and one that implements the OpenTelemetry API (WrapperTracer) and mostly forwards the calls to the OpenTelemetry tracer of choice, but does some extra steps to make the interaction between both APIs working. If the OpenTelemetry tracer of choice already knows how to cooperate with OpenTracing API through the OpenTracing bridge (explained in detail below), then it is fine to skip the WrapperTracer by calling the NewBridgeTracer() function to get the bridge tracer and then passing the chosen OpenTelemetry tracer to the SetOpenTelemetryTracer() function of the bridge tracer.
Bridge tracer also allows the user to install a warning handler through the SetWarningHandler() function. The warning handler will be called when there is some misbehavior of the OpenTelemetry tracer with regard to the cooperation with the OpenTracing API.
For an OpenTelemetry tracer to cooperate with OpenTracing API through the BridgeTracer, the OpenTelemetry tracer needs to (reasoning is below the list):
1. Return the same context it received in the Start() function if migration.SkipContextSetup() returns true.
2. Implement the migration.DeferredContextSetupTracerExtension interface. The implementation should setup the context it would normally do in the Start() function if the migration.SkipContextSetup() function returned false. Calling ContextWithBridgeSpan() is not necessary.
3. Have an access to the BridgeTracer instance.
4. If the migration.SkipContextSetup() function returned false, the tracer should use the ContextWithBridgeSpan() function to install the created span as an active OpenTracing span.
There are some differences between OpenTracing and OpenTelemetry APIs, especially with regard to Go context handling. When a span is created with an OpenTracing API (through the StartSpan() function) the Go context is not available. BridgeTracer has access to the OpenTelemetry tracer of choice, so in the StartSpan() function BridgeTracer translates the parameters to the OpenTelemetry version and uses the OpenTelemetry tracer's Start() function to actually create a span. The OpenTelemetry Start() function takes the Go context as a parameter, so BridgeTracer at this point passes a temporary context to Start(). All the changes to the temporary context will be lost at the end of the StartSpan() function, so the OpenTelemetry tracer of choice should not do anything with the context. If the returned context is different, BridgeTracer will warn about it. The OpenTelemetry tracer of choice can learn about this situation by using the migration.SkipContextSetup() function. The tracer will receive an opportunity to set up the context at a later stage. Usually after StartSpan() is finished, users of the OpenTracing API are calling (either directly or through the opentracing.StartSpanFromContext() helper function) the opentracing.ContextWithSpan() function to insert the created OpenTracing span into the context. At that time, the OpenTelemetry tracer of choice has a chance of setting up the context through a hook invoked inside the opentracing.ContextWithSpan() function. For that to happen, the tracer should implement the migration.DeferredContextSetupTracerExtension interface. This so far explains the need for points 1. and 2.
When the span is created with the OpenTelemetry API (with the Start() function) then migration.SkipContextSetup() will return false. This means that the tracer can do the usual setup of the context, but it also should set up the active OpenTracing span in the context. This is because OpenTracing API is not used at all in the creation of the span, but the OpenTracing API may be used during the time when the created OpenTelemetry span is current. For this case to work, we need to also set up active OpenTracing span in the context. This can be done with the ContextWithBridgeSpan() function. This means that the OpenTelemetry tracer of choice needs to have an access to the BridgeTracer instance. This should explain the need for points 3. and 4.
Another difference related to the Go context handling is in logging - OpenTracing API does not take a context parameter in the LogFields() function, so when the call to the function gets translated to OpenTelemetry AddEvent() function, an empty context is passed.
Index ¶
- func NewTracerPair(tracer oteltrace.Tracer) (*BridgeTracer, *WrapperProvider)
- type BridgeTracer
- func (t *BridgeTracer) ContextWithBridgeSpan(ctx context.Context, span oteltrace.Span) context.Context
- func (t *BridgeTracer) ContextWithSpanHook(ctx context.Context, span ot.Span) context.Context
- func (t *BridgeTracer) Extract(format interface{}, carrier interface{}) (ot.SpanContext, error)
- func (t *BridgeTracer) Inject(sm ot.SpanContext, format interface{}, carrier interface{}) error
- func (t *BridgeTracer) SetOpenTelemetryTracer(tracer oteltrace.Tracer)
- func (t *BridgeTracer) SetWarningHandler(handler BridgeWarningHandler)
- func (t *BridgeTracer) StartSpan(operationName string, opts ...ot.StartSpanOption) ot.Span
- type BridgeWarningHandler
- type WrapperProvider
- type WrapperTracer
- func (t *WrapperTracer) DeferredContextSetupHook(ctx context.Context, span oteltrace.Span) context.Context
- func (t *WrapperTracer) Start(ctx context.Context, name string, opts ...oteltrace.StartOption) (context.Context, oteltrace.Span)
- func (t *WrapperTracer) WithSpan(ctx context.Context, name string, body func(context.Context) error, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTracerPair ¶
func NewTracerPair(tracer oteltrace.Tracer) (*BridgeTracer, *WrapperProvider)
NewTracerPair is a utility function that creates a BridgeTracer and a WrapperProvider. WrapperProvider creates a single instance of WrapperTracer. The BridgeTracer forwards the calls to the WrapperTracer that wraps the passed tracer. BridgeTracer and WrapperProvider are returned to the caller and the caller is expected to register BridgeTracer with opentracing and WrapperProvider with opentelemetry.
Types ¶
type BridgeTracer ¶
type BridgeTracer struct {
// contains filtered or unexported fields
}
BridgeTracer is an implementation of the OpenTracing tracer, which translates the calls to the OpenTracing API into OpenTelemetry counterparts and calls the underlying OpenTelemetry tracer.
func NewBridgeTracer ¶
func NewBridgeTracer() *BridgeTracer
NewBridgeTracer creates a new BridgeTracer. The new tracer forwards the calls to the OpenTelemetry Noop tracer, so it should be overridden with the SetOpenTelemetryTracer function. The warnings handler does nothing by default, so to override it use the SetWarningHandler function.
func (*BridgeTracer) ContextWithBridgeSpan ¶
func (t *BridgeTracer) ContextWithBridgeSpan(ctx context.Context, span oteltrace.Span) context.Context
ContextWithBridgeSpan sets up the context with the passed OpenTelemetry span as the active OpenTracing span.
This function should be used by the OpenTelemetry tracers that want to be aware how to operate in the environment using OpenTracing API.
func (*BridgeTracer) ContextWithSpanHook ¶
ContextWithSpanHook is an implementation of the OpenTracing tracer extension interface. It will call the DeferredContextSetupHook function on the tracer if it implements the DeferredContextSetupTracerExtension interface.
func (*BridgeTracer) Extract ¶
func (t *BridgeTracer) Extract(format interface{}, carrier interface{}) (ot.SpanContext, error)
Extract is a part of the implementation of the OpenTracing Tracer interface.
Currently only the HTTPHeaders format is kinda sorta supported.
func (*BridgeTracer) Inject ¶
func (t *BridgeTracer) Inject(sm ot.SpanContext, format interface{}, carrier interface{}) error
Inject is a part of the implementation of the OpenTracing Tracer interface.
Currently only the HTTPHeaders format is kinda sorta supported.
func (*BridgeTracer) SetOpenTelemetryTracer ¶
func (t *BridgeTracer) SetOpenTelemetryTracer(tracer oteltrace.Tracer)
SetWarningHandler overrides the underlying OpenTelemetry tracer. The passed tracer should know how to operate in the environment that uses OpenTracing API.
func (*BridgeTracer) SetWarningHandler ¶
func (t *BridgeTracer) SetWarningHandler(handler BridgeWarningHandler)
SetWarningHandler overrides the warning handler.
func (*BridgeTracer) StartSpan ¶
func (t *BridgeTracer) StartSpan(operationName string, opts ...ot.StartSpanOption) ot.Span
StartSpan is a part of the implementation of the OpenTracing Tracer interface.
type BridgeWarningHandler ¶
type BridgeWarningHandler func(msg string)
BridgeWarningHandler is a type of handler that receives warnings from the BridgeTracer.
type WrapperProvider ¶
type WrapperProvider struct {
// contains filtered or unexported fields
}
func NewWrappedProvider ¶
func NewWrappedProvider(bridge *BridgeTracer, tracer oteltrace.Tracer) *WrapperProvider
NewWrappedProvider creates a new trace provider that creates a single instance of WrapperTracer that wraps OpenTelemetry tracer.
type WrapperTracer ¶
type WrapperTracer struct {
// contains filtered or unexported fields
}
WrapperTracer is a wrapper around an OpenTelemetry tracer. It mostly forwards the calls to the wrapped tracer, but also does some extra steps like setting up a context with the active OpenTracing span.
It does not need to be used when the OpenTelemetry tracer is also aware how to operate in environment where OpenTracing API is also used.
func NewWrapperTracer ¶
func NewWrapperTracer(bridge *BridgeTracer, tracer oteltrace.Tracer) *WrapperTracer
NewWrapperTracer wraps the passed tracer and also talks to the passed bridge tracer when setting up the context with the new active OpenTracing span.
func (*WrapperTracer) DeferredContextSetupHook ¶
func (t *WrapperTracer) DeferredContextSetupHook(ctx context.Context, span oteltrace.Span) context.Context
DeferredContextSetupHook is a part of the implementation of the DeferredContextSetupTracerExtension interface. It will try to forward the call to the wrapped tracer if it implements the interface.
func (*WrapperTracer) Start ¶
func (t *WrapperTracer) Start(ctx context.Context, name string, opts ...oteltrace.StartOption) (context.Context, oteltrace.Span)
Start forwards the call to the wrapped tracer. It also tries to override the tracer of the returned span if the span implements the OverrideTracerSpanExtension interface.
func (*WrapperTracer) WithSpan ¶
func (t *WrapperTracer) WithSpan(ctx context.Context, name string, body func(context.Context) error, opts ...oteltrace.StartOption) error
WithSpan forwards the call to the wrapped tracer with a modified body callback, which sets the active OpenTracing span before calling the original callback.
Directories ¶
Path | Synopsis |
---|---|
This package provides interfaces and functions that are useful for providing a cooperation of the OpenTelemetry tracers with the OpenTracing API.
|
This package provides interfaces and functions that are useful for providing a cooperation of the OpenTelemetry tracers with the OpenTracing API. |