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
John Watson 4475aaa8f8
Create README.md for the ot bridge (#2896)
* Create README.md

Some very bare-bones introductory documentation on how to use the ot bridge

* Update README.md

linting

* Update README.md

more linting

* Update bridge/opentracing/README.md

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

* Update bridge/opentracing/README.md

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

* Update bridge/opentracing/README.md

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

* Update bridge/opentracing/README.md

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

* Update bridge/opentracing/README.md

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

* Update bridge/opentracing/README.md

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

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
2022-05-17 05:13:49 -04:00
..
internal Add semconv/v1.10.0 (#2842) 2022-04-22 07:41:28 -07:00
migration Fix golint error of package comment form (#1487) 2021-02-04 09:55:44 -08:00
bridge.go Remove unnecessary internal package for noop instances (#2867) 2022-04-28 12:11:17 -07:00
doc.go Update doc.go (#2030) 2021-06-25 07:56:12 -07:00
go.mod Integrate go-build-tools crosslink (#2886) 2022-05-06 07:40:59 -07:00
go.sum Bump github.com/google/go-cmp from 0.5.7 to 0.5.8 (#2875) 2022-05-02 08:19:09 -07:00
mix_test.go Replace use of old term label with attribute (#2790) 2022-04-18 07:31:31 -07:00
README.md Create README.md for the ot bridge (#2896) 2022-05-17 05:13:49 -04:00
util.go Move tracing code to trace package (#1307) 2020-11-06 17:13:31 -05:00
wrapper.go Fix imports in all files except generated files in jaeger exporter (#2383) 2021-11-13 08:35:04 -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.