mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-01-14 02:33:21 +02:00
Identify global Tracer
s and Meter
s with their schema URLs (#5426)
Fix #5403
This commit is contained in:
parent
982e96dd9b
commit
525fedbb26
@ -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
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
//
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user