# README
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() {
/* Create tracerProvider and configure OpenTelemetry ... */
otelTracer := tracerProvider.Tracer("tracer_name")
// Use the bridgeTracer as your OpenTracing tracer.
bridgeTracer, wrapperTracerProvider := otelBridge.NewTracerPair(otelTracer)
// Set the wrapperTracerProvider as the global OpenTelemetry
// TracerProvider so instrumentation will use it by default.
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)
// Propagate the otSpan to both OpenTracing and OpenTelemetry
// instrumentation by using the ctxWithOTAndOTelSpan context.
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
... // any other available method can be added here to access it
}
var sc opentracing.SpanContext = ...
if s, ok := sc.(spanContextProvider); ok {
// Use TraceID by s.TraceID()
// Use SpanID by s.SpanID()
// Use TraceFlags by s.TraceFlags()
...
}
# Functions
NewBridgeTracer creates a new BridgeTracer.
NewTracerPair is a utility function that creates a BridgeTracer and a WrapperTracerProvider.
NewTracerPairWithContext is a convenience function.
NewTracerProvider returns a new TracerProvider that creates new instances of WrapperTracer from the given TracerProvider.
NewWrappedTracerProvider creates a new trace provider that creates a single instance of WrapperTracer that wraps OpenTelemetry tracer, and always returns it unmodified from Tracer().
NewWrapperTracer wraps the passed tracer and also talks to the passed bridge tracer when setting up the context with the new active OpenTracing span.
# Structs
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.
TracerProvider is an OpenTelemetry TracerProvider that wraps an OpenTracing Tracer.
WrapperTracer is a wrapper around an OpenTelemetry tracer.
WrapperTracerProvider is an OpenTelemetry TracerProvider that wraps an OpenTracing Tracer, created by the deprecated NewWrappedTracerProvider.
# Type aliases
BridgeWarningHandler is a type of handler that receives warnings from the BridgeTracer.