1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-14 02:33:21 +02:00

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

Fixes https://github.com/open-telemetry/opentelemetry-go/issues/5928
This commit is contained in:
Robert Pająk 2024-10-31 10:20:09 +01:00 committed by GitHub
parent 4f94b1e661
commit 3cc4857fd8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 11 deletions

View File

@ -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 -->

View File

@ -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"
)
@ -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
@ -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 {

View File

@ -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"
@ -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)
}
}
}
}
})
}