1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-26 21:05:00 +02:00

Make scope attributes as identifying for Meter (#5926)

Towards https://github.com/open-telemetry/opentelemetry-go/issues/3368
This commit is contained in:
Robert Pająk 2024-10-30 06:29:32 +01:00 committed by GitHub
parent 3742c54497
commit ee56fb97e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 20 additions and 13 deletions

View File

@ -30,6 +30,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5911)
- `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5915)
- 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)
<!-- Released section -->
<!-- Don't change this section unless doing release -->

View File

@ -67,6 +67,7 @@ func (p *meterProvider) Meter(name string, opts ...metric.MeterOption) metric.Me
name: name,
version: c.InstrumentationVersion(),
schema: c.SchemaURL(),
attrs: c.InstrumentationAttributes(),
}
if p.meters == nil {

View File

@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
@ -397,17 +398,18 @@ func TestRegistrationDelegation(t *testing.T) {
}
func TestMeterIdentity(t *testing.T) {
type id struct{ name, ver, url string }
type id struct{ name, ver, url, attr 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"},
{"name-a", "version-a", "url-a", ""},
{"name-a", "version-a", "url-a", "attr"},
{"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{}
@ -416,6 +418,7 @@ func TestMeterIdentity(t *testing.T) {
i.name,
metric.WithInstrumentationVersion(i.ver),
metric.WithSchemaURL(i.url),
metric.WithInstrumentationAttributes(attribute.String("key", i.attr)),
)
}

View File

@ -76,15 +76,17 @@ func (mp *MeterProvider) Meter(name string, options ...metric.MeterOption) metri
c := metric.NewMeterConfig(options...)
s := instrumentation.Scope{
Name: name,
Version: c.InstrumentationVersion(),
SchemaURL: c.SchemaURL(),
Name: name,
Version: c.InstrumentationVersion(),
SchemaURL: c.SchemaURL(),
Attributes: c.InstrumentationAttributes(),
}
global.Info("Meter created",
"Name", s.Name,
"Version", s.Version,
"SchemaURL", s.SchemaURL,
"Attributes", s.Attributes,
)
return mp.meters.Lookup(s, func() *meter {

View File

@ -96,7 +96,7 @@ func TestMeterProviderReturnsSameMeter(t *testing.T) {
assert.Same(t, mtr, mp.Meter(""))
assert.NotSame(t, mtr, mp.Meter("diff"))
assert.Same(t, mtr, mp.Meter("", api.WithInstrumentationAttributes(attribute.String("k", "v")))) // TODO (#3368): Change to assert.NotSame.
assert.NotSame(t, mtr, mp.Meter("", api.WithInstrumentationAttributes(attribute.String("k", "v"))))
}
func TestEmptyMeterName(t *testing.T) {