diff --git a/sdk/metric/meter.go b/sdk/metric/meter.go index daf892dd1dc..c77a4fa54d8 100644 --- a/sdk/metric/meter.go +++ b/sdk/metric/meter.go @@ -31,7 +31,7 @@ import ( ) // meterRegistry keeps a record of initialized meters for instrumentation -// libraries. A meter is unique to an instrumentation library and if multiple +// scopes. A meter is unique to an instrumentation scope and if multiple // requests for that meter are made a meterRegistry ensure the same instance // is used. // @@ -43,31 +43,31 @@ import ( type meterRegistry struct { sync.Mutex - meters map[instrumentation.Library]*meter + meters map[instrumentation.Scope]*meter } -// Get returns a registered meter matching the instrumentation library if it +// Get returns a registered meter matching the instrumentation scope if it // exists in the meterRegistry. Otherwise, a new meter configured for the -// instrumentation library is registered and then returned. +// instrumentation scope is registered and then returned. // // Get is safe to call concurrently. -func (r *meterRegistry) Get(l instrumentation.Library) *meter { +func (r *meterRegistry) Get(s instrumentation.Scope) *meter { r.Lock() defer r.Unlock() if r.meters == nil { - m := &meter{Library: l} - r.meters = map[instrumentation.Library]*meter{l: m} + m := &meter{Scope: s} + r.meters = map[instrumentation.Scope]*meter{s: m} return m } - m, ok := r.meters[l] + m, ok := r.meters[s] if ok { return m } - m = &meter{Library: l} - r.meters[l] = m + m = &meter{Scope: s} + r.meters[s] = m return m } @@ -91,7 +91,7 @@ func (r *meterRegistry) Range(f func(*meter) bool) { // produced by an instrumentation scope will use metric instruments from a // single meter. type meter struct { - instrumentation.Library + instrumentation.Scope // TODO (#2815, 2814): implement. } diff --git a/sdk/metric/meter_test.go b/sdk/metric/meter_test.go index 38aa7ae28d9..54ae767b20b 100644 --- a/sdk/metric/meter_test.go +++ b/sdk/metric/meter_test.go @@ -26,24 +26,24 @@ import ( ) func TestMeterRegistry(t *testing.T) { - il0 := instrumentation.Library{Name: "zero"} - il1 := instrumentation.Library{Name: "one"} + is0 := instrumentation.Scope{Name: "zero"} + is1 := instrumentation.Scope{Name: "one"} r := meterRegistry{} var m0 *meter t.Run("ZeroValueGetDoesNotPanic", func(t *testing.T) { - assert.NotPanics(t, func() { m0 = r.Get(il0) }) - assert.Equal(t, il0, m0.Library, "uninitialized meter returned") + assert.NotPanics(t, func() { m0 = r.Get(is0) }) + assert.Equal(t, is0, m0.Scope, "uninitialized meter returned") }) - m01 := r.Get(il0) + m01 := r.Get(is0) t.Run("GetSameMeter", func(t *testing.T) { - assert.Samef(t, m0, m01, "returned different meters: %v", il0) + assert.Samef(t, m0, m01, "returned different meters: %v", is0) }) - m1 := r.Get(il1) + m1 := r.Get(is1) t.Run("GetDifferentMeter", func(t *testing.T) { - assert.NotSamef(t, m0, m1, "returned same meters: %v", il1) + assert.NotSamef(t, m0, m1, "returned same meters: %v", is1) }) t.Run("RangeComplete", func(t *testing.T) { diff --git a/sdk/metric/provider.go b/sdk/metric/provider.go index 5b939f93251..a3c12ea5808 100644 --- a/sdk/metric/provider.go +++ b/sdk/metric/provider.go @@ -76,7 +76,7 @@ func NewMeterProvider(options ...Option) *MeterProvider { // This method is safe to call concurrently. func (mp *MeterProvider) Meter(name string, options ...metric.MeterOption) metric.Meter { c := metric.NewMeterConfig(options...) - return mp.meters.Get(instrumentation.Library{ + return mp.meters.Get(instrumentation.Scope{ Name: name, Version: c.InstrumentationVersion(), SchemaURL: c.SchemaURL(), diff --git a/sdk/metric/view/instrument.go b/sdk/metric/view/instrument.go index 10d30243fa8..3df030aa4ba 100644 --- a/sdk/metric/view/instrument.go +++ b/sdk/metric/view/instrument.go @@ -24,7 +24,7 @@ import ( // Instrument uniquely identifies an instrument within a meter. type Instrument struct { - Scope instrumentation.Library + Scope instrumentation.Scope Name string Description string diff --git a/sdk/metric/view/view.go b/sdk/metric/view/view.go index 35483f59ab1..03bfd8eec73 100644 --- a/sdk/metric/view/view.go +++ b/sdk/metric/view/view.go @@ -40,7 +40,7 @@ import ( type View struct { instrumentName *regexp.Regexp hasWildcard bool - scope instrumentation.Library + scope instrumentation.Scope filter attribute.Filter name string @@ -57,9 +57,9 @@ func New(opts ...Option) (View, error) { v = opt.apply(v) } - emptyLibrary := instrumentation.Library{} + emptyScope := instrumentation.Scope{} if v.instrumentName == nil && - v.scope == emptyLibrary { + v.scope == emptyScope { return View{}, fmt.Errorf("must provide at least 1 match option") } @@ -104,23 +104,23 @@ func (v View) matchName(name string) bool { return v.instrumentName == nil || v.instrumentName.MatchString(name) } -func (v View) matchLibraryName(name string) bool { +func (v View) matchScopeName(name string) bool { return v.scope.Name == "" || name == v.scope.Name } -func (v View) matchLibraryVersion(version string) bool { +func (v View) matchScopeVersion(version string) bool { return v.scope.Version == "" || version == v.scope.Version } -func (v View) matchLibrarySchemaURL(schemaURL string) bool { +func (v View) matchScopeSchemaURL(schemaURL string) bool { return v.scope.SchemaURL == "" || schemaURL == v.scope.SchemaURL } func (v View) match(i Instrument) bool { return v.matchName(i.Name) && - v.matchLibraryName(i.Scope.Name) && - v.matchLibrarySchemaURL(i.Scope.SchemaURL) && - v.matchLibraryVersion(i.Scope.Version) + v.matchScopeName(i.Scope.Name) && + v.matchScopeSchemaURL(i.Scope.SchemaURL) && + v.matchScopeVersion(i.Scope.Version) } // Option applies a Configuration option value to a View. All options @@ -155,12 +155,12 @@ func MatchInstrumentName(name string) Option { // TODO (#2813): Implement MatchInstrumentKind when InstrumentKind is defined. // TODO (#2813): Implement MatchNumberKind when NumberKind is defined. -// MatchInstrumentationLibrary will do an exact match on any +// MatchInstrumentationScope will do an exact match on any // instrumentation.Scope field that is non-empty (""). The default is to match all // instrumentation scopes. -func MatchInstrumentationLibrary(lib instrumentation.Library) Option { +func MatchInstrumentationScope(scope instrumentation.Scope) Option { return optionFunc(func(v View) View { - v.scope = lib + v.scope = scope return v }) } diff --git a/sdk/metric/view/view_test.go b/sdk/metric/view/view_test.go index 10696ff00a6..2d95c437355 100644 --- a/sdk/metric/view/view_test.go +++ b/sdk/metric/view/view_test.go @@ -28,7 +28,7 @@ import ( ) var matchInstrument = Instrument{ - Scope: instrumentation.Library{ + Scope: instrumentation.Scope{ Name: "bar", Version: "v1.0.0", SchemaURL: "stuff.test/", @@ -38,7 +38,7 @@ var matchInstrument = Instrument{ } var noMatchInstrument = Instrument{ - Scope: instrumentation.Library{ + Scope: instrumentation.Scope{ Name: "notfoo", Version: "v0.x.0", SchemaURL: "notstuff.test/", @@ -65,9 +65,9 @@ func TestViewTransformInstrument(t *testing.T) { notMatch: emptyDescription, }, { - name: "Library name", + name: "Scope name", options: []Option{ - MatchInstrumentationLibrary(instrumentation.Library{ + MatchInstrumentationScope(instrumentation.Scope{ Name: "bar", }), }, @@ -75,9 +75,9 @@ func TestViewTransformInstrument(t *testing.T) { notMatch: emptyDescription, }, { - name: "Library version", + name: "Scope version", options: []Option{ - MatchInstrumentationLibrary(instrumentation.Library{ + MatchInstrumentationScope(instrumentation.Scope{ Version: "v1.0.0", }), }, @@ -86,9 +86,9 @@ func TestViewTransformInstrument(t *testing.T) { notMatch: emptyDescription, }, { - name: "Library SchemaURL", + name: "Scope SchemaURL", options: []Option{ - MatchInstrumentationLibrary(instrumentation.Library{ + MatchInstrumentationScope(instrumentation.Scope{ SchemaURL: "stuff.test/", }), }, @@ -107,7 +107,7 @@ func TestViewTransformInstrument(t *testing.T) { name: "composite literal name", options: []Option{ MatchInstrumentName("foo"), - MatchInstrumentationLibrary(instrumentation.Library{ + MatchInstrumentationScope(instrumentation.Scope{ Name: "bar", Version: "v1.0.0", SchemaURL: "stuff.test/", @@ -123,7 +123,7 @@ func TestViewTransformInstrument(t *testing.T) { WithRename("baz"), }, match: Instrument{ - Scope: instrumentation.Library{ + Scope: instrumentation.Scope{ Name: "bar", Version: "v1.0.0", SchemaURL: "stuff.test/", @@ -140,7 +140,7 @@ func TestViewTransformInstrument(t *testing.T) { WithSetDescription("descriptive stuff"), }, match: Instrument{ - Scope: instrumentation.Library{ + Scope: instrumentation.Scope{ Name: "bar", Version: "v1.0.0", SchemaURL: "stuff.test/",