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

Identify global Tracers and Meters with their schema URLs #5426

Merged
merged 7 commits into from
May 30, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions internal/global/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 36 additions & 0 deletions internal/global/meter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
6 changes: 2 additions & 4 deletions internal/global/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
//
Expand Down
36 changes: 36 additions & 0 deletions internal/global/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}