OpenTelemetry/OpenTracing Bridge
Getting started
go get go.opentelemetry.io/otel/bridge/opentracing
Assuming you have configured an OpenTelemetry TracerProvider
, these will be the steps to follow to wire up the bridge:
import (
"go.opentelemetry.io/otel"
otelBridge "go.opentelemetry.io/otel/bridge/opentracing"
)
func main() {
otelTracer := tracerProvider.Tracer("tracer_name")
bridgeTracer, wrapperTracerProvider := otelBridge.NewTracerPair(otelTracer)
otel.SetTracerProvider(wrapperTracerProvider)
}
Interop from trace context from OpenTracing to OpenTelemetry
In order to get OpenTracing spans properly into the OpenTelemetry context, so they can be propagated (both internally, and externally), you will need to explicitly use the BridgeTracer
for creating your OpenTracing spans, rather than a bare OpenTracing Tracer
instance.
When you have started an OpenTracing Span, make sure the OpenTelemetry knows about it like this:
ctxWithOTSpan := opentracing.ContextWithSpan(ctx, otSpan)
ctxWithOTAndOTelSpan := bridgeTracer.ContextWithSpanHook(ctxWithOTSpan, otSpan)
Extended Functionality
The bridge functionality can be extended beyond the OpenTracing API.
Any trace.SpanContext
method can be accessed as following:
type spanContextProvider interface {
IsSampled() bool
TraceID() trace.TraceID
SpanID() trace.SpanID
TraceFlags() trace.TraceFlags
...
}
var sc opentracing.SpanContext = ...
if s, ok := sc.(spanContextProvider); ok {
...
}