diff --git a/CHANGELOG.md b/CHANGELOG.md index 34bc4eda8dc..f40860d88f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed - Log a warning to the OpenTelemetry internal logger when a `Record` in `go.opentelemetry.io/otel/sdk/log` drops an attribute due to a limit being reached. (#5376) +- Identify the `Tracer` returned from the global `TracerProvider` in `go.opentelemetry.io/otel/global` with its schema URL. (#5426) +- Identify the `Meter` returned from the global `MeterProvider` in `go.opentelemetry.io/otel/global` with its schema URL. (#5426) ## [1.27.0/0.49.0/0.3.0] 2024-05-21 diff --git a/internal/global/meter.go b/internal/global/meter.go index 590fa7385f3..cfd1df9bfa2 100644 --- a/internal/global/meter.go +++ b/internal/global/meter.go @@ -65,6 +65,7 @@ func (p *meterProvider) Meter(name string, opts ...metric.MeterOption) metric.Me key := il{ name: name, version: c.InstrumentationVersion(), + schema: c.SchemaURL(), } if p.meters == nil { diff --git a/internal/global/meter_test.go b/internal/global/meter_test.go index 19cc15884b9..144f89ef9c3 100644 --- a/internal/global/meter_test.go +++ b/internal/global/meter_test.go @@ -375,3 +375,39 @@ func TestRegistrationDelegation(t *testing.T) { assert.NoError(t, reg1.Unregister(), "duplicate unregister calls") }) } + +func TestMeterIdentity(t *testing.T) { + type id struct{ name, ver, url string } + + ids := []id{ + {"name-a", "version-a", "url-a"}, + {"name-a", "version-a", "url-b"}, + {"name-a", "version-b", "url-a"}, + {"name-a", "version-b", "url-b"}, + {"name-b", "version-a", "url-a"}, + {"name-b", "version-a", "url-b"}, + {"name-b", "version-b", "url-a"}, + {"name-b", "version-b", "url-b"}, + } + + provider := &meterProvider{} + newMeter := func(i id) metric.Meter { + return provider.Meter( + i.name, + metric.WithInstrumentationVersion(i.ver), + metric.WithSchemaURL(i.url), + ) + } + + for i, id0 := range ids { + for j, id1 := range ids { + l0, l1 := newMeter(id0), newMeter(id1) + + if i == j { + assert.Samef(t, l0, l1, "Meter(%v) != Meter(%v)", id0, id1) + } else { + assert.NotSamef(t, l0, l1, "Meter(%v) == Meter(%v)", id0, id1) + } + } + } +} diff --git a/internal/global/trace.go b/internal/global/trace.go index 596f716f40c..e31f442b48f 100644 --- a/internal/global/trace.go +++ b/internal/global/trace.go @@ -86,6 +86,7 @@ func (p *tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T key := il{ name: name, version: c.InstrumentationVersion(), + schema: c.SchemaURL(), } if p.tracers == nil { @@ -101,10 +102,7 @@ func (p *tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T return t } -type il struct { - name string - version string -} +type il struct{ name, version, schema string } // tracer is a placeholder for a trace.Tracer. // diff --git a/internal/global/trace_test.go b/internal/global/trace_test.go index cc0fd73b526..0eb34e3a3f6 100644 --- a/internal/global/trace_test.go +++ b/internal/global/trace_test.go @@ -235,3 +235,39 @@ func TestSpanContextPropagatedWithNonRecordingSpan(t *testing.T) { assert.Equal(t, sc, span.SpanContext()) assert.False(t, span.IsRecording()) } + +func TestTracerIdentity(t *testing.T) { + type id struct{ name, ver, url string } + + ids := []id{ + {"name-a", "version-a", "url-a"}, + {"name-a", "version-a", "url-b"}, + {"name-a", "version-b", "url-a"}, + {"name-a", "version-b", "url-b"}, + {"name-b", "version-a", "url-a"}, + {"name-b", "version-a", "url-b"}, + {"name-b", "version-b", "url-a"}, + {"name-b", "version-b", "url-b"}, + } + + provider := &tracerProvider{} + newTracer := func(i id) trace.Tracer { + return provider.Tracer( + i.name, + trace.WithInstrumentationVersion(i.ver), + trace.WithSchemaURL(i.url), + ) + } + + for i, id0 := range ids { + for j, id1 := range ids { + l0, l1 := newTracer(id0), newTracer(id1) + + if i == j { + assert.Samef(t, l0, l1, "Tracer(%v) != Tracer(%v)", id0, id1) + } else { + assert.NotSamef(t, l0, l1, "Tracer(%v) == Tracer(%v)", id0, id1) + } + } + } +}