Skip to content

Commit

Permalink
opentracing: Make schemaURL and scope attributes as identifying for T…
Browse files Browse the repository at this point in the history
…racer
  • Loading branch information
pellared committed Oct 30, 2024
1 parent 4f94b1e commit 6387a60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bridge/opentracing/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package opentracing // import "go.opentelemetry.io/otel/bridge/opentracing"
import (
"sync"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
)
Expand Down Expand Up @@ -38,6 +39,8 @@ func NewTracerProvider(bridge *BridgeTracer, provider trace.TracerProvider) *Tra
type wrappedTracerKey struct {
name string
version string
schema string
attrs attribute.Set
}

// Tracer creates a WrappedTracer that wraps the OpenTelemetry tracer for each call to
Expand All @@ -51,6 +54,8 @@ func (p *TracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T
key := wrappedTracerKey{
name: name,
version: c.InstrumentationVersion(),
schema: c.SchemaURL(),
attrs: c.InstrumentationAttributes(),
}

if t, ok := p.tracers[key]; ok {
Expand Down
7 changes: 6 additions & 1 deletion bridge/opentracing/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package opentracing
import (
"testing"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/bridge/opentracing/internal"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
Expand Down Expand Up @@ -64,11 +65,15 @@ func TestTracerProvider(t *testing.T) {
assertMockTracerName(t, tracer2, foobar)
tracer3 := provider.Tracer(bazbar)
assertMockTracerName(t, tracer3, bazbar)
tracer4 := provider.Tracer(bazbar, trace.WithInstrumentationAttributes(attribute.String("foo", "bar")))
assertMockTracerName(t, tracer4, bazbar)
tracer5 := provider.Tracer(bazbar, trace.WithSchemaURL("https://opentelemetry.io/schemas/1.2.0"))
assertMockTracerName(t, tracer5, bazbar)

if tracer1 != tracer2 {
t.Errorf("expected the same tracer, got different tracers")
}
if tracer1 == tracer3 || tracer2 == tracer3 {
if tracer1 == tracer3 || tracer2 == tracer3 || tracer3 == tracer4 || tracer3 == tracer5 || tracer4 == tracer5 {
t.Errorf("expected different tracers, got the same tracer")
}
})
Expand Down

0 comments on commit 6387a60

Please sign in to comment.