1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-28 21:09:17 +02:00
opentelemetry-go/bridge/opentracing
renovate[bot] f5872418a6
chore(deps): update google.golang.org/genproto/googleapis/rpc digest to ddb44da (#5715)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[google.golang.org/genproto/googleapis/rpc](https://togithub.com/googleapis/go-genproto)
| indirect | digest | `8ffd90a` -> `ddb44da` |
|
[google.golang.org/genproto/googleapis/rpc](https://togithub.com/googleapis/go-genproto)
| require | digest | `8ffd90a` -> `ddb44da` |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View the
[repository job
log](https://developer.mend.io/github/open-telemetry/opentelemetry-go).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yNi4xIiwidXBkYXRlZEluVmVyIjoiMzguMjYuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiU2tpcCBDaGFuZ2Vsb2ciLCJkZXBlbmRlbmNpZXMiXX0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-08-16 10:30:11 -07: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 chore(deps): update google.golang.org/genproto/googleapis/rpc digest to ddb44da (#5715) 2024-08-16 10:30:11 -07:00
bridge_test.go [chore] Simplify the license header (#4987) 2024-02-29 07:05:28 +01:00
bridge.go [chore] Simplify the license header (#4987) 2024-02-29 07:05:28 +01:00
doc.go [chore] Simplify the license header (#4987) 2024-02-29 07:05:28 +01:00
go.mod Releases v1.28.0/v0.50.0/v0.4.0 (#5569) 2024-07-02 13:29:45 -07:00
go.sum fix(deps): update module github.com/go-logr/logr to v1.4.2 (#5393) 2024-05-21 13:58:14 -07:00
mix_test.go [chore] Simplify the license header (#4987) 2024-02-29 07:05:28 +01:00
provider_test.go [chore] Simplify the license header (#4987) 2024-02-29 07:05:28 +01:00
provider.go [chore] Simplify the license header (#4987) 2024-02-29 07:05:28 +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()
	...
}