1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-10 09:50:58 +02:00
opentelemetry-go/bridge/opentracing
Tyler Yahn 813936187e
Support a global MeterProvider in go.opentelemetry.io/otel (#3818)
* Move ErrorHandler impl to internal

To avoid the import cycle, the otel/metric package needs to not import
otel. To achieve this, the error handling implementation is moved to the
otel/internal/global package where both can import the needed
functionality.

* Add global metric to go.opentelemetry.io/otel

* Crosslink and update to global metric in otel

* Add changes to changelog

* Set PR number in changelog

* Add global metric unit tests

* Rename MeterProivder() to GetMeterProivder()

* Add TODO to remove nolint comments
2023-03-01 11:16:03 -08:00
..
internal Implement IsSampled for OpenTelemetry bridgeSpanContext (#3570) 2023-02-23 13:11:48 -08:00
migration Fix golint error of package comment form (#1487) 2021-02-04 09:55:44 -08:00
test Support a global MeterProvider in go.opentelemetry.io/otel (#3818) 2023-03-01 11:16:03 -08:00
bridge_test.go Implement IsSampled for OpenTelemetry bridgeSpanContext (#3570) 2023-02-23 13:11:48 -08:00
bridge.go Implement IsSampled for OpenTelemetry bridgeSpanContext (#3570) 2023-02-23 13:11:48 -08:00
doc.go Update doc.go (#2030) 2021-06-25 07:56:12 -07:00
go.mod Support a global MeterProvider in go.opentelemetry.io/otel (#3818) 2023-03-01 11:16:03 -08:00
go.sum dependabot updates Sun Feb 26 15:49:13 UTC 2023 (#3804) 2023-02-26 07:58:24 -08:00
mix_test.go Replace use of old term label with attribute (#2790) 2022-04-18 07:31:31 -07:00
provider_test.go bridge/opentracing: introduce NewTracerProvider that wraps TracerProvider instead of Tracer (#3116) 2023-01-11 16:59:06 -08:00
provider.go bridge/opentracing: introduce NewTracerProvider that wraps TracerProvider instead of Tracer (#3116) 2023-01-11 16:59:06 -08:00
README.md Implement IsSampled for OpenTelemetry bridgeSpanContext (#3570) 2023-02-23 13:11:48 -08:00
util.go Use already enabled revive linter and add depguard (#2883) 2022-05-19 15:15:07 -05:00
wrapper.go bridge/opentracing: introduce NewTracerProvider that wraps TracerProvider instead of Tracer (#3116) 2023-01-11 16:59:06 -08: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.

SpanContext.IsSampled

Return the underlying OpenTelemetry Span.IsSampled value by converting a bridgeSpanContext.

type samplable interface {
	IsSampled() bool
}

var sc opentracing.SpanContext = ...
if s, ok := sc.(samplable); ok && s.IsSampled() {
	// Do something with sc knowing it is sampled.
}