From b14f6316c046f68cfca484f1426b844b3ae2d510 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Tue, 16 Dec 2025 19:04:38 +0000 Subject: [PATCH 1/4] Add DefaultDisabled to the metric api --- metric/asyncfloat64.go | 36 ++++++++++++----- metric/asyncfloat64_test.go | 12 ++++-- metric/asyncint64.go | 36 ++++++++++++----- metric/asyncint64_test.go | 12 ++++-- metric/example_test.go | 20 ++++++++++ metric/instrument.go | 79 +++++++++++++++++++++++++++++++++++++ metric/syncfloat64.go | 36 ++++++++++++++--- metric/syncfloat64_test.go | 17 ++++---- metric/syncint64.go | 36 ++++++++++++++--- metric/syncint64_test.go | 17 ++++---- 10 files changed, 251 insertions(+), 50 deletions(-) diff --git a/metric/asyncfloat64.go b/metric/asyncfloat64.go index b7fc973a66c..e88c6618486 100644 --- a/metric/asyncfloat64.go +++ b/metric/asyncfloat64.go @@ -41,9 +41,10 @@ type Float64ObservableCounter interface { // Float64ObservableCounterConfig contains options for asynchronous counter // instruments that record float64 values. type Float64ObservableCounterConfig struct { - description string - unit string - callbacks []Float64Callback + description string + unit string + defaultDisabled bool + callbacks []Float64Callback } // NewFloat64ObservableCounterConfig returns a new @@ -66,6 +67,11 @@ func (c Float64ObservableCounterConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Float64ObservableCounterConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // Callbacks returns the configured callbacks. func (c Float64ObservableCounterConfig) Callbacks() []Float64Callback { return c.callbacks @@ -99,9 +105,10 @@ type Float64ObservableUpDownCounter interface { // Float64ObservableUpDownCounterConfig contains options for asynchronous // counter instruments that record float64 values. type Float64ObservableUpDownCounterConfig struct { - description string - unit string - callbacks []Float64Callback + description string + unit string + defaultDisabled bool + callbacks []Float64Callback } // NewFloat64ObservableUpDownCounterConfig returns a new @@ -126,6 +133,11 @@ func (c Float64ObservableUpDownCounterConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Float64ObservableUpDownCounterConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // Callbacks returns the configured callbacks. func (c Float64ObservableUpDownCounterConfig) Callbacks() []Float64Callback { return c.callbacks @@ -158,9 +170,10 @@ type Float64ObservableGauge interface { // Float64ObservableGaugeConfig contains options for asynchronous counter // instruments that record float64 values. type Float64ObservableGaugeConfig struct { - description string - unit string - callbacks []Float64Callback + description string + unit string + defaultDisabled bool + callbacks []Float64Callback } // NewFloat64ObservableGaugeConfig returns a new [Float64ObservableGaugeConfig] @@ -183,6 +196,11 @@ func (c Float64ObservableGaugeConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Float64ObservableGaugeConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // Callbacks returns the configured callbacks. func (c Float64ObservableGaugeConfig) Callbacks() []Float64Callback { return c.callbacks diff --git a/metric/asyncfloat64_test.go b/metric/asyncfloat64_test.go index 14934e3c160..d42d90db81c 100644 --- a/metric/asyncfloat64_test.go +++ b/metric/asyncfloat64_test.go @@ -15,15 +15,17 @@ import ( func TestFloat64ObservableConfiguration(t *testing.T) { const ( - token float64 = 43 - desc = "Instrument description." - uBytes = "By" + token float64 = 43 + desc = "Instrument description." + uBytes = "By" + defaultDisabled = true ) run := func(got float64ObservableConfig) func(*testing.T) { return func(t *testing.T) { assert.Equal(t, desc, got.Description(), "description") assert.Equal(t, uBytes, got.Unit(), "unit") + assert.Equal(t, defaultDisabled, got.DefaultDisabled(), "defaultDisabled") // Functions are not comparable. cBacks := got.Callbacks() @@ -44,6 +46,7 @@ func TestFloat64ObservableConfiguration(t *testing.T) { NewFloat64ObservableCounterConfig( WithDescription(desc), WithUnit(uBytes), + WithDefaultDisabled(), WithFloat64Callback(cback), ), )) @@ -52,6 +55,7 @@ func TestFloat64ObservableConfiguration(t *testing.T) { NewFloat64ObservableUpDownCounterConfig( WithDescription(desc), WithUnit(uBytes), + WithDefaultDisabled(), WithFloat64Callback(cback), ), )) @@ -60,6 +64,7 @@ func TestFloat64ObservableConfiguration(t *testing.T) { NewFloat64ObservableGaugeConfig( WithDescription(desc), WithUnit(uBytes), + WithDefaultDisabled(), WithFloat64Callback(cback), ), )) @@ -68,6 +73,7 @@ func TestFloat64ObservableConfiguration(t *testing.T) { type float64ObservableConfig interface { Description() string Unit() string + DefaultDisabled() bool Callbacks() []Float64Callback } diff --git a/metric/asyncint64.go b/metric/asyncint64.go index 4404b71a22f..27405b68284 100644 --- a/metric/asyncint64.go +++ b/metric/asyncint64.go @@ -40,9 +40,10 @@ type Int64ObservableCounter interface { // Int64ObservableCounterConfig contains options for asynchronous counter // instruments that record int64 values. type Int64ObservableCounterConfig struct { - description string - unit string - callbacks []Int64Callback + description string + unit string + defaultDisabled bool + callbacks []Int64Callback } // NewInt64ObservableCounterConfig returns a new [Int64ObservableCounterConfig] @@ -65,6 +66,11 @@ func (c Int64ObservableCounterConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Int64ObservableCounterConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // Callbacks returns the configured callbacks. func (c Int64ObservableCounterConfig) Callbacks() []Int64Callback { return c.callbacks @@ -98,9 +104,10 @@ type Int64ObservableUpDownCounter interface { // Int64ObservableUpDownCounterConfig contains options for asynchronous counter // instruments that record int64 values. type Int64ObservableUpDownCounterConfig struct { - description string - unit string - callbacks []Int64Callback + description string + unit string + defaultDisabled bool + callbacks []Int64Callback } // NewInt64ObservableUpDownCounterConfig returns a new @@ -125,6 +132,11 @@ func (c Int64ObservableUpDownCounterConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Int64ObservableUpDownCounterConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // Callbacks returns the configured callbacks. func (c Int64ObservableUpDownCounterConfig) Callbacks() []Int64Callback { return c.callbacks @@ -157,9 +169,10 @@ type Int64ObservableGauge interface { // Int64ObservableGaugeConfig contains options for asynchronous counter // instruments that record int64 values. type Int64ObservableGaugeConfig struct { - description string - unit string - callbacks []Int64Callback + description string + unit string + defaultDisabled bool + callbacks []Int64Callback } // NewInt64ObservableGaugeConfig returns a new [Int64ObservableGaugeConfig] @@ -182,6 +195,11 @@ func (c Int64ObservableGaugeConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Int64ObservableGaugeConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // Callbacks returns the configured callbacks. func (c Int64ObservableGaugeConfig) Callbacks() []Int64Callback { return c.callbacks diff --git a/metric/asyncint64_test.go b/metric/asyncint64_test.go index 5c58b7ca13b..30bcc3caaa8 100644 --- a/metric/asyncint64_test.go +++ b/metric/asyncint64_test.go @@ -15,15 +15,17 @@ import ( func TestInt64ObservableConfiguration(t *testing.T) { const ( - token int64 = 43 - desc = "Instrument description." - uBytes = "By" + token int64 = 43 + desc = "Instrument description." + uBytes = "By" + defaultDisabled = true ) run := func(got int64ObservableConfig) func(*testing.T) { return func(t *testing.T) { assert.Equal(t, desc, got.Description(), "description") assert.Equal(t, uBytes, got.Unit(), "unit") + assert.Equal(t, defaultDisabled, got.DefaultDisabled(), "defaultDisabled") // Functions are not comparable. cBacks := got.Callbacks() @@ -44,6 +46,7 @@ func TestInt64ObservableConfiguration(t *testing.T) { NewInt64ObservableCounterConfig( WithDescription(desc), WithUnit(uBytes), + WithDefaultDisabled(), WithInt64Callback(cback), ), )) @@ -52,6 +55,7 @@ func TestInt64ObservableConfiguration(t *testing.T) { NewInt64ObservableUpDownCounterConfig( WithDescription(desc), WithUnit(uBytes), + WithDefaultDisabled(), WithInt64Callback(cback), ), )) @@ -60,6 +64,7 @@ func TestInt64ObservableConfiguration(t *testing.T) { NewInt64ObservableGaugeConfig( WithDescription(desc), WithUnit(uBytes), + WithDefaultDisabled(), WithInt64Callback(cback), ), )) @@ -68,6 +73,7 @@ func TestInt64ObservableConfiguration(t *testing.T) { type int64ObservableConfig interface { Description() string Unit() string + DefaultDisabled() bool Callbacks() []Int64Callback } diff --git a/metric/example_test.go b/metric/example_test.go index 67af3751ffe..d36f9ec53eb 100644 --- a/metric/example_test.go +++ b/metric/example_test.go @@ -301,3 +301,23 @@ func ExampleMeter_attributes() { metric.WithAttributes(semconv.HTTPResponseStatusCode(statusCode))) }) } + +// You can define metrics which are disabled by default using the [WithDefaultDisabled] option. +// +// Here's how you might define a counter that is disabled by default. +func ExampleMeter_withDefaultDisabled() { + var err error + itemsCounter, err := meter.Int64UpDownCounter( + "items.counter", + metric.WithDescription("Number of items."), + metric.WithUnit("{item}"), + metric.WithDefaultDisabled(), + ) + if err != nil { + panic(err) + } + + // This increment is a no-op unless the user has explicitly enabled the + // metric using the SDK. + itemsCounter.Add(context.Background(), 1) +} diff --git a/metric/instrument.go b/metric/instrument.go index 9f48d5f117c..b27c0f3bb73 100644 --- a/metric/instrument.go +++ b/metric/instrument.go @@ -196,6 +196,85 @@ func (o unitOpt) applyInt64ObservableGauge(c Int64ObservableGaugeConfig) Int64Ob // The unit u should be defined using the appropriate [UCUM](https://ucum.org) case-sensitive code. func WithUnit(u string) InstrumentOption { return unitOpt(u) } +type defaultDisabledOpt struct{} + +func (o defaultDisabledOpt) applyFloat64Counter(c Float64CounterConfig) Float64CounterConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyFloat64UpDownCounter(c Float64UpDownCounterConfig) Float64UpDownCounterConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyFloat64Histogram(c Float64HistogramConfig) Float64HistogramConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyFloat64Gauge(c Float64GaugeConfig) Float64GaugeConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyFloat64ObservableCounter(c Float64ObservableCounterConfig) Float64ObservableCounterConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyFloat64ObservableUpDownCounter( + c Float64ObservableUpDownCounterConfig, +) Float64ObservableUpDownCounterConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyFloat64ObservableGauge(c Float64ObservableGaugeConfig) Float64ObservableGaugeConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyInt64Counter(c Int64CounterConfig) Int64CounterConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyInt64UpDownCounter(c Int64UpDownCounterConfig) Int64UpDownCounterConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyInt64Histogram(c Int64HistogramConfig) Int64HistogramConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyInt64Gauge(c Int64GaugeConfig) Int64GaugeConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyInt64ObservableCounter(c Int64ObservableCounterConfig) Int64ObservableCounterConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyInt64ObservableUpDownCounter( + c Int64ObservableUpDownCounterConfig, +) Int64ObservableUpDownCounterConfig { + c.defaultDisabled = true + return c +} + +func (o defaultDisabledOpt) applyInt64ObservableGauge(c Int64ObservableGaugeConfig) Int64ObservableGaugeConfig { + c.defaultDisabled = true + return c +} + +// WithDefaultDisabled sets the instrument to be disabled by default. +func WithDefaultDisabled() InstrumentOption { return defaultDisabledOpt{} } + // WithExplicitBucketBoundaries sets the instrument explicit bucket boundaries. // // This option is considered "advisory", and may be ignored by API implementations. diff --git a/metric/syncfloat64.go b/metric/syncfloat64.go index 8403a4bad2d..c3287f85194 100644 --- a/metric/syncfloat64.go +++ b/metric/syncfloat64.go @@ -30,8 +30,9 @@ type Float64Counter interface { // Float64CounterConfig contains options for synchronous counter instruments that // record float64 values. type Float64CounterConfig struct { - description string - unit string + description string + unit string + defaultDisabled bool } // NewFloat64CounterConfig returns a new [Float64CounterConfig] with all opts @@ -54,6 +55,11 @@ func (c Float64CounterConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Float64CounterConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // Float64CounterOption applies options to a [Float64CounterConfig]. See // [InstrumentOption] for other options that can be used as a // Float64CounterOption. @@ -83,8 +89,9 @@ type Float64UpDownCounter interface { // Float64UpDownCounterConfig contains options for synchronous counter // instruments that record float64 values. type Float64UpDownCounterConfig struct { - description string - unit string + description string + unit string + defaultDisabled bool } // NewFloat64UpDownCounterConfig returns a new [Float64UpDownCounterConfig] @@ -107,6 +114,11 @@ func (c Float64UpDownCounterConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Float64UpDownCounterConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // Float64UpDownCounterOption applies options to a // [Float64UpDownCounterConfig]. See [InstrumentOption] for other options that // can be used as a Float64UpDownCounterOption. @@ -138,6 +150,7 @@ type Float64Histogram interface { type Float64HistogramConfig struct { description string unit string + defaultDisabled bool explicitBucketBoundaries []float64 } @@ -161,6 +174,11 @@ func (c Float64HistogramConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Float64HistogramConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // ExplicitBucketBoundaries returns the configured explicit bucket boundaries. func (c Float64HistogramConfig) ExplicitBucketBoundaries() []float64 { return c.explicitBucketBoundaries @@ -194,8 +212,9 @@ type Float64Gauge interface { // Float64GaugeConfig contains options for synchronous gauge instruments that // record float64 values. type Float64GaugeConfig struct { - description string - unit string + description string + unit string + defaultDisabled bool } // NewFloat64GaugeConfig returns a new [Float64GaugeConfig] with all opts @@ -218,6 +237,11 @@ func (c Float64GaugeConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Float64GaugeConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // Float64GaugeOption applies options to a [Float64GaugeConfig]. See // [InstrumentOption] for other options that can be used as a // Float64GaugeOption. diff --git a/metric/syncfloat64_test.go b/metric/syncfloat64_test.go index 223eb081b03..f663f5ae7fb 100644 --- a/metric/syncfloat64_test.go +++ b/metric/syncfloat64_test.go @@ -11,38 +11,41 @@ import ( func TestFloat64Configuration(t *testing.T) { const ( - token float64 = 43 - desc = "Instrument description." - uBytes = "By" + token float64 = 43 + desc = "Instrument description." + uBytes = "By" + defaultDisabled = true ) run := func(got float64Config) func(*testing.T) { return func(t *testing.T) { assert.Equal(t, desc, got.Description(), "description") assert.Equal(t, uBytes, got.Unit(), "unit") + assert.Equal(t, defaultDisabled, got.DefaultDisabled(), "defaultDisabled") } } t.Run("Float64Counter", run( - NewFloat64CounterConfig(WithDescription(desc), WithUnit(uBytes)), + NewFloat64CounterConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), )) t.Run("Float64UpDownCounter", run( - NewFloat64UpDownCounterConfig(WithDescription(desc), WithUnit(uBytes)), + NewFloat64UpDownCounterConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), )) t.Run("Float64Histogram", run( - NewFloat64HistogramConfig(WithDescription(desc), WithUnit(uBytes)), + NewFloat64HistogramConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), )) t.Run("Float64Gauge", run( - NewFloat64GaugeConfig(WithDescription(desc), WithUnit(uBytes)), + NewFloat64GaugeConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), )) } type float64Config interface { Description() string Unit() string + DefaultDisabled() bool } func TestFloat64ExplicitBucketHistogramConfiguration(t *testing.T) { diff --git a/metric/syncint64.go b/metric/syncint64.go index 783fdfba773..606e5ec8ca5 100644 --- a/metric/syncint64.go +++ b/metric/syncint64.go @@ -30,8 +30,9 @@ type Int64Counter interface { // Int64CounterConfig contains options for synchronous counter instruments that // record int64 values. type Int64CounterConfig struct { - description string - unit string + description string + unit string + defaultDisabled bool } // NewInt64CounterConfig returns a new [Int64CounterConfig] with all opts @@ -54,6 +55,11 @@ func (c Int64CounterConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Int64CounterConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // Int64CounterOption applies options to a [Int64CounterConfig]. See // [InstrumentOption] for other options that can be used as an // Int64CounterOption. @@ -83,8 +89,9 @@ type Int64UpDownCounter interface { // Int64UpDownCounterConfig contains options for synchronous counter // instruments that record int64 values. type Int64UpDownCounterConfig struct { - description string - unit string + description string + unit string + defaultDisabled bool } // NewInt64UpDownCounterConfig returns a new [Int64UpDownCounterConfig] with @@ -107,6 +114,11 @@ func (c Int64UpDownCounterConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Int64UpDownCounterConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // Int64UpDownCounterOption applies options to a [Int64UpDownCounterConfig]. // See [InstrumentOption] for other options that can be used as an // Int64UpDownCounterOption. @@ -138,6 +150,7 @@ type Int64Histogram interface { type Int64HistogramConfig struct { description string unit string + defaultDisabled bool explicitBucketBoundaries []float64 } @@ -161,6 +174,11 @@ func (c Int64HistogramConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Int64HistogramConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // ExplicitBucketBoundaries returns the configured explicit bucket boundaries. func (c Int64HistogramConfig) ExplicitBucketBoundaries() []float64 { return c.explicitBucketBoundaries @@ -194,8 +212,9 @@ type Int64Gauge interface { // Int64GaugeConfig contains options for synchronous gauge instruments that // record int64 values. type Int64GaugeConfig struct { - description string - unit string + description string + unit string + defaultDisabled bool } // NewInt64GaugeConfig returns a new [Int64GaugeConfig] with all opts @@ -218,6 +237,11 @@ func (c Int64GaugeConfig) Unit() string { return c.unit } +// DefaultDisabled returns true if the instrument is disabled by default. +func (c Int64GaugeConfig) DefaultDisabled() bool { + return c.defaultDisabled +} + // Int64GaugeOption applies options to a [Int64GaugeConfig]. See // [InstrumentOption] for other options that can be used as a // Int64GaugeOption. diff --git a/metric/syncint64_test.go b/metric/syncint64_test.go index 9bf52bf325f..4933d7c0a2c 100644 --- a/metric/syncint64_test.go +++ b/metric/syncint64_test.go @@ -11,38 +11,41 @@ import ( func TestInt64Configuration(t *testing.T) { const ( - token int64 = 43 - desc = "Instrument description." - uBytes = "By" + token int64 = 43 + desc = "Instrument description." + uBytes = "By" + defaultDisabled = true ) run := func(got int64Config) func(*testing.T) { return func(t *testing.T) { assert.Equal(t, desc, got.Description(), "description") assert.Equal(t, uBytes, got.Unit(), "unit") + assert.Equal(t, defaultDisabled, got.DefaultDisabled(), "defaultDisabled") } } t.Run("Int64Counter", run( - NewInt64CounterConfig(WithDescription(desc), WithUnit(uBytes)), + NewInt64CounterConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), )) t.Run("Int64UpDownCounter", run( - NewInt64UpDownCounterConfig(WithDescription(desc), WithUnit(uBytes)), + NewInt64UpDownCounterConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), )) t.Run("Int64Histogram", run( - NewInt64HistogramConfig(WithDescription(desc), WithUnit(uBytes)), + NewInt64HistogramConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), )) t.Run("Int64Gauge", run( - NewInt64GaugeConfig(WithDescription(desc), WithUnit(uBytes)), + NewInt64GaugeConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), )) } type int64Config interface { Description() string Unit() string + DefaultDisabled() bool } func TestInt64ExplicitBucketHistogramConfiguration(t *testing.T) { From e143055cc8cd00abf366a52979c7de4c473ea204 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Tue, 16 Dec 2025 19:27:20 +0000 Subject: [PATCH 2/4] Add DefaultDisabled to the metric sdk --- sdk/metric/meter.go | 51 ++++++++++++++-------------- sdk/metric/pipeline.go | 13 ++++--- sdk/metric/pipeline_registry_test.go | 32 ++++++++--------- sdk/metric/pipeline_test.go | 4 +-- 4 files changed, 52 insertions(+), 48 deletions(-) diff --git a/sdk/metric/meter.go b/sdk/metric/meter.go index e0a1e90e778..f9e56f6e653 100644 --- a/sdk/metric/meter.go +++ b/sdk/metric/meter.go @@ -70,7 +70,7 @@ func (m *meter) Int64Counter(name string, options ...metric.Int64CounterOption) cfg := metric.NewInt64CounterConfig(options...) const kind = InstrumentKindCounter p := int64InstProvider{m} - i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit()) + i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.DefaultDisabled()) if err != nil { return i, err } @@ -88,7 +88,7 @@ func (m *meter) Int64UpDownCounter( cfg := metric.NewInt64UpDownCounterConfig(options...) const kind = InstrumentKindUpDownCounter p := int64InstProvider{m} - i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit()) + i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.DefaultDisabled()) if err != nil { return i, err } @@ -117,7 +117,7 @@ func (m *meter) Int64Gauge(name string, options ...metric.Int64GaugeOption) (met cfg := metric.NewInt64GaugeConfig(options...) const kind = InstrumentKindGauge p := int64InstProvider{m} - i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit()) + i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.DefaultDisabled()) if err != nil { return i, err } @@ -127,7 +127,7 @@ func (m *meter) Int64Gauge(name string, options ...metric.Int64GaugeOption) (met // int64ObservableInstrument returns a new observable identified by the Instrument. // It registers callbacks for each reader's pipeline. -func (m *meter) int64ObservableInstrument(id Instrument, callbacks []metric.Int64Callback) (int64Observable, error) { +func (m *meter) int64ObservableInstrument(id Instrument, callbacks []metric.Int64Callback, defaultDisabled bool) (int64Observable, error) { key := instID{ Name: id.Name, Description: id.Description, @@ -142,7 +142,7 @@ func (m *meter) int64ObservableInstrument(id Instrument, callbacks []metric.Int6 for _, insert := range m.int64Resolver.inserters { // Connect the measure functions for instruments in this pipeline with the // callbacks for this pipeline. - in, err := insert.Instrument(id, insert.readerDefaultAggregation(id.Kind)) + in, err := insert.Instrument(id, insert.readerDefaultAggregation(id.Kind, defaultDisabled)) if err != nil { return inst, err } @@ -188,7 +188,7 @@ func (m *meter) Int64ObservableCounter( Kind: InstrumentKindObservableCounter, Scope: m.scope, } - return m.int64ObservableInstrument(id, cfg.Callbacks()) + return m.int64ObservableInstrument(id, cfg.Callbacks(), cfg.DefaultDisabled()) } // Int64ObservableUpDownCounter returns a new instrument identified by name and @@ -212,7 +212,7 @@ func (m *meter) Int64ObservableUpDownCounter( Kind: InstrumentKindObservableUpDownCounter, Scope: m.scope, } - return m.int64ObservableInstrument(id, cfg.Callbacks()) + return m.int64ObservableInstrument(id, cfg.Callbacks(), cfg.DefaultDisabled()) } // Int64ObservableGauge returns a new instrument identified by name and @@ -236,7 +236,7 @@ func (m *meter) Int64ObservableGauge( Kind: InstrumentKindObservableGauge, Scope: m.scope, } - return m.int64ObservableInstrument(id, cfg.Callbacks()) + return m.int64ObservableInstrument(id, cfg.Callbacks(), cfg.DefaultDisabled()) } // Float64Counter returns a new instrument identified by name and configured @@ -246,7 +246,7 @@ func (m *meter) Float64Counter(name string, options ...metric.Float64CounterOpti cfg := metric.NewFloat64CounterConfig(options...) const kind = InstrumentKindCounter p := float64InstProvider{m} - i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit()) + i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.DefaultDisabled()) if err != nil { return i, err } @@ -264,7 +264,7 @@ func (m *meter) Float64UpDownCounter( cfg := metric.NewFloat64UpDownCounterConfig(options...) const kind = InstrumentKindUpDownCounter p := float64InstProvider{m} - i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit()) + i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.DefaultDisabled()) if err != nil { return i, err } @@ -296,7 +296,7 @@ func (m *meter) Float64Gauge(name string, options ...metric.Float64GaugeOption) cfg := metric.NewFloat64GaugeConfig(options...) const kind = InstrumentKindGauge p := float64InstProvider{m} - i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit()) + i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.DefaultDisabled()) if err != nil { return i, err } @@ -309,6 +309,7 @@ func (m *meter) Float64Gauge(name string, options ...metric.Float64GaugeOption) func (m *meter) float64ObservableInstrument( id Instrument, callbacks []metric.Float64Callback, + defaultDisabled bool, ) (float64Observable, error) { key := instID{ Name: id.Name, @@ -324,7 +325,7 @@ func (m *meter) float64ObservableInstrument( for _, insert := range m.float64Resolver.inserters { // Connect the measure functions for instruments in this pipeline with the // callbacks for this pipeline. - in, err := insert.Instrument(id, insert.readerDefaultAggregation(id.Kind)) + in, err := insert.Instrument(id, insert.readerDefaultAggregation(id.Kind, defaultDisabled)) if err != nil { return inst, err } @@ -370,7 +371,7 @@ func (m *meter) Float64ObservableCounter( Kind: InstrumentKindObservableCounter, Scope: m.scope, } - return m.float64ObservableInstrument(id, cfg.Callbacks()) + return m.float64ObservableInstrument(id, cfg.Callbacks(), cfg.DefaultDisabled()) } // Float64ObservableUpDownCounter returns a new instrument identified by name @@ -394,7 +395,7 @@ func (m *meter) Float64ObservableUpDownCounter( Kind: InstrumentKindObservableUpDownCounter, Scope: m.scope, } - return m.float64ObservableInstrument(id, cfg.Callbacks()) + return m.float64ObservableInstrument(id, cfg.Callbacks(), cfg.DefaultDisabled()) } // Float64ObservableGauge returns a new instrument identified by name and @@ -418,7 +419,7 @@ func (m *meter) Float64ObservableGauge( Kind: InstrumentKindObservableGauge, Scope: m.scope, } - return m.float64ObservableInstrument(id, cfg.Callbacks()) + return m.float64ObservableInstrument(id, cfg.Callbacks(), cfg.DefaultDisabled()) } func validateInstrumentName(name string) error { @@ -633,7 +634,7 @@ func (noopRegister) Unregister() error { // int64InstProvider provides int64 OpenTelemetry instruments. type int64InstProvider struct{ *meter } -func (p int64InstProvider) aggs(kind InstrumentKind, name, desc, u string) ([]aggregate.Measure[int64], error) { +func (p int64InstProvider) aggs(kind InstrumentKind, name, desc, u string, defaultDisabled bool) ([]aggregate.Measure[int64], error) { inst := Instrument{ Name: name, Description: desc, @@ -641,7 +642,7 @@ func (p int64InstProvider) aggs(kind InstrumentKind, name, desc, u string) ([]ag Kind: kind, Scope: p.scope, } - return p.int64Resolver.Aggregators(inst) + return p.int64Resolver.Aggregators(inst, defaultDisabled) } func (p int64InstProvider) histogramAggs( @@ -661,19 +662,19 @@ func (p int64InstProvider) histogramAggs( Kind: InstrumentKindHistogram, Scope: p.scope, } - measures, err := p.int64Resolver.HistogramAggregators(inst, boundaries) + measures, err := p.int64Resolver.HistogramAggregators(inst, boundaries, cfg.DefaultDisabled()) return measures, errors.Join(aggError, err) } // lookup returns the resolved instrumentImpl. -func (p int64InstProvider) lookup(kind InstrumentKind, name, desc, u string) (*int64Inst, error) { +func (p int64InstProvider) lookup(kind InstrumentKind, name, desc, u string, defaultDisabled bool) (*int64Inst, error) { return p.int64Insts.Lookup(instID{ Name: name, Description: desc, Unit: u, Kind: kind, }, func() (*int64Inst, error) { - aggs, err := p.aggs(kind, name, desc, u) + aggs, err := p.aggs(kind, name, desc, u, defaultDisabled) return &int64Inst{measures: aggs}, err }) } @@ -694,7 +695,7 @@ func (p int64InstProvider) lookupHistogram(name string, cfg metric.Int64Histogra // float64InstProvider provides float64 OpenTelemetry instruments. type float64InstProvider struct{ *meter } -func (p float64InstProvider) aggs(kind InstrumentKind, name, desc, u string) ([]aggregate.Measure[float64], error) { +func (p float64InstProvider) aggs(kind InstrumentKind, name, desc, u string, defaultDisabled bool) ([]aggregate.Measure[float64], error) { inst := Instrument{ Name: name, Description: desc, @@ -702,7 +703,7 @@ func (p float64InstProvider) aggs(kind InstrumentKind, name, desc, u string) ([] Kind: kind, Scope: p.scope, } - return p.float64Resolver.Aggregators(inst) + return p.float64Resolver.Aggregators(inst, defaultDisabled) } func (p float64InstProvider) histogramAggs( @@ -722,19 +723,19 @@ func (p float64InstProvider) histogramAggs( Kind: InstrumentKindHistogram, Scope: p.scope, } - measures, err := p.float64Resolver.HistogramAggregators(inst, boundaries) + measures, err := p.float64Resolver.HistogramAggregators(inst, boundaries, cfg.DefaultDisabled()) return measures, errors.Join(aggError, err) } // lookup returns the resolved instrumentImpl. -func (p float64InstProvider) lookup(kind InstrumentKind, name, desc, u string) (*float64Inst, error) { +func (p float64InstProvider) lookup(kind InstrumentKind, name, desc, u string, defaultDisabled bool) (*float64Inst, error) { return p.float64Insts.Lookup(instID{ Name: name, Description: desc, Unit: u, Kind: kind, }, func() (*float64Inst, error) { - aggs, err := p.aggs(kind, name, desc, u) + aggs, err := p.aggs(kind, name, desc, u, defaultDisabled) return &float64Inst{measures: aggs}, err }) } diff --git a/sdk/metric/pipeline.go b/sdk/metric/pipeline.go index 408fddc8d4e..ee017c10320 100644 --- a/sdk/metric/pipeline.go +++ b/sdk/metric/pipeline.go @@ -313,7 +313,10 @@ type aggVal[N int64 | float64] struct { // readerDefaultAggregation returns the default aggregation for the instrument // kind based on the reader's aggregation preferences. This is used unless the // aggregation is overridden with a view. -func (i *inserter[N]) readerDefaultAggregation(kind InstrumentKind) Aggregation { +func (i *inserter[N]) readerDefaultAggregation(kind InstrumentKind, defaultDisabled bool) Aggregation { + if defaultDisabled { + return AggregationDrop{} + } aggregation := i.pipeline.reader.aggregation(kind) switch aggregation.(type) { case nil, AggregationDefault: @@ -641,12 +644,12 @@ func newResolver[N int64 | float64](p pipelines, vc *cache[string, instID]) reso // Aggregators returns the Aggregators that must be updated by the instrument // defined by key. -func (r resolver[N]) Aggregators(id Instrument) ([]aggregate.Measure[N], error) { +func (r resolver[N]) Aggregators(id Instrument, defaultDisabled bool) ([]aggregate.Measure[N], error) { var measures []aggregate.Measure[N] var err error for _, i := range r.inserters { - in, e := i.Instrument(id, i.readerDefaultAggregation(id.Kind)) + in, e := i.Instrument(id, i.readerDefaultAggregation(id.Kind, defaultDisabled)) if e != nil { err = errors.Join(err, e) } @@ -658,12 +661,12 @@ func (r resolver[N]) Aggregators(id Instrument) ([]aggregate.Measure[N], error) // HistogramAggregators returns the histogram Aggregators that must be updated by the instrument // defined by key. If boundaries were provided on instrument instantiation, those take precedence // over boundaries provided by the reader. -func (r resolver[N]) HistogramAggregators(id Instrument, boundaries []float64) ([]aggregate.Measure[N], error) { +func (r resolver[N]) HistogramAggregators(id Instrument, boundaries []float64, defaultDisabled bool) ([]aggregate.Measure[N], error) { var measures []aggregate.Measure[N] var err error for _, i := range r.inserters { - agg := i.readerDefaultAggregation(id.Kind) + agg := i.readerDefaultAggregation(id.Kind, defaultDisabled) if histAgg, ok := agg.(AggregationExplicitBucketHistogram); ok && len(boundaries) > 0 { histAgg.Boundaries = boundaries agg = histAgg diff --git a/sdk/metric/pipeline_registry_test.go b/sdk/metric/pipeline_registry_test.go index e7b3fb95709..a374e01d302 100644 --- a/sdk/metric/pipeline_registry_test.go +++ b/sdk/metric/pipeline_registry_test.go @@ -393,7 +393,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) { var c cache[string, instID] p := newPipeline(nil, tt.reader, tt.views, exemplar.AlwaysOffFilter, 0) i := newInserter[N](p, &c) - readerAggregation := i.readerDefaultAggregation(tt.inst.Kind) + readerAggregation := i.readerDefaultAggregation(tt.inst.Kind, false) input, err := i.Instrument(tt.inst, readerAggregation) var comps []aggregate.ComputeAggregation for _, instSyncs := range p.aggregations { @@ -418,7 +418,7 @@ func testInvalidInstrumentShouldPanic[N int64 | float64]() { Name: "foo", Kind: InstrumentKind(255), } - readerAggregation := i.readerDefaultAggregation(inst.Kind) + readerAggregation := i.readerDefaultAggregation(inst.Kind, false) _, _ = i.Instrument(inst, readerAggregation) } @@ -435,7 +435,7 @@ func TestPipelinesAggregatorForEachReader(t *testing.T) { inst := Instrument{Name: "foo", Kind: InstrumentKindCounter} var c cache[string, instID] r := newResolver[int64](pipes, &c) - aggs, err := r.Aggregators(inst) + aggs, err := r.Aggregators(inst, false) require.NoError(t, err, "resolved Aggregators error") require.Len(t, aggs, 2, "instrument aggregators") @@ -516,7 +516,7 @@ func testPipelineRegistryResolveIntAggregators(t *testing.T, p pipelines, wantCo inst := Instrument{Name: "foo", Kind: InstrumentKindCounter} var c cache[string, instID] r := newResolver[int64](p, &c) - aggs, err := r.Aggregators(inst) + aggs, err := r.Aggregators(inst, false) assert.NoError(t, err) require.Len(t, aggs, wantCount) @@ -526,7 +526,7 @@ func testPipelineRegistryResolveFloatAggregators(t *testing.T, p pipelines, want inst := Instrument{Name: "foo", Kind: InstrumentKindCounter} var c cache[string, instID] r := newResolver[float64](p, &c) - aggs, err := r.Aggregators(inst) + aggs, err := r.Aggregators(inst, false) assert.NoError(t, err) require.Len(t, aggs, wantCount) @@ -536,7 +536,7 @@ func testPipelineRegistryResolveIntHistogramAggregators(t *testing.T, p pipeline inst := Instrument{Name: "foo", Kind: InstrumentKindCounter} var c cache[string, instID] r := newResolver[int64](p, &c) - aggs, err := r.HistogramAggregators(inst, []float64{1, 2, 3}) + aggs, err := r.HistogramAggregators(inst, []float64{1, 2, 3}, false) assert.NoError(t, err) require.Len(t, aggs, wantCount) @@ -546,7 +546,7 @@ func testPipelineRegistryResolveFloatHistogramAggregators(t *testing.T, p pipeli inst := Instrument{Name: "foo", Kind: InstrumentKindCounter} var c cache[string, instID] r := newResolver[float64](p, &c) - aggs, err := r.HistogramAggregators(inst, []float64{1, 2, 3}) + aggs, err := r.HistogramAggregators(inst, []float64{1, 2, 3}, false) assert.NoError(t, err) require.Len(t, aggs, wantCount) @@ -575,20 +575,20 @@ func TestPipelineRegistryCreateAggregatorsIncompatibleInstrument(t *testing.T) { var vc cache[string, instID] ri := newResolver[int64](p, &vc) - intAggs, err := ri.Aggregators(inst) + intAggs, err := ri.Aggregators(inst, false) assert.Error(t, err) assert.Empty(t, intAggs) rf := newResolver[float64](p, &vc) - floatAggs, err := rf.Aggregators(inst) + floatAggs, err := rf.Aggregators(inst, false) assert.Error(t, err) assert.Empty(t, floatAggs) - intAggs, err = ri.HistogramAggregators(inst, []float64{1, 2, 3}) + intAggs, err = ri.HistogramAggregators(inst, []float64{1, 2, 3}, false) assert.Error(t, err) assert.Empty(t, intAggs) - floatAggs, err = rf.HistogramAggregators(inst, []float64{1, 2, 3}) + floatAggs, err = rf.HistogramAggregators(inst, []float64{1, 2, 3}, false) assert.Error(t, err) assert.Empty(t, floatAggs) } @@ -634,14 +634,14 @@ func TestResolveAggregatorsDuplicateErrors(t *testing.T) { var vc cache[string, instID] ri := newResolver[int64](p, &vc) - intAggs, err := ri.Aggregators(fooInst) + intAggs, err := ri.Aggregators(fooInst, false) assert.NoError(t, err) assert.Equal(t, 0, l.InfoN(), "no info logging should happen") assert.Len(t, intAggs, 1) // The Rename view should produce the same instrument without an error, the // default view should also cause a new aggregator to be returned. - intAggs, err = ri.Aggregators(barInst) + intAggs, err = ri.Aggregators(barInst, false) assert.NoError(t, err) assert.Equal(t, 0, l.InfoN(), "no info logging should happen") assert.Len(t, intAggs, 2) @@ -649,19 +649,19 @@ func TestResolveAggregatorsDuplicateErrors(t *testing.T) { // Creating a float foo instrument should log a warning because there is an // int foo instrument. rf := newResolver[float64](p, &vc) - floatAggs, err := rf.Aggregators(fooInst) + floatAggs, err := rf.Aggregators(fooInst, false) assert.NoError(t, err) assert.Equal(t, 1, l.InfoN(), "instrument conflict not logged") assert.Len(t, floatAggs, 1) fooInst = Instrument{Name: "foo-float", Kind: InstrumentKindCounter} - floatAggs, err = rf.Aggregators(fooInst) + floatAggs, err = rf.Aggregators(fooInst, false) assert.NoError(t, err) assert.Equal(t, 0, l.InfoN(), "no info logging should happen") assert.Len(t, floatAggs, 1) - floatAggs, err = rf.Aggregators(barInst) + floatAggs, err = rf.Aggregators(barInst, false) assert.NoError(t, err) // Both the rename and default view aggregators created above should now // conflict. Therefore, 2 warning messages should be logged. diff --git a/sdk/metric/pipeline_test.go b/sdk/metric/pipeline_test.go index ca0b34f826b..5ec1d590919 100644 --- a/sdk/metric/pipeline_test.go +++ b/sdk/metric/pipeline_test.go @@ -158,7 +158,7 @@ func testDefaultViewImplicit[N int64 | float64]() func(t *testing.T) { t.Run(test.name, func(t *testing.T) { var c cache[string, instID] i := newInserter[N](test.pipe, &c) - readerAggregation := i.readerDefaultAggregation(inst.Kind) + readerAggregation := i.readerDefaultAggregation(inst.Kind, false) got, err := i.Instrument(inst, readerAggregation) require.NoError(t, err) assert.Len(t, got, 1, "default view not applied") @@ -385,7 +385,7 @@ func TestInserterCachedAggregatorNameConflict(t *testing.T) { pipe := newPipeline(nil, NewManualReader(), nil, exemplar.AlwaysOffFilter, 0) i := newInserter[int64](pipe, &vc) - readerAggregation := i.readerDefaultAggregation(kind) + readerAggregation := i.readerDefaultAggregation(kind, false) _, origID, err := i.cachedAggregator(scope, kind, stream, readerAggregation) require.NoError(t, err) From 25a142e99069c2bf9fb55a78652f5dd8e40574c4 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Wed, 28 Jan 2026 16:34:35 +0000 Subject: [PATCH 3/4] switch to view.Enabled --- sdk/metric/example_test.go | 36 ++++++++++++++++++++++++++++ sdk/metric/instrument.go | 4 ++++ sdk/metric/meter.go | 4 ++-- sdk/metric/pipeline.go | 24 +++++++++++-------- sdk/metric/pipeline_registry_test.go | 8 +++---- sdk/metric/pipeline_test.go | 10 ++++---- sdk/metric/view.go | 1 + 7 files changed, 66 insertions(+), 21 deletions(-) diff --git a/sdk/metric/example_test.go b/sdk/metric/example_test.go index 22bf60f6946..442500c4c83 100644 --- a/sdk/metric/example_test.go +++ b/sdk/metric/example_test.go @@ -11,6 +11,7 @@ import ( "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" + apimetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/exemplar" @@ -157,6 +158,41 @@ func ExampleNewView() { // unit: ms } +func ExampleNewView_optIn() { + // Create a view that renames the "latency" instrument from the v0.34.0 + // version of the "http" instrumentation library as "request.latency". + enabledTrue := true + view := metric.NewView(metric.Instrument{ + Name: "optin.counter", + Scope: instrumentation.Scope{ + Name: "example", + }, + // This enables a metric that is disabled by default. + }, metric.Stream{Enabled: &enabledTrue}) + + // The created view can then be registered with the OpenTelemetry metric + // SDK using the WithView option. + mp := metric.NewMeterProvider( + metric.WithView(view), + ) + + // A metric can be marked opt-in using apimetric.WithDefaultDieabled. + mp.Meter("example").Int64Counter("optin.counter", apimetric.WithDefaultDisabled()) + + // Below is an example of how the view will + // function in the SDK for certain instruments. + stream, _ := view(metric.Instrument{ + Name: "optin.counter", + Kind: metric.InstrumentKindCounter, + Scope: instrumentation.Scope{ + Name: "example", + }, + }) + fmt.Println("enabled:", *stream.Enabled) + // Output: + // enabled: true +} + func ExampleNewView_wildcard() { // Create a view that sets unit to milliseconds for any instrument with a // name suffix of ".ms". diff --git a/sdk/metric/instrument.go b/sdk/metric/instrument.go index 63cccc508f4..a5c34de00ec 100644 --- a/sdk/metric/instrument.go +++ b/sdk/metric/instrument.go @@ -151,6 +151,10 @@ type Stream struct { // // If unspecified, [DefaultExemplarReservoirProviderSelector] is used. ExemplarReservoirProviderSelector ExemplarReservoirProviderSelector + // Enabled can be used to enable an OptIn metric, or disable a metric that + // is not OptIn. If it is unset, it leaves the enablement of the metric in + // its default state. + Enabled *bool } // instID are the identifying properties of a instrument. diff --git a/sdk/metric/meter.go b/sdk/metric/meter.go index f9e56f6e653..502e26871a4 100644 --- a/sdk/metric/meter.go +++ b/sdk/metric/meter.go @@ -142,7 +142,7 @@ func (m *meter) int64ObservableInstrument(id Instrument, callbacks []metric.Int6 for _, insert := range m.int64Resolver.inserters { // Connect the measure functions for instruments in this pipeline with the // callbacks for this pipeline. - in, err := insert.Instrument(id, insert.readerDefaultAggregation(id.Kind, defaultDisabled)) + in, err := insert.Instrument(id, insert.readerDefaultAggregation(id.Kind), defaultDisabled) if err != nil { return inst, err } @@ -325,7 +325,7 @@ func (m *meter) float64ObservableInstrument( for _, insert := range m.float64Resolver.inserters { // Connect the measure functions for instruments in this pipeline with the // callbacks for this pipeline. - in, err := insert.Instrument(id, insert.readerDefaultAggregation(id.Kind, defaultDisabled)) + in, err := insert.Instrument(id, insert.readerDefaultAggregation(id.Kind), defaultDisabled) if err != nil { return inst, err } diff --git a/sdk/metric/pipeline.go b/sdk/metric/pipeline.go index ee017c10320..07f1dd9265d 100644 --- a/sdk/metric/pipeline.go +++ b/sdk/metric/pipeline.go @@ -236,7 +236,7 @@ func newInserter[N int64 | float64](p *pipeline, vc *cache[string, instID]) *ins // // If an instrument is determined to use a Drop aggregation, that instrument is // not inserted nor returned. -func (i *inserter[N]) Instrument(inst Instrument, readerAggregation Aggregation) ([]aggregate.Measure[N], error) { +func (i *inserter[N]) Instrument(inst Instrument, readerAggregation Aggregation, defaultDisabled bool) ([]aggregate.Measure[N], error) { var ( matched bool measures []aggregate.Measure[N] @@ -250,7 +250,7 @@ func (i *inserter[N]) Instrument(inst Instrument, readerAggregation Aggregation) continue } matched = true - in, id, e := i.cachedAggregator(inst.Scope, inst.Kind, stream, readerAggregation) + in, id, e := i.cachedAggregator(inst.Scope, inst.Kind, stream, readerAggregation, defaultDisabled) if e != nil { err = errors.Join(err, e) } @@ -279,7 +279,7 @@ func (i *inserter[N]) Instrument(inst Instrument, readerAggregation Aggregation) Description: inst.Description, Unit: inst.Unit, } - in, _, e := i.cachedAggregator(inst.Scope, inst.Kind, stream, readerAggregation) + in, _, e := i.cachedAggregator(inst.Scope, inst.Kind, stream, readerAggregation, defaultDisabled) if e != nil { if err == nil { err = errCreatingAggregators @@ -313,10 +313,7 @@ type aggVal[N int64 | float64] struct { // readerDefaultAggregation returns the default aggregation for the instrument // kind based on the reader's aggregation preferences. This is used unless the // aggregation is overridden with a view. -func (i *inserter[N]) readerDefaultAggregation(kind InstrumentKind, defaultDisabled bool) Aggregation { - if defaultDisabled { - return AggregationDrop{} - } +func (i *inserter[N]) readerDefaultAggregation(kind InstrumentKind) Aggregation { aggregation := i.pipeline.reader.aggregation(kind) switch aggregation.(type) { case nil, AggregationDefault: @@ -357,6 +354,7 @@ func (i *inserter[N]) cachedAggregator( kind InstrumentKind, stream Stream, readerAggregation Aggregation, + defaultDisabled bool, ) (meas aggregate.Measure[N], aggID uint64, err error) { switch stream.Aggregation.(type) { case nil: @@ -371,6 +369,12 @@ func (i *inserter[N]) cachedAggregator( stream.ExemplarReservoirProviderSelector = DefaultExemplarReservoirProviderSelector } + isEnabled := stream.Enabled != nil && *stream.Enabled + isDisabled := stream.Enabled != nil && !*stream.Enabled + if (defaultDisabled && !isEnabled) || isDisabled { + stream.Aggregation = AggregationDrop{} + } + if err := isAggregatorCompatible(kind, stream.Aggregation); err != nil { return nil, 0, fmt.Errorf( "creating aggregator with instrumentKind: %d, aggregation %v: %w", @@ -649,7 +653,7 @@ func (r resolver[N]) Aggregators(id Instrument, defaultDisabled bool) ([]aggrega var err error for _, i := range r.inserters { - in, e := i.Instrument(id, i.readerDefaultAggregation(id.Kind, defaultDisabled)) + in, e := i.Instrument(id, i.readerDefaultAggregation(id.Kind), defaultDisabled) if e != nil { err = errors.Join(err, e) } @@ -666,12 +670,12 @@ func (r resolver[N]) HistogramAggregators(id Instrument, boundaries []float64, d var err error for _, i := range r.inserters { - agg := i.readerDefaultAggregation(id.Kind, defaultDisabled) + agg := i.readerDefaultAggregation(id.Kind) if histAgg, ok := agg.(AggregationExplicitBucketHistogram); ok && len(boundaries) > 0 { histAgg.Boundaries = boundaries agg = histAgg } - in, e := i.Instrument(id, agg) + in, e := i.Instrument(id, agg, defaultDisabled) if e != nil { err = errors.Join(err, e) } diff --git a/sdk/metric/pipeline_registry_test.go b/sdk/metric/pipeline_registry_test.go index a374e01d302..dd939d8f908 100644 --- a/sdk/metric/pipeline_registry_test.go +++ b/sdk/metric/pipeline_registry_test.go @@ -393,8 +393,8 @@ func testCreateAggregators[N int64 | float64](t *testing.T) { var c cache[string, instID] p := newPipeline(nil, tt.reader, tt.views, exemplar.AlwaysOffFilter, 0) i := newInserter[N](p, &c) - readerAggregation := i.readerDefaultAggregation(tt.inst.Kind, false) - input, err := i.Instrument(tt.inst, readerAggregation) + readerAggregation := i.readerDefaultAggregation(tt.inst.Kind) + input, err := i.Instrument(tt.inst, readerAggregation, false) var comps []aggregate.ComputeAggregation for _, instSyncs := range p.aggregations { for _, i := range instSyncs { @@ -418,8 +418,8 @@ func testInvalidInstrumentShouldPanic[N int64 | float64]() { Name: "foo", Kind: InstrumentKind(255), } - readerAggregation := i.readerDefaultAggregation(inst.Kind, false) - _, _ = i.Instrument(inst, readerAggregation) + readerAggregation := i.readerDefaultAggregation(inst.Kind) + _, _ = i.Instrument(inst, readerAggregation, false) } func TestInvalidInstrumentShouldPanic(t *testing.T) { diff --git a/sdk/metric/pipeline_test.go b/sdk/metric/pipeline_test.go index 5ec1d590919..250258982df 100644 --- a/sdk/metric/pipeline_test.go +++ b/sdk/metric/pipeline_test.go @@ -158,8 +158,8 @@ func testDefaultViewImplicit[N int64 | float64]() func(t *testing.T) { t.Run(test.name, func(t *testing.T) { var c cache[string, instID] i := newInserter[N](test.pipe, &c) - readerAggregation := i.readerDefaultAggregation(inst.Kind, false) - got, err := i.Instrument(inst, readerAggregation) + readerAggregation := i.readerDefaultAggregation(inst.Kind) + got, err := i.Instrument(inst, readerAggregation, false) require.NoError(t, err) assert.Len(t, got, 1, "default view not applied") for _, in := range got { @@ -385,8 +385,8 @@ func TestInserterCachedAggregatorNameConflict(t *testing.T) { pipe := newPipeline(nil, NewManualReader(), nil, exemplar.AlwaysOffFilter, 0) i := newInserter[int64](pipe, &vc) - readerAggregation := i.readerDefaultAggregation(kind, false) - _, origID, err := i.cachedAggregator(scope, kind, stream, readerAggregation) + readerAggregation := i.readerDefaultAggregation(kind) + _, origID, err := i.cachedAggregator(scope, kind, stream, readerAggregation, false) require.NoError(t, err) require.Len(t, pipe.aggregations, 1) @@ -396,7 +396,7 @@ func TestInserterCachedAggregatorNameConflict(t *testing.T) { require.Equal(t, name, iSync[0].name) stream.Name = "RequestCount" - _, id, err := i.cachedAggregator(scope, kind, stream, readerAggregation) + _, id, err := i.cachedAggregator(scope, kind, stream, readerAggregation, false) require.NoError(t, err) assert.Equal(t, origID, id, "multiple aggregators for equivalent name") diff --git a/sdk/metric/view.go b/sdk/metric/view.go index 630890f4263..ca3d03ecaf2 100644 --- a/sdk/metric/view.go +++ b/sdk/metric/view.go @@ -102,6 +102,7 @@ func NewView(criteria Instrument, mask Stream) View { Aggregation: agg, AttributeFilter: mask.AttributeFilter, ExemplarReservoirProviderSelector: mask.ExemplarReservoirProviderSelector, + Enabled: mask.Enabled, }, true } return Stream{}, false From cf2d56b05709bef2e48d13cfa69c00cb3ee59339 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Wed, 28 Jan 2026 16:58:22 +0000 Subject: [PATCH 4/4] rename DefaultDisabled to OptIn --- metric/asyncfloat64.go | 42 ++++++++++++------------- metric/asyncfloat64_test.go | 18 +++++------ metric/asyncint64.go | 42 ++++++++++++------------- metric/asyncint64_test.go | 18 +++++------ metric/example_test.go | 6 ++-- metric/instrument.go | 62 ++++++++++++++++++------------------- metric/syncfloat64.go | 44 +++++++++++++------------- metric/syncfloat64_test.go | 20 ++++++------ metric/syncint64.go | 44 +++++++++++++------------- metric/syncint64_test.go | 20 ++++++------ sdk/metric/example_test.go | 4 +-- sdk/metric/meter.go | 52 +++++++++++++++---------------- sdk/metric/pipeline.go | 18 +++++------ 13 files changed, 195 insertions(+), 195 deletions(-) diff --git a/metric/asyncfloat64.go b/metric/asyncfloat64.go index e88c6618486..db69e23cf7e 100644 --- a/metric/asyncfloat64.go +++ b/metric/asyncfloat64.go @@ -41,10 +41,10 @@ type Float64ObservableCounter interface { // Float64ObservableCounterConfig contains options for asynchronous counter // instruments that record float64 values. type Float64ObservableCounterConfig struct { - description string - unit string - defaultDisabled bool - callbacks []Float64Callback + description string + unit string + optIn bool + callbacks []Float64Callback } // NewFloat64ObservableCounterConfig returns a new @@ -67,9 +67,9 @@ func (c Float64ObservableCounterConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Float64ObservableCounterConfig) DefaultDisabled() bool { - return c.defaultDisabled +// OptIn returns true if the instrument is disabled by default. +func (c Float64ObservableCounterConfig) OptIn() bool { + return c.optIn } // Callbacks returns the configured callbacks. @@ -105,10 +105,10 @@ type Float64ObservableUpDownCounter interface { // Float64ObservableUpDownCounterConfig contains options for asynchronous // counter instruments that record float64 values. type Float64ObservableUpDownCounterConfig struct { - description string - unit string - defaultDisabled bool - callbacks []Float64Callback + description string + unit string + optIn bool + callbacks []Float64Callback } // NewFloat64ObservableUpDownCounterConfig returns a new @@ -133,9 +133,9 @@ func (c Float64ObservableUpDownCounterConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Float64ObservableUpDownCounterConfig) DefaultDisabled() bool { - return c.defaultDisabled +// OptIn returns true if the instrument is disabled by default. +func (c Float64ObservableUpDownCounterConfig) OptIn() bool { + return c.optIn } // Callbacks returns the configured callbacks. @@ -170,10 +170,10 @@ type Float64ObservableGauge interface { // Float64ObservableGaugeConfig contains options for asynchronous counter // instruments that record float64 values. type Float64ObservableGaugeConfig struct { - description string - unit string - defaultDisabled bool - callbacks []Float64Callback + description string + unit string + optIn bool + callbacks []Float64Callback } // NewFloat64ObservableGaugeConfig returns a new [Float64ObservableGaugeConfig] @@ -196,9 +196,9 @@ func (c Float64ObservableGaugeConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Float64ObservableGaugeConfig) DefaultDisabled() bool { - return c.defaultDisabled +// OptIn returns true if the instrument is disabled by default. +func (c Float64ObservableGaugeConfig) OptIn() bool { + return c.optIn } // Callbacks returns the configured callbacks. diff --git a/metric/asyncfloat64_test.go b/metric/asyncfloat64_test.go index d42d90db81c..58e915eec83 100644 --- a/metric/asyncfloat64_test.go +++ b/metric/asyncfloat64_test.go @@ -15,17 +15,17 @@ import ( func TestFloat64ObservableConfiguration(t *testing.T) { const ( - token float64 = 43 - desc = "Instrument description." - uBytes = "By" - defaultDisabled = true + token float64 = 43 + desc = "Instrument description." + uBytes = "By" + optIn = true ) run := func(got float64ObservableConfig) func(*testing.T) { return func(t *testing.T) { assert.Equal(t, desc, got.Description(), "description") assert.Equal(t, uBytes, got.Unit(), "unit") - assert.Equal(t, defaultDisabled, got.DefaultDisabled(), "defaultDisabled") + assert.Equal(t, optIn, got.OptIn(), "optIn") // Functions are not comparable. cBacks := got.Callbacks() @@ -46,7 +46,7 @@ func TestFloat64ObservableConfiguration(t *testing.T) { NewFloat64ObservableCounterConfig( WithDescription(desc), WithUnit(uBytes), - WithDefaultDisabled(), + WithOptIn(), WithFloat64Callback(cback), ), )) @@ -55,7 +55,7 @@ func TestFloat64ObservableConfiguration(t *testing.T) { NewFloat64ObservableUpDownCounterConfig( WithDescription(desc), WithUnit(uBytes), - WithDefaultDisabled(), + WithOptIn(), WithFloat64Callback(cback), ), )) @@ -64,7 +64,7 @@ func TestFloat64ObservableConfiguration(t *testing.T) { NewFloat64ObservableGaugeConfig( WithDescription(desc), WithUnit(uBytes), - WithDefaultDisabled(), + WithOptIn(), WithFloat64Callback(cback), ), )) @@ -73,7 +73,7 @@ func TestFloat64ObservableConfiguration(t *testing.T) { type float64ObservableConfig interface { Description() string Unit() string - DefaultDisabled() bool + OptIn() bool Callbacks() []Float64Callback } diff --git a/metric/asyncint64.go b/metric/asyncint64.go index 27405b68284..12908c9eb25 100644 --- a/metric/asyncint64.go +++ b/metric/asyncint64.go @@ -40,10 +40,10 @@ type Int64ObservableCounter interface { // Int64ObservableCounterConfig contains options for asynchronous counter // instruments that record int64 values. type Int64ObservableCounterConfig struct { - description string - unit string - defaultDisabled bool - callbacks []Int64Callback + description string + unit string + optIn bool + callbacks []Int64Callback } // NewInt64ObservableCounterConfig returns a new [Int64ObservableCounterConfig] @@ -66,9 +66,9 @@ func (c Int64ObservableCounterConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Int64ObservableCounterConfig) DefaultDisabled() bool { - return c.defaultDisabled +// OptIn returns true if the instrument is disabled by default. +func (c Int64ObservableCounterConfig) OptIn() bool { + return c.optIn } // Callbacks returns the configured callbacks. @@ -104,10 +104,10 @@ type Int64ObservableUpDownCounter interface { // Int64ObservableUpDownCounterConfig contains options for asynchronous counter // instruments that record int64 values. type Int64ObservableUpDownCounterConfig struct { - description string - unit string - defaultDisabled bool - callbacks []Int64Callback + description string + unit string + optIn bool + callbacks []Int64Callback } // NewInt64ObservableUpDownCounterConfig returns a new @@ -132,9 +132,9 @@ func (c Int64ObservableUpDownCounterConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Int64ObservableUpDownCounterConfig) DefaultDisabled() bool { - return c.defaultDisabled +// OptIn returns true if the instrument is disabled by default. +func (c Int64ObservableUpDownCounterConfig) OptIn() bool { + return c.optIn } // Callbacks returns the configured callbacks. @@ -169,10 +169,10 @@ type Int64ObservableGauge interface { // Int64ObservableGaugeConfig contains options for asynchronous counter // instruments that record int64 values. type Int64ObservableGaugeConfig struct { - description string - unit string - defaultDisabled bool - callbacks []Int64Callback + description string + unit string + optIn bool + callbacks []Int64Callback } // NewInt64ObservableGaugeConfig returns a new [Int64ObservableGaugeConfig] @@ -195,9 +195,9 @@ func (c Int64ObservableGaugeConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Int64ObservableGaugeConfig) DefaultDisabled() bool { - return c.defaultDisabled +// OptIn returns true if the instrument is disabled by default. +func (c Int64ObservableGaugeConfig) OptIn() bool { + return c.optIn } // Callbacks returns the configured callbacks. diff --git a/metric/asyncint64_test.go b/metric/asyncint64_test.go index 30bcc3caaa8..db78b87b986 100644 --- a/metric/asyncint64_test.go +++ b/metric/asyncint64_test.go @@ -15,17 +15,17 @@ import ( func TestInt64ObservableConfiguration(t *testing.T) { const ( - token int64 = 43 - desc = "Instrument description." - uBytes = "By" - defaultDisabled = true + token int64 = 43 + desc = "Instrument description." + uBytes = "By" + optIn = true ) run := func(got int64ObservableConfig) func(*testing.T) { return func(t *testing.T) { assert.Equal(t, desc, got.Description(), "description") assert.Equal(t, uBytes, got.Unit(), "unit") - assert.Equal(t, defaultDisabled, got.DefaultDisabled(), "defaultDisabled") + assert.Equal(t, optIn, got.OptIn(), "optIn") // Functions are not comparable. cBacks := got.Callbacks() @@ -46,7 +46,7 @@ func TestInt64ObservableConfiguration(t *testing.T) { NewInt64ObservableCounterConfig( WithDescription(desc), WithUnit(uBytes), - WithDefaultDisabled(), + WithOptIn(), WithInt64Callback(cback), ), )) @@ -55,7 +55,7 @@ func TestInt64ObservableConfiguration(t *testing.T) { NewInt64ObservableUpDownCounterConfig( WithDescription(desc), WithUnit(uBytes), - WithDefaultDisabled(), + WithOptIn(), WithInt64Callback(cback), ), )) @@ -64,7 +64,7 @@ func TestInt64ObservableConfiguration(t *testing.T) { NewInt64ObservableGaugeConfig( WithDescription(desc), WithUnit(uBytes), - WithDefaultDisabled(), + WithOptIn(), WithInt64Callback(cback), ), )) @@ -73,7 +73,7 @@ func TestInt64ObservableConfiguration(t *testing.T) { type int64ObservableConfig interface { Description() string Unit() string - DefaultDisabled() bool + OptIn() bool Callbacks() []Int64Callback } diff --git a/metric/example_test.go b/metric/example_test.go index d36f9ec53eb..b21ba8bbcae 100644 --- a/metric/example_test.go +++ b/metric/example_test.go @@ -302,16 +302,16 @@ func ExampleMeter_attributes() { }) } -// You can define metrics which are disabled by default using the [WithDefaultDisabled] option. +// You can define metrics which are disabled by default using the [WithOptIn] option. // // Here's how you might define a counter that is disabled by default. -func ExampleMeter_withDefaultDisabled() { +func ExampleMeter_withOptIn() { var err error itemsCounter, err := meter.Int64UpDownCounter( "items.counter", metric.WithDescription("Number of items."), metric.WithUnit("{item}"), - metric.WithDefaultDisabled(), + metric.WithOptIn(), ) if err != nil { panic(err) diff --git a/metric/instrument.go b/metric/instrument.go index b27c0f3bb73..4179abdada3 100644 --- a/metric/instrument.go +++ b/metric/instrument.go @@ -196,84 +196,84 @@ func (o unitOpt) applyInt64ObservableGauge(c Int64ObservableGaugeConfig) Int64Ob // The unit u should be defined using the appropriate [UCUM](https://ucum.org) case-sensitive code. func WithUnit(u string) InstrumentOption { return unitOpt(u) } -type defaultDisabledOpt struct{} +type optInOpt struct{} -func (o defaultDisabledOpt) applyFloat64Counter(c Float64CounterConfig) Float64CounterConfig { - c.defaultDisabled = true +func (o optInOpt) applyFloat64Counter(c Float64CounterConfig) Float64CounterConfig { + c.optIn = true return c } -func (o defaultDisabledOpt) applyFloat64UpDownCounter(c Float64UpDownCounterConfig) Float64UpDownCounterConfig { - c.defaultDisabled = true +func (o optInOpt) applyFloat64UpDownCounter(c Float64UpDownCounterConfig) Float64UpDownCounterConfig { + c.optIn = true return c } -func (o defaultDisabledOpt) applyFloat64Histogram(c Float64HistogramConfig) Float64HistogramConfig { - c.defaultDisabled = true +func (o optInOpt) applyFloat64Histogram(c Float64HistogramConfig) Float64HistogramConfig { + c.optIn = true return c } -func (o defaultDisabledOpt) applyFloat64Gauge(c Float64GaugeConfig) Float64GaugeConfig { - c.defaultDisabled = true +func (o optInOpt) applyFloat64Gauge(c Float64GaugeConfig) Float64GaugeConfig { + c.optIn = true return c } -func (o defaultDisabledOpt) applyFloat64ObservableCounter(c Float64ObservableCounterConfig) Float64ObservableCounterConfig { - c.defaultDisabled = true +func (o optInOpt) applyFloat64ObservableCounter(c Float64ObservableCounterConfig) Float64ObservableCounterConfig { + c.optIn = true return c } -func (o defaultDisabledOpt) applyFloat64ObservableUpDownCounter( +func (o optInOpt) applyFloat64ObservableUpDownCounter( c Float64ObservableUpDownCounterConfig, ) Float64ObservableUpDownCounterConfig { - c.defaultDisabled = true + c.optIn = true return c } -func (o defaultDisabledOpt) applyFloat64ObservableGauge(c Float64ObservableGaugeConfig) Float64ObservableGaugeConfig { - c.defaultDisabled = true +func (o optInOpt) applyFloat64ObservableGauge(c Float64ObservableGaugeConfig) Float64ObservableGaugeConfig { + c.optIn = true return c } -func (o defaultDisabledOpt) applyInt64Counter(c Int64CounterConfig) Int64CounterConfig { - c.defaultDisabled = true +func (o optInOpt) applyInt64Counter(c Int64CounterConfig) Int64CounterConfig { + c.optIn = true return c } -func (o defaultDisabledOpt) applyInt64UpDownCounter(c Int64UpDownCounterConfig) Int64UpDownCounterConfig { - c.defaultDisabled = true +func (o optInOpt) applyInt64UpDownCounter(c Int64UpDownCounterConfig) Int64UpDownCounterConfig { + c.optIn = true return c } -func (o defaultDisabledOpt) applyInt64Histogram(c Int64HistogramConfig) Int64HistogramConfig { - c.defaultDisabled = true +func (o optInOpt) applyInt64Histogram(c Int64HistogramConfig) Int64HistogramConfig { + c.optIn = true return c } -func (o defaultDisabledOpt) applyInt64Gauge(c Int64GaugeConfig) Int64GaugeConfig { - c.defaultDisabled = true +func (o optInOpt) applyInt64Gauge(c Int64GaugeConfig) Int64GaugeConfig { + c.optIn = true return c } -func (o defaultDisabledOpt) applyInt64ObservableCounter(c Int64ObservableCounterConfig) Int64ObservableCounterConfig { - c.defaultDisabled = true +func (o optInOpt) applyInt64ObservableCounter(c Int64ObservableCounterConfig) Int64ObservableCounterConfig { + c.optIn = true return c } -func (o defaultDisabledOpt) applyInt64ObservableUpDownCounter( +func (o optInOpt) applyInt64ObservableUpDownCounter( c Int64ObservableUpDownCounterConfig, ) Int64ObservableUpDownCounterConfig { - c.defaultDisabled = true + c.optIn = true return c } -func (o defaultDisabledOpt) applyInt64ObservableGauge(c Int64ObservableGaugeConfig) Int64ObservableGaugeConfig { - c.defaultDisabled = true +func (o optInOpt) applyInt64ObservableGauge(c Int64ObservableGaugeConfig) Int64ObservableGaugeConfig { + c.optIn = true return c } -// WithDefaultDisabled sets the instrument to be disabled by default. -func WithDefaultDisabled() InstrumentOption { return defaultDisabledOpt{} } +// WithOptIn sets the instrument to be disabled by default. +func WithOptIn() InstrumentOption { return optInOpt{} } // WithExplicitBucketBoundaries sets the instrument explicit bucket boundaries. // diff --git a/metric/syncfloat64.go b/metric/syncfloat64.go index c3287f85194..edaddfef5d6 100644 --- a/metric/syncfloat64.go +++ b/metric/syncfloat64.go @@ -30,9 +30,9 @@ type Float64Counter interface { // Float64CounterConfig contains options for synchronous counter instruments that // record float64 values. type Float64CounterConfig struct { - description string - unit string - defaultDisabled bool + description string + unit string + optIn bool } // NewFloat64CounterConfig returns a new [Float64CounterConfig] with all opts @@ -55,9 +55,9 @@ func (c Float64CounterConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Float64CounterConfig) DefaultDisabled() bool { - return c.defaultDisabled +// optIn returns true if the instrument is disabled by default. +func (c Float64CounterConfig) OptIn() bool { + return c.optIn } // Float64CounterOption applies options to a [Float64CounterConfig]. See @@ -89,9 +89,9 @@ type Float64UpDownCounter interface { // Float64UpDownCounterConfig contains options for synchronous counter // instruments that record float64 values. type Float64UpDownCounterConfig struct { - description string - unit string - defaultDisabled bool + description string + unit string + optIn bool } // NewFloat64UpDownCounterConfig returns a new [Float64UpDownCounterConfig] @@ -114,9 +114,9 @@ func (c Float64UpDownCounterConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Float64UpDownCounterConfig) DefaultDisabled() bool { - return c.defaultDisabled +// optIn returns true if the instrument is disabled by default. +func (c Float64UpDownCounterConfig) OptIn() bool { + return c.optIn } // Float64UpDownCounterOption applies options to a @@ -150,7 +150,7 @@ type Float64Histogram interface { type Float64HistogramConfig struct { description string unit string - defaultDisabled bool + optIn bool explicitBucketBoundaries []float64 } @@ -174,9 +174,9 @@ func (c Float64HistogramConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Float64HistogramConfig) DefaultDisabled() bool { - return c.defaultDisabled +// optIn returns true if the instrument is disabled by default. +func (c Float64HistogramConfig) OptIn() bool { + return c.optIn } // ExplicitBucketBoundaries returns the configured explicit bucket boundaries. @@ -212,9 +212,9 @@ type Float64Gauge interface { // Float64GaugeConfig contains options for synchronous gauge instruments that // record float64 values. type Float64GaugeConfig struct { - description string - unit string - defaultDisabled bool + description string + unit string + optIn bool } // NewFloat64GaugeConfig returns a new [Float64GaugeConfig] with all opts @@ -237,9 +237,9 @@ func (c Float64GaugeConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Float64GaugeConfig) DefaultDisabled() bool { - return c.defaultDisabled +// optIn returns true if the instrument is disabled by default. +func (c Float64GaugeConfig) OptIn() bool { + return c.optIn } // Float64GaugeOption applies options to a [Float64GaugeConfig]. See diff --git a/metric/syncfloat64_test.go b/metric/syncfloat64_test.go index f663f5ae7fb..e815480decf 100644 --- a/metric/syncfloat64_test.go +++ b/metric/syncfloat64_test.go @@ -11,41 +11,41 @@ import ( func TestFloat64Configuration(t *testing.T) { const ( - token float64 = 43 - desc = "Instrument description." - uBytes = "By" - defaultDisabled = true + token float64 = 43 + desc = "Instrument description." + uBytes = "By" + optIn = true ) run := func(got float64Config) func(*testing.T) { return func(t *testing.T) { assert.Equal(t, desc, got.Description(), "description") assert.Equal(t, uBytes, got.Unit(), "unit") - assert.Equal(t, defaultDisabled, got.DefaultDisabled(), "defaultDisabled") + assert.Equal(t, optIn, got.OptIn(), "optIn") } } t.Run("Float64Counter", run( - NewFloat64CounterConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), + NewFloat64CounterConfig(WithDescription(desc), WithUnit(uBytes), WithOptIn()), )) t.Run("Float64UpDownCounter", run( - NewFloat64UpDownCounterConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), + NewFloat64UpDownCounterConfig(WithDescription(desc), WithUnit(uBytes), WithOptIn()), )) t.Run("Float64Histogram", run( - NewFloat64HistogramConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), + NewFloat64HistogramConfig(WithDescription(desc), WithUnit(uBytes), WithOptIn()), )) t.Run("Float64Gauge", run( - NewFloat64GaugeConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), + NewFloat64GaugeConfig(WithDescription(desc), WithUnit(uBytes), WithOptIn()), )) } type float64Config interface { Description() string Unit() string - DefaultDisabled() bool + OptIn() bool } func TestFloat64ExplicitBucketHistogramConfiguration(t *testing.T) { diff --git a/metric/syncint64.go b/metric/syncint64.go index 606e5ec8ca5..d90a91a93bc 100644 --- a/metric/syncint64.go +++ b/metric/syncint64.go @@ -30,9 +30,9 @@ type Int64Counter interface { // Int64CounterConfig contains options for synchronous counter instruments that // record int64 values. type Int64CounterConfig struct { - description string - unit string - defaultDisabled bool + description string + unit string + optIn bool } // NewInt64CounterConfig returns a new [Int64CounterConfig] with all opts @@ -55,9 +55,9 @@ func (c Int64CounterConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Int64CounterConfig) DefaultDisabled() bool { - return c.defaultDisabled +// OptIn returns true if the instrument is disabled by default. +func (c Int64CounterConfig) OptIn() bool { + return c.optIn } // Int64CounterOption applies options to a [Int64CounterConfig]. See @@ -89,9 +89,9 @@ type Int64UpDownCounter interface { // Int64UpDownCounterConfig contains options for synchronous counter // instruments that record int64 values. type Int64UpDownCounterConfig struct { - description string - unit string - defaultDisabled bool + description string + unit string + optIn bool } // NewInt64UpDownCounterConfig returns a new [Int64UpDownCounterConfig] with @@ -114,9 +114,9 @@ func (c Int64UpDownCounterConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Int64UpDownCounterConfig) DefaultDisabled() bool { - return c.defaultDisabled +// OptIn returns true if the instrument is disabled by default. +func (c Int64UpDownCounterConfig) OptIn() bool { + return c.optIn } // Int64UpDownCounterOption applies options to a [Int64UpDownCounterConfig]. @@ -150,7 +150,7 @@ type Int64Histogram interface { type Int64HistogramConfig struct { description string unit string - defaultDisabled bool + optIn bool explicitBucketBoundaries []float64 } @@ -174,9 +174,9 @@ func (c Int64HistogramConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Int64HistogramConfig) DefaultDisabled() bool { - return c.defaultDisabled +// OptIn returns true if the instrument is disabled by default. +func (c Int64HistogramConfig) OptIn() bool { + return c.optIn } // ExplicitBucketBoundaries returns the configured explicit bucket boundaries. @@ -212,9 +212,9 @@ type Int64Gauge interface { // Int64GaugeConfig contains options for synchronous gauge instruments that // record int64 values. type Int64GaugeConfig struct { - description string - unit string - defaultDisabled bool + description string + unit string + optIn bool } // NewInt64GaugeConfig returns a new [Int64GaugeConfig] with all opts @@ -237,9 +237,9 @@ func (c Int64GaugeConfig) Unit() string { return c.unit } -// DefaultDisabled returns true if the instrument is disabled by default. -func (c Int64GaugeConfig) DefaultDisabled() bool { - return c.defaultDisabled +// OptIn returns true if the instrument is disabled by default. +func (c Int64GaugeConfig) OptIn() bool { + return c.optIn } // Int64GaugeOption applies options to a [Int64GaugeConfig]. See diff --git a/metric/syncint64_test.go b/metric/syncint64_test.go index 4933d7c0a2c..bb0d1d9e404 100644 --- a/metric/syncint64_test.go +++ b/metric/syncint64_test.go @@ -11,41 +11,41 @@ import ( func TestInt64Configuration(t *testing.T) { const ( - token int64 = 43 - desc = "Instrument description." - uBytes = "By" - defaultDisabled = true + token int64 = 43 + desc = "Instrument description." + uBytes = "By" + optIn = true ) run := func(got int64Config) func(*testing.T) { return func(t *testing.T) { assert.Equal(t, desc, got.Description(), "description") assert.Equal(t, uBytes, got.Unit(), "unit") - assert.Equal(t, defaultDisabled, got.DefaultDisabled(), "defaultDisabled") + assert.Equal(t, optIn, got.OptIn(), "optIn") } } t.Run("Int64Counter", run( - NewInt64CounterConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), + NewInt64CounterConfig(WithDescription(desc), WithUnit(uBytes), WithOptIn()), )) t.Run("Int64UpDownCounter", run( - NewInt64UpDownCounterConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), + NewInt64UpDownCounterConfig(WithDescription(desc), WithUnit(uBytes), WithOptIn()), )) t.Run("Int64Histogram", run( - NewInt64HistogramConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), + NewInt64HistogramConfig(WithDescription(desc), WithUnit(uBytes), WithOptIn()), )) t.Run("Int64Gauge", run( - NewInt64GaugeConfig(WithDescription(desc), WithUnit(uBytes), WithDefaultDisabled()), + NewInt64GaugeConfig(WithDescription(desc), WithUnit(uBytes), WithOptIn()), )) } type int64Config interface { Description() string Unit() string - DefaultDisabled() bool + OptIn() bool } func TestInt64ExplicitBucketHistogramConfiguration(t *testing.T) { diff --git a/sdk/metric/example_test.go b/sdk/metric/example_test.go index 442500c4c83..554a34320d3 100644 --- a/sdk/metric/example_test.go +++ b/sdk/metric/example_test.go @@ -176,8 +176,8 @@ func ExampleNewView_optIn() { metric.WithView(view), ) - // A metric can be marked opt-in using apimetric.WithDefaultDieabled. - mp.Meter("example").Int64Counter("optin.counter", apimetric.WithDefaultDisabled()) + // A metric can be marked opt-in using apimetric.WithOptIn. + mp.Meter("example").Int64Counter("optin.counter", apimetric.WithOptIn()) // Below is an example of how the view will // function in the SDK for certain instruments. diff --git a/sdk/metric/meter.go b/sdk/metric/meter.go index 502e26871a4..ec0b91ec8f4 100644 --- a/sdk/metric/meter.go +++ b/sdk/metric/meter.go @@ -70,7 +70,7 @@ func (m *meter) Int64Counter(name string, options ...metric.Int64CounterOption) cfg := metric.NewInt64CounterConfig(options...) const kind = InstrumentKindCounter p := int64InstProvider{m} - i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.DefaultDisabled()) + i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.OptIn()) if err != nil { return i, err } @@ -88,7 +88,7 @@ func (m *meter) Int64UpDownCounter( cfg := metric.NewInt64UpDownCounterConfig(options...) const kind = InstrumentKindUpDownCounter p := int64InstProvider{m} - i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.DefaultDisabled()) + i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.OptIn()) if err != nil { return i, err } @@ -117,7 +117,7 @@ func (m *meter) Int64Gauge(name string, options ...metric.Int64GaugeOption) (met cfg := metric.NewInt64GaugeConfig(options...) const kind = InstrumentKindGauge p := int64InstProvider{m} - i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.DefaultDisabled()) + i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.OptIn()) if err != nil { return i, err } @@ -127,7 +127,7 @@ func (m *meter) Int64Gauge(name string, options ...metric.Int64GaugeOption) (met // int64ObservableInstrument returns a new observable identified by the Instrument. // It registers callbacks for each reader's pipeline. -func (m *meter) int64ObservableInstrument(id Instrument, callbacks []metric.Int64Callback, defaultDisabled bool) (int64Observable, error) { +func (m *meter) int64ObservableInstrument(id Instrument, callbacks []metric.Int64Callback, optIn bool) (int64Observable, error) { key := instID{ Name: id.Name, Description: id.Description, @@ -142,7 +142,7 @@ func (m *meter) int64ObservableInstrument(id Instrument, callbacks []metric.Int6 for _, insert := range m.int64Resolver.inserters { // Connect the measure functions for instruments in this pipeline with the // callbacks for this pipeline. - in, err := insert.Instrument(id, insert.readerDefaultAggregation(id.Kind), defaultDisabled) + in, err := insert.Instrument(id, insert.readerDefaultAggregation(id.Kind), optIn) if err != nil { return inst, err } @@ -188,7 +188,7 @@ func (m *meter) Int64ObservableCounter( Kind: InstrumentKindObservableCounter, Scope: m.scope, } - return m.int64ObservableInstrument(id, cfg.Callbacks(), cfg.DefaultDisabled()) + return m.int64ObservableInstrument(id, cfg.Callbacks(), cfg.OptIn()) } // Int64ObservableUpDownCounter returns a new instrument identified by name and @@ -212,7 +212,7 @@ func (m *meter) Int64ObservableUpDownCounter( Kind: InstrumentKindObservableUpDownCounter, Scope: m.scope, } - return m.int64ObservableInstrument(id, cfg.Callbacks(), cfg.DefaultDisabled()) + return m.int64ObservableInstrument(id, cfg.Callbacks(), cfg.OptIn()) } // Int64ObservableGauge returns a new instrument identified by name and @@ -236,7 +236,7 @@ func (m *meter) Int64ObservableGauge( Kind: InstrumentKindObservableGauge, Scope: m.scope, } - return m.int64ObservableInstrument(id, cfg.Callbacks(), cfg.DefaultDisabled()) + return m.int64ObservableInstrument(id, cfg.Callbacks(), cfg.OptIn()) } // Float64Counter returns a new instrument identified by name and configured @@ -246,7 +246,7 @@ func (m *meter) Float64Counter(name string, options ...metric.Float64CounterOpti cfg := metric.NewFloat64CounterConfig(options...) const kind = InstrumentKindCounter p := float64InstProvider{m} - i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.DefaultDisabled()) + i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.OptIn()) if err != nil { return i, err } @@ -264,7 +264,7 @@ func (m *meter) Float64UpDownCounter( cfg := metric.NewFloat64UpDownCounterConfig(options...) const kind = InstrumentKindUpDownCounter p := float64InstProvider{m} - i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.DefaultDisabled()) + i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.OptIn()) if err != nil { return i, err } @@ -296,7 +296,7 @@ func (m *meter) Float64Gauge(name string, options ...metric.Float64GaugeOption) cfg := metric.NewFloat64GaugeConfig(options...) const kind = InstrumentKindGauge p := float64InstProvider{m} - i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.DefaultDisabled()) + i, err := p.lookup(kind, name, cfg.Description(), cfg.Unit(), cfg.OptIn()) if err != nil { return i, err } @@ -309,7 +309,7 @@ func (m *meter) Float64Gauge(name string, options ...metric.Float64GaugeOption) func (m *meter) float64ObservableInstrument( id Instrument, callbacks []metric.Float64Callback, - defaultDisabled bool, + optIn bool, ) (float64Observable, error) { key := instID{ Name: id.Name, @@ -325,7 +325,7 @@ func (m *meter) float64ObservableInstrument( for _, insert := range m.float64Resolver.inserters { // Connect the measure functions for instruments in this pipeline with the // callbacks for this pipeline. - in, err := insert.Instrument(id, insert.readerDefaultAggregation(id.Kind), defaultDisabled) + in, err := insert.Instrument(id, insert.readerDefaultAggregation(id.Kind), optIn) if err != nil { return inst, err } @@ -371,7 +371,7 @@ func (m *meter) Float64ObservableCounter( Kind: InstrumentKindObservableCounter, Scope: m.scope, } - return m.float64ObservableInstrument(id, cfg.Callbacks(), cfg.DefaultDisabled()) + return m.float64ObservableInstrument(id, cfg.Callbacks(), cfg.OptIn()) } // Float64ObservableUpDownCounter returns a new instrument identified by name @@ -395,7 +395,7 @@ func (m *meter) Float64ObservableUpDownCounter( Kind: InstrumentKindObservableUpDownCounter, Scope: m.scope, } - return m.float64ObservableInstrument(id, cfg.Callbacks(), cfg.DefaultDisabled()) + return m.float64ObservableInstrument(id, cfg.Callbacks(), cfg.OptIn()) } // Float64ObservableGauge returns a new instrument identified by name and @@ -419,7 +419,7 @@ func (m *meter) Float64ObservableGauge( Kind: InstrumentKindObservableGauge, Scope: m.scope, } - return m.float64ObservableInstrument(id, cfg.Callbacks(), cfg.DefaultDisabled()) + return m.float64ObservableInstrument(id, cfg.Callbacks(), cfg.OptIn()) } func validateInstrumentName(name string) error { @@ -634,7 +634,7 @@ func (noopRegister) Unregister() error { // int64InstProvider provides int64 OpenTelemetry instruments. type int64InstProvider struct{ *meter } -func (p int64InstProvider) aggs(kind InstrumentKind, name, desc, u string, defaultDisabled bool) ([]aggregate.Measure[int64], error) { +func (p int64InstProvider) aggs(kind InstrumentKind, name, desc, u string, optIn bool) ([]aggregate.Measure[int64], error) { inst := Instrument{ Name: name, Description: desc, @@ -642,7 +642,7 @@ func (p int64InstProvider) aggs(kind InstrumentKind, name, desc, u string, defau Kind: kind, Scope: p.scope, } - return p.int64Resolver.Aggregators(inst, defaultDisabled) + return p.int64Resolver.Aggregators(inst, optIn) } func (p int64InstProvider) histogramAggs( @@ -662,19 +662,19 @@ func (p int64InstProvider) histogramAggs( Kind: InstrumentKindHistogram, Scope: p.scope, } - measures, err := p.int64Resolver.HistogramAggregators(inst, boundaries, cfg.DefaultDisabled()) + measures, err := p.int64Resolver.HistogramAggregators(inst, boundaries, cfg.OptIn()) return measures, errors.Join(aggError, err) } // lookup returns the resolved instrumentImpl. -func (p int64InstProvider) lookup(kind InstrumentKind, name, desc, u string, defaultDisabled bool) (*int64Inst, error) { +func (p int64InstProvider) lookup(kind InstrumentKind, name, desc, u string, optIn bool) (*int64Inst, error) { return p.int64Insts.Lookup(instID{ Name: name, Description: desc, Unit: u, Kind: kind, }, func() (*int64Inst, error) { - aggs, err := p.aggs(kind, name, desc, u, defaultDisabled) + aggs, err := p.aggs(kind, name, desc, u, optIn) return &int64Inst{measures: aggs}, err }) } @@ -695,7 +695,7 @@ func (p int64InstProvider) lookupHistogram(name string, cfg metric.Int64Histogra // float64InstProvider provides float64 OpenTelemetry instruments. type float64InstProvider struct{ *meter } -func (p float64InstProvider) aggs(kind InstrumentKind, name, desc, u string, defaultDisabled bool) ([]aggregate.Measure[float64], error) { +func (p float64InstProvider) aggs(kind InstrumentKind, name, desc, u string, optIn bool) ([]aggregate.Measure[float64], error) { inst := Instrument{ Name: name, Description: desc, @@ -703,7 +703,7 @@ func (p float64InstProvider) aggs(kind InstrumentKind, name, desc, u string, def Kind: kind, Scope: p.scope, } - return p.float64Resolver.Aggregators(inst, defaultDisabled) + return p.float64Resolver.Aggregators(inst, optIn) } func (p float64InstProvider) histogramAggs( @@ -723,19 +723,19 @@ func (p float64InstProvider) histogramAggs( Kind: InstrumentKindHistogram, Scope: p.scope, } - measures, err := p.float64Resolver.HistogramAggregators(inst, boundaries, cfg.DefaultDisabled()) + measures, err := p.float64Resolver.HistogramAggregators(inst, boundaries, cfg.OptIn()) return measures, errors.Join(aggError, err) } // lookup returns the resolved instrumentImpl. -func (p float64InstProvider) lookup(kind InstrumentKind, name, desc, u string, defaultDisabled bool) (*float64Inst, error) { +func (p float64InstProvider) lookup(kind InstrumentKind, name, desc, u string, optIn bool) (*float64Inst, error) { return p.float64Insts.Lookup(instID{ Name: name, Description: desc, Unit: u, Kind: kind, }, func() (*float64Inst, error) { - aggs, err := p.aggs(kind, name, desc, u, defaultDisabled) + aggs, err := p.aggs(kind, name, desc, u, optIn) return &float64Inst{measures: aggs}, err }) } diff --git a/sdk/metric/pipeline.go b/sdk/metric/pipeline.go index 07f1dd9265d..d550cba56ab 100644 --- a/sdk/metric/pipeline.go +++ b/sdk/metric/pipeline.go @@ -236,7 +236,7 @@ func newInserter[N int64 | float64](p *pipeline, vc *cache[string, instID]) *ins // // If an instrument is determined to use a Drop aggregation, that instrument is // not inserted nor returned. -func (i *inserter[N]) Instrument(inst Instrument, readerAggregation Aggregation, defaultDisabled bool) ([]aggregate.Measure[N], error) { +func (i *inserter[N]) Instrument(inst Instrument, readerAggregation Aggregation, optIn bool) ([]aggregate.Measure[N], error) { var ( matched bool measures []aggregate.Measure[N] @@ -250,7 +250,7 @@ func (i *inserter[N]) Instrument(inst Instrument, readerAggregation Aggregation, continue } matched = true - in, id, e := i.cachedAggregator(inst.Scope, inst.Kind, stream, readerAggregation, defaultDisabled) + in, id, e := i.cachedAggregator(inst.Scope, inst.Kind, stream, readerAggregation, optIn) if e != nil { err = errors.Join(err, e) } @@ -279,7 +279,7 @@ func (i *inserter[N]) Instrument(inst Instrument, readerAggregation Aggregation, Description: inst.Description, Unit: inst.Unit, } - in, _, e := i.cachedAggregator(inst.Scope, inst.Kind, stream, readerAggregation, defaultDisabled) + in, _, e := i.cachedAggregator(inst.Scope, inst.Kind, stream, readerAggregation, optIn) if e != nil { if err == nil { err = errCreatingAggregators @@ -354,7 +354,7 @@ func (i *inserter[N]) cachedAggregator( kind InstrumentKind, stream Stream, readerAggregation Aggregation, - defaultDisabled bool, + optIn bool, ) (meas aggregate.Measure[N], aggID uint64, err error) { switch stream.Aggregation.(type) { case nil: @@ -371,7 +371,7 @@ func (i *inserter[N]) cachedAggregator( isEnabled := stream.Enabled != nil && *stream.Enabled isDisabled := stream.Enabled != nil && !*stream.Enabled - if (defaultDisabled && !isEnabled) || isDisabled { + if (optIn && !isEnabled) || isDisabled { stream.Aggregation = AggregationDrop{} } @@ -648,12 +648,12 @@ func newResolver[N int64 | float64](p pipelines, vc *cache[string, instID]) reso // Aggregators returns the Aggregators that must be updated by the instrument // defined by key. -func (r resolver[N]) Aggregators(id Instrument, defaultDisabled bool) ([]aggregate.Measure[N], error) { +func (r resolver[N]) Aggregators(id Instrument, optIn bool) ([]aggregate.Measure[N], error) { var measures []aggregate.Measure[N] var err error for _, i := range r.inserters { - in, e := i.Instrument(id, i.readerDefaultAggregation(id.Kind), defaultDisabled) + in, e := i.Instrument(id, i.readerDefaultAggregation(id.Kind), optIn) if e != nil { err = errors.Join(err, e) } @@ -665,7 +665,7 @@ func (r resolver[N]) Aggregators(id Instrument, defaultDisabled bool) ([]aggrega // HistogramAggregators returns the histogram Aggregators that must be updated by the instrument // defined by key. If boundaries were provided on instrument instantiation, those take precedence // over boundaries provided by the reader. -func (r resolver[N]) HistogramAggregators(id Instrument, boundaries []float64, defaultDisabled bool) ([]aggregate.Measure[N], error) { +func (r resolver[N]) HistogramAggregators(id Instrument, boundaries []float64, optIn bool) ([]aggregate.Measure[N], error) { var measures []aggregate.Measure[N] var err error @@ -675,7 +675,7 @@ func (r resolver[N]) HistogramAggregators(id Instrument, boundaries []float64, d histAgg.Boundaries = boundaries agg = histAgg } - in, e := i.Instrument(id, agg, defaultDisabled) + in, e := i.Instrument(id, agg, optIn) if e != nil { err = errors.Join(err, e) }