mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-12 10:04:29 +02:00
e3f547fedd
Bump google.golang.org/grpc from 1.55.0 to 1.56.0 in /bridge/opentracing/test Bump github.com/prometheus/client_golang from 1.15.1 to 1.16.0 in /example/view Bump github.com/golangci/golangci-lint from 1.53.2 to 1.53.3 in /internal/tools Bump github.com/prometheus/client_golang from 1.15.1 to 1.16.0 in /exporters/prometheus Bump golang.org/x/tools from 0.9.3 to 0.10.0 in /internal/tools Bump google.golang.org/grpc from 1.55.0 to 1.56.0 in /exporters/otlp/otlpmetric/otlpmetricgrpc Bump google.golang.org/grpc from 1.55.0 to 1.56.0 in /exporters/otlp/otlpmetric Bump google.golang.org/grpc from 1.55.0 to 1.56.0 in /exporters/otlp/otlptrace/otlptracegrpc Bump google.golang.org/grpc from 1.55.0 to 1.56.0 in /exporters/otlp/otlptrace Bump github.com/prometheus/client_golang from 1.15.1 to 1.16.0 in /example/prometheus Bump google.golang.org/grpc from 1.55.0 to 1.56.0 in /example/otel-collector Bump golang.org/x/sys from 0.8.0 to 0.9.0 in /sdk |
||
---|---|---|
.. | ||
internal | ||
migration | ||
test | ||
bridge_test.go | ||
bridge.go | ||
doc.go | ||
go.mod | ||
go.sum | ||
mix_test.go | ||
provider_test.go | ||
provider.go | ||
README.md | ||
util.go | ||
wrapper.go |
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()
...
}