Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
internal/tracer: correctly set Tracer names in OpenTracing bridge (#4…
Browse files Browse the repository at this point in the history
…0945)

The existing wrapped OpenTelemetry TracerProvider for bridging
OpenTracing API calls to OpenTelemetryAPI calls discards the name
provided to the `Tracer()` constructor on it, since it uses a fixed
tracer that we provide it.

This change leverages an upstream patch,
open-telemetry/opentelemetry-go#3116 (dependency
update: https://github.com/sourcegraph/sourcegraph/pull/47126), that
allows wrapped tracers to be created on the fly with the provided
parameters, so that we can more accurately see the instrumentation
source.

## Test plan

Via the bridge, we can see that the Tracer used is the bridge tracer:

<img width="1322" alt="image"
src="https://user-images.githubusercontent.com/23356519/186957763-60faee32-e6a5-4bda-bb64-fddb82eacc0d.png">

Via direct usage of OpenTelemetry, we can see that the Tracer used has
the custom name set:

<img width="1448" alt="image"
src="https://user-images.githubusercontent.com/23356519/186957773-c6ff7643-3f89-498d-857b-1dd79b36508d.png">
  • Loading branch information
bobheadxi authored Feb 23, 2023
1 parent 3c31223 commit 1cb5bc4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/trace/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (t Tracer) New(ctx context.Context, family, title string, tags ...Tag) (*Tr

var otelSpan oteltrace.Span
ctx, otelSpan = t.TracerProvider.
Tracer("internal/trace").
Tracer("sourcegraph/internal/trace").
Start(ctx, family,
oteltrace.WithAttributes(attribute.String("title", title)),
oteltrace.WithAttributes(tagSet(tags).toAttributes()...))
Expand Down
9 changes: 4 additions & 5 deletions internal/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,11 @@ func newBridgeTracers(logger log.Logger, provider *oteltracesdk.TracerProvider,

// Set up otBridgeTracer for converting OpenTracing API calls to OpenTelemetry, and
// otelTracerProvider for the inverse.
//
// TODO: Unfortunately, this wrapped tracer provider discards the name provided to
// the Tracer() constructor on it, since it uses a fixed tracer that we provide it.
// This is implemented in https://github.com/sourcegraph/sourcegraph/pull/40945
otBridgeTracer, otelTracerProvider := otelbridge.NewTracerPair(provider.Tracer("internal/tracer/otel"))
otBridgeTracer := otelbridge.NewBridgeTracer()
otBridgeTracer.SetTextMapPropagator(compositePropagator)
otelTracerProvider := otelbridge.NewTracerProvider(otBridgeTracer, provider)
otBridgeTracer.SetOpenTelemetryTracer(
otelTracerProvider.Tracer("sourcegraph/internal/tracer.opentracing-bridge"))

// Set up logging
otelLogger := logger.AddCallerSkip(2).Scoped("otel", "OpenTelemetry library")
Expand Down

0 comments on commit 1cb5bc4

Please sign in to comment.