1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-04 09:43:23 +02:00
opentelemetry-go/bridge/opentracing
Robert Lin 640a0cd8bc
bridge/opentracing: introduce NewTracerProvider that wraps TracerProvider instead of Tracer (#3116)
* bridge/opentracing: add NewDynamicWrappedTracerProvider for named tracers

* bridge/opentelmeetry: cache created Tracers, add tests

* bridge/opentracing: rename constructor to NewTracerProvider

* add license header

* Update docstring

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

* fix deprecated docstring

* rewrite new lookup TracerProvider as separate type

* update docstring

* add changelog entries

* Update bridge/opentracing/provider.go

Co-authored-by: Damien Mathieu <42@dmathieu.com>

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2023-01-11 16:59:06 -08:00
..
internal Upgrade all semconv dependencies to v1.16.0 (#3581) 2023-01-10 10:57:28 -08:00
migration Fix golint error of package comment form (#1487) 2021-02-04 09:55:44 -08:00
bridge_test.go Fix Http Status Code with Otel Bridge (#3265) 2022-10-13 10:44:40 -05:00
bridge.go Fix Http Status Code with Otel Bridge (#3265) 2022-10-13 10:44:40 -05:00
doc.go Update doc.go (#2030) 2021-06-25 07:56:12 -07:00
go.mod Release v1.11.2/v0.34.0 (#3512) 2022-12-05 13:43:20 -06:00
go.sum dependabot updates Mon Oct 31 15:24:02 UTC 2022 (#3433) 2022-10-31 08:54:41 -07: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 Create README.md for the ot bridge (#2896) 2022-05-17 05:13:49 -04: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.