From 6fd24fe8e5d575c575abdace8fff13a26fdcb10c Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 29 May 2024 07:05:44 -0700 Subject: [PATCH 1/3] Export the Instrument Empty method --- sdk/metric/instrument.go | 4 ++-- sdk/metric/view.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/metric/instrument.go b/sdk/metric/instrument.go index f9768fd11cc..70d1b433aa3 100644 --- a/sdk/metric/instrument.go +++ b/sdk/metric/instrument.go @@ -77,8 +77,8 @@ type Instrument struct { nonComparable // nolint: unused } -// empty returns if all fields of i are their zero-value. -func (i Instrument) empty() bool { +// Empty returns if all Instrument fields are their zero-value. +func (i Instrument) Empty() bool { return i.Name == "" && i.Description == "" && i.Kind == zeroInstrumentKind && diff --git a/sdk/metric/view.go b/sdk/metric/view.go index 11e334319d0..18e18334324 100644 --- a/sdk/metric/view.go +++ b/sdk/metric/view.go @@ -43,7 +43,7 @@ type View func(Instrument) (Stream, bool) // of the default. If you need to zero out an Stream field returned from a // View, create a View directly. func NewView(criteria Instrument, mask Stream) View { - if criteria.empty() { + if criteria.Empty() { global.Error( errEmptyView, "dropping view", "mask", mask, From 5a374f60a7fe3e2b4a34d3deffd4d96faa752e81 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 29 May 2024 07:10:31 -0700 Subject: [PATCH 2/3] Add changelog entry --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34bc4eda8dc..45e7defdabe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +### Added + +- The `Empty` method is added to the `Instrument` type in `go.opentelemetry.io/otel/sdk/metric`. + This method is used to check if an `Instrument` instance is a zero-value. (#5431) + ### 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) From 056a8f7633087d1cc2f83b452568abe642c7fe2e Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Wed, 29 May 2024 07:30:34 -0700 Subject: [PATCH 3/3] Rename Empty to IsEmpty --- CHANGELOG.md | 2 +- sdk/metric/instrument.go | 4 ++-- sdk/metric/view.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45e7defdabe..c3e888c9852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Added -- The `Empty` method is added to the `Instrument` type in `go.opentelemetry.io/otel/sdk/metric`. +- The `IsEmpty` method is added to the `Instrument` type in `go.opentelemetry.io/otel/sdk/metric`. This method is used to check if an `Instrument` instance is a zero-value. (#5431) ### Fixed diff --git a/sdk/metric/instrument.go b/sdk/metric/instrument.go index 70d1b433aa3..bbf56086738 100644 --- a/sdk/metric/instrument.go +++ b/sdk/metric/instrument.go @@ -77,8 +77,8 @@ type Instrument struct { nonComparable // nolint: unused } -// Empty returns if all Instrument fields are their zero-value. -func (i Instrument) Empty() bool { +// IsEmpty returns if all Instrument fields are their zero-value. +func (i Instrument) IsEmpty() bool { return i.Name == "" && i.Description == "" && i.Kind == zeroInstrumentKind && diff --git a/sdk/metric/view.go b/sdk/metric/view.go index 18e18334324..cd08c673248 100644 --- a/sdk/metric/view.go +++ b/sdk/metric/view.go @@ -43,7 +43,7 @@ type View func(Instrument) (Stream, bool) // of the default. If you need to zero out an Stream field returned from a // View, create a View directly. func NewView(criteria Instrument, mask Stream) View { - if criteria.Empty() { + if criteria.IsEmpty() { global.Error( errEmptyView, "dropping view", "mask", mask,