Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opentracing: Make schemaURL and scope attributes as identifying for Tracer #5931

Merged
merged 3 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Support scope attributes and make them as identifying for `Tracer` in `go.opentelemetry.io/otel` and `go.opentelemetry.io/otel/sdk/trace`. (#5924)
- Support scope attributes and make them as identifying for `Meter` in `go.opentelemetry.io/otel` and `go.opentelemetry.io/otel/sdk/metric`. (#5926)
- Support scope attributes and make them as identifying for `Logger` in `go.opentelemetry.io/otel` and `go.opentelemetry.io/otel/sdk/log`. (#5925)
- Make schema URL and scope attributes as identifying for `Tracer` in `go.opentelemetry.io/otel/bridge/opentracing`. (#5931)

<!-- Released section -->
<!-- Don't change this section unless doing release -->
Expand Down
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
42 changes: 31 additions & 11 deletions 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 @@ -58,18 +59,37 @@ func TestTracerProvider(t *testing.T) {
})

t.Run("Repeated requests to create a tracer should provide the existing tracer", func(t *testing.T) {
tracer1 := provider.Tracer(foobar)
assertMockTracerName(t, tracer1, foobar)
tracer2 := provider.Tracer(foobar)
assertMockTracerName(t, tracer2, foobar)
tracer3 := provider.Tracer(bazbar)
assertMockTracerName(t, tracer3, bazbar)

if tracer1 != tracer2 {
t.Errorf("expected the same tracer, got different tracers")
tracerFns := []func() trace.Tracer{
func() trace.Tracer {
return provider.Tracer(foobar)
},
func() trace.Tracer {
return provider.Tracer(bazbar)
},
func() trace.Tracer {
return provider.Tracer(foobar, trace.WithSchemaURL("https://opentelemetry.io/schemas/1.2.0"))
},
func() trace.Tracer {
return provider.Tracer(foobar, trace.WithInstrumentationAttributes(attribute.String("foo", "bar")))
},
func() trace.Tracer {
return provider.Tracer(foobar, trace.WithSchemaURL("https://opentelemetry.io/schemas/1.2.0"), trace.WithInstrumentationAttributes(attribute.String("foo", "bar")))
},
}
if tracer1 == tracer3 || tracer2 == tracer3 {
t.Errorf("expected different tracers, got the same tracer")

for i, fn1 := range tracerFns {
for j, fn2 := range tracerFns {
tracer1, tracer2 := fn1(), fn2()
if i == j {
if tracer1 != tracer2 {
t.Errorf("expected the same tracer, got different tracers; i=%d j=%d", i, j)
}
} else {
if tracer1 == tracer2 {
t.Errorf("expected different tracers, got the same tracer; i=%d j=%d", i, j)
}
}
}
}
})
}
Loading