diff --git a/sdk/metric/view/view.go b/sdk/metric/view/view.go index 1e55cfd6dfc..4a80708c880 100644 --- a/sdk/metric/view/view.go +++ b/sdk/metric/view/view.go @@ -60,7 +60,8 @@ func New(opts ...Option) (View, error) { emptyScope := instrumentation.Scope{} if v.instrumentName == nil && - v.scope == emptyScope { + v.scope == emptyScope && + v.instrumentKind == undefinedInstrument { return View{}, fmt.Errorf("must provide at least 1 match option") } @@ -119,6 +120,7 @@ func (v View) matchScopeVersion(version string) bool { func (v View) matchScopeSchemaURL(schemaURL string) bool { return v.scope.SchemaURL == "" || schemaURL == v.scope.SchemaURL } + func (v View) matchInstrumentKind(kind InstrumentKind) bool { return v.instrumentKind == undefinedInstrument || kind == v.instrumentKind } diff --git a/sdk/metric/view/view_test.go b/sdk/metric/view/view_test.go index 612767e3b9e..68412f365bb 100644 --- a/sdk/metric/view/view_test.go +++ b/sdk/metric/view/view_test.go @@ -34,6 +34,7 @@ var matchInstrument = Instrument{ SchemaURL: "stuff.test/", }, Name: "foo", + Kind: SyncCounter, Description: "", } @@ -45,6 +46,7 @@ var noMatchInstrument = Instrument{ }, Name: "notstuff", Description: "", + Kind: undefinedInstrument, } var emptyDescription = Instrument{} @@ -94,6 +96,13 @@ func TestViewTransformInstrument(t *testing.T) { }, match: matchInstrument, notMatch: emptyDescription, + }, { + name: "instrument kind", + options: []Option{ + MatchInstrumentKind(SyncCounter), + }, + match: matchInstrument, + notMatch: emptyDescription, }, { name: "Expands *", @@ -130,6 +139,7 @@ func TestViewTransformInstrument(t *testing.T) { }, Name: "baz", Description: "", + Kind: SyncCounter, }, notMatch: emptyDescription, }, @@ -147,6 +157,7 @@ func TestViewTransformInstrument(t *testing.T) { }, Name: "foo", Description: "descriptive stuff", + Kind: SyncCounter, }, notMatch: emptyDescription, },