Skip to content

Commit ee56fb9

Browse files
authored
Make scope attributes as identifying for Meter (#5926)
Towards #3368
1 parent 3742c54 commit ee56fb9

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
3030
- `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5911)
3131
- `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc` now keeps the metadata already present in the context when `WithHeaders` is used. (#5915)
3232
- Support scope attributes and make them as identifying for `Tracer` in `go.opentelemetry.io/otel` and `go.opentelemetry.io/otel/sdk/trace`. (#5924)
33+
- Support scope attributes and make them as identifying for `Meter` in `go.opentelemetry.io/otel` and `go.opentelemetry.io/otel/sdk/metric`. (#5926)
3334

3435
<!-- Released section -->
3536
<!-- Don't change this section unless doing release -->

internal/global/meter.go

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func (p *meterProvider) Meter(name string, opts ...metric.MeterOption) metric.Me
6767
name: name,
6868
version: c.InstrumentationVersion(),
6969
schema: c.SchemaURL(),
70+
attrs: c.InstrumentationAttributes(),
7071
}
7172

7273
if p.meters == nil {

internal/global/meter_test.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"
1515

16+
"go.opentelemetry.io/otel/attribute"
1617
"go.opentelemetry.io/otel/metric"
1718
"go.opentelemetry.io/otel/metric/noop"
1819
)
@@ -397,17 +398,18 @@ func TestRegistrationDelegation(t *testing.T) {
397398
}
398399

399400
func TestMeterIdentity(t *testing.T) {
400-
type id struct{ name, ver, url string }
401+
type id struct{ name, ver, url, attr string }
401402

402403
ids := []id{
403-
{"name-a", "version-a", "url-a"},
404-
{"name-a", "version-a", "url-b"},
405-
{"name-a", "version-b", "url-a"},
406-
{"name-a", "version-b", "url-b"},
407-
{"name-b", "version-a", "url-a"},
408-
{"name-b", "version-a", "url-b"},
409-
{"name-b", "version-b", "url-a"},
410-
{"name-b", "version-b", "url-b"},
404+
{"name-a", "version-a", "url-a", ""},
405+
{"name-a", "version-a", "url-a", "attr"},
406+
{"name-a", "version-a", "url-b", ""},
407+
{"name-a", "version-b", "url-a", ""},
408+
{"name-a", "version-b", "url-b", ""},
409+
{"name-b", "version-a", "url-a", ""},
410+
{"name-b", "version-a", "url-b", ""},
411+
{"name-b", "version-b", "url-a", ""},
412+
{"name-b", "version-b", "url-b", ""},
411413
}
412414

413415
provider := &meterProvider{}
@@ -416,6 +418,7 @@ func TestMeterIdentity(t *testing.T) {
416418
i.name,
417419
metric.WithInstrumentationVersion(i.ver),
418420
metric.WithSchemaURL(i.url),
421+
metric.WithInstrumentationAttributes(attribute.String("key", i.attr)),
419422
)
420423
}
421424

sdk/metric/provider.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,17 @@ func (mp *MeterProvider) Meter(name string, options ...metric.MeterOption) metri
7676

7777
c := metric.NewMeterConfig(options...)
7878
s := instrumentation.Scope{
79-
Name: name,
80-
Version: c.InstrumentationVersion(),
81-
SchemaURL: c.SchemaURL(),
79+
Name: name,
80+
Version: c.InstrumentationVersion(),
81+
SchemaURL: c.SchemaURL(),
82+
Attributes: c.InstrumentationAttributes(),
8283
}
8384

8485
global.Info("Meter created",
8586
"Name", s.Name,
8687
"Version", s.Version,
8788
"SchemaURL", s.SchemaURL,
89+
"Attributes", s.Attributes,
8890
)
8991

9092
return mp.meters.Lookup(s, func() *meter {

sdk/metric/provider_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestMeterProviderReturnsSameMeter(t *testing.T) {
9696

9797
assert.Same(t, mtr, mp.Meter(""))
9898
assert.NotSame(t, mtr, mp.Meter("diff"))
99-
assert.Same(t, mtr, mp.Meter("", api.WithInstrumentationAttributes(attribute.String("k", "v")))) // TODO (#3368): Change to assert.NotSame.
99+
assert.NotSame(t, mtr, mp.Meter("", api.WithInstrumentationAttributes(attribute.String("k", "v"))))
100100
}
101101

102102
func TestEmptyMeterName(t *testing.T) {

0 commit comments

Comments
 (0)