1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-24 20:14:40 +02:00
opentelemetry-go/bridge/opentracing
2024-12-23 16:47:07 +00:00
..
internal Upgrade semconv use to v1.26.0 (#5490) 2024-06-06 09:36:59 -07:00
migration Add READMEs to every package (#5103) 2024-03-26 20:13:54 +01:00
test fix(deps): update googleapis to 3abc09e 2024-12-23 16:47:07 +00:00
bridge_test.go [chore]: enable expected-actual rule from testifylint (#5848) 2024-09-26 12:04:33 +02:00
bridge.go [chore]: enable int-conversion rule of perfsprint (#5964) 2024-11-14 19:17:37 +01:00
doc.go [chore] Simplify the license header (#4987) 2024-02-29 07:05:28 +01:00
go.mod Release v1.33.0 (#6035) 2024-12-12 09:54:13 -08:00
go.sum chore(deps): update module go.opentelemetry.io/auto/sdk to v1.1.0 (#6025) 2024-12-05 12:57:07 -08:00
mix_test.go Fix lint issues for golangci-lint 1.62.0 (#5967) 2024-11-13 08:58:59 +01:00
provider_test.go opentracing: Make schemaURL and scope attributes as identifying for Tracer (#5931) 2024-10-31 10:20:09 +01:00
provider.go opentracing: Make schemaURL and scope attributes as identifying for Tracer (#5931) 2024-10-31 10:20:09 +01:00
README.md Added methods for SpanID and TraceID on bridgeSpanContext (#3966) 2023-04-25 10:11:03 -07:00
util.go [chore] Simplify the license header (#4987) 2024-02-29 07:05:28 +01:00
wrapper.go [chore] Simplify the license header (#4987) 2024-02-29 07:05:28 +01:00

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()
	...
}