mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-26 21:05:00 +02:00
Export the Instrument IsEmpty method (#5431)
From https://github.com/open-telemetry/opentelemetry-go-contrib/pull/5654#discussion_r1617971674 Constructing a view requires an `Instrument` to be constructed. Given `NewView` will not return an error directly when an empty instrument is passed, it may be ideal for users to check this prior to making the call. Instead of having all use-cases copy this code, export it so they can just call the method.
This commit is contained in:
parent
8d4d3c875c
commit
c3569d85d9
@ -8,6 +8,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- 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
|
||||
|
||||
- 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)
|
||||
|
@ -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 {
|
||||
// IsEmpty returns if all Instrument fields are their zero-value.
|
||||
func (i Instrument) IsEmpty() bool {
|
||||
return i.Name == "" &&
|
||||
i.Description == "" &&
|
||||
i.Kind == zeroInstrumentKind &&
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user