1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

Split metric configuration down to instrument (#3895)

* Split metric configuration down to instrument

* Rename *ObserverOptions to *ObservableOption

* Update option docs with links
This commit is contained in:
Tyler Yahn
2023-03-21 06:16:57 -07:00
committed by GitHub
parent 6eb1157b45
commit 90df52586b
17 changed files with 789 additions and 255 deletions
+7
View File
@@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The `WithoutTimestamps` option to `go.opentelemetry.io/otel/exporters/stdout/stdoutmetric` to sets all timestamps to zero. (#3828)
- The new `Exemplar` type is added to `go.opentelemetry.io/otel/sdk/metric/metricdata`.
Both the `DataPoint` and `HistogramDataPoint` types from that package have a new field of `Exemplars` containing the sampled exemplars for their timeseries. (#3849)
- Configuration for each metric instrument in `go.opentelemetry.io/otel/sdk/metric/instrument`. (#3895)
### Changed
@@ -23,11 +24,17 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Both the `Histogram` and `HistogramDataPoint` are redefined with a generic argument of `[N int64 | float64]` in `go.opentelemetry.io/otel/sdk/metric/metricdata`. (#3849)
- The metric `Export` interface from `go.opentelemetry.io/otel/sdk/metric` accepts a `*ResourceMetrics` instead of `ResourceMetrics`. (#3853)
- Rename `Asynchronous` to `Observable` in `go.opentelemetry.io/otel/metric/instrument`. (#3892)
- Rename `Int64ObserverOption` to `Int64ObservableOption` in `go.opentelemetry.io/otel/metric/instrument`. (#3895)
- Rename `Float64ObserverOption` to `Float64ObservableOption` in `go.opentelemetry.io/otel/metric/instrument`. (#3895)
### Removed
- The deprecated `go.opentelemetry.io/otel/metric/global` package is removed. (#3829)
- The unneeded `Synchronous` interface in `go.opentelemetry.io/otel/metric/instrument` was removed. (#3892)
- The `Float64ObserverConfig` and `NewFloat64ObserverConfig` in `go.opentelemetry.io/otel/sdk/metric/instrument`.
Use the added `float64` instrument configuration instead. (#3895)
- The `Int64ObserverConfig` and `NewInt64ObserverConfig` in `go.opentelemetry.io/otel/sdk/metric/instrument`.
Use the added `int64` instrument configuration instead. (#3895)
## [1.15.0-rc.1/0.38.0-rc.1] 2023-03-01
+12 -12
View File
@@ -32,7 +32,7 @@ type afCounter struct {
instrument.Float64Observable
name string
opts []instrument.Float64ObserverOption
opts []instrument.Float64ObservableCounterOption
delegate atomic.Value //instrument.Float64ObservableCounter
}
@@ -60,7 +60,7 @@ type afUpDownCounter struct {
instrument.Float64Observable
name string
opts []instrument.Float64ObserverOption
opts []instrument.Float64ObservableUpDownCounterOption
delegate atomic.Value //instrument.Float64ObservableUpDownCounter
}
@@ -88,7 +88,7 @@ type afGauge struct {
instrument.Float64Observable
name string
opts []instrument.Float64ObserverOption
opts []instrument.Float64ObservableGaugeOption
delegate atomic.Value //instrument.Float64ObservableGauge
}
@@ -116,7 +116,7 @@ type aiCounter struct {
instrument.Int64Observable
name string
opts []instrument.Int64ObserverOption
opts []instrument.Int64ObservableCounterOption
delegate atomic.Value //instrument.Int64ObservableCounter
}
@@ -144,7 +144,7 @@ type aiUpDownCounter struct {
instrument.Int64Observable
name string
opts []instrument.Int64ObserverOption
opts []instrument.Int64ObservableUpDownCounterOption
delegate atomic.Value //instrument.Int64ObservableUpDownCounter
}
@@ -172,7 +172,7 @@ type aiGauge struct {
instrument.Int64Observable
name string
opts []instrument.Int64ObserverOption
opts []instrument.Int64ObservableGaugeOption
delegate atomic.Value //instrument.Int64ObservableGauge
}
@@ -199,7 +199,7 @@ func (i *aiGauge) Unwrap() instrument.Observable {
// Sync Instruments.
type sfCounter struct {
name string
opts []instrument.Float64Option
opts []instrument.Float64CounterOption
delegate atomic.Value //instrument.Float64Counter
}
@@ -223,7 +223,7 @@ func (i *sfCounter) Add(ctx context.Context, incr float64, attrs ...attribute.Ke
type sfUpDownCounter struct {
name string
opts []instrument.Float64Option
opts []instrument.Float64UpDownCounterOption
delegate atomic.Value //instrument.Float64UpDownCounter
}
@@ -247,7 +247,7 @@ func (i *sfUpDownCounter) Add(ctx context.Context, incr float64, attrs ...attrib
type sfHistogram struct {
name string
opts []instrument.Float64Option
opts []instrument.Float64HistogramOption
delegate atomic.Value //instrument.Float64Histogram
}
@@ -271,7 +271,7 @@ func (i *sfHistogram) Record(ctx context.Context, x float64, attrs ...attribute.
type siCounter struct {
name string
opts []instrument.Int64Option
opts []instrument.Int64CounterOption
delegate atomic.Value //instrument.Int64Counter
}
@@ -295,7 +295,7 @@ func (i *siCounter) Add(ctx context.Context, x int64, attrs ...attribute.KeyValu
type siUpDownCounter struct {
name string
opts []instrument.Int64Option
opts []instrument.Int64UpDownCounterOption
delegate atomic.Value //instrument.Int64UpDownCounter
}
@@ -319,7 +319,7 @@ func (i *siUpDownCounter) Add(ctx context.Context, x int64, attrs ...attribute.K
type siHistogram struct {
name string
opts []instrument.Int64Option
opts []instrument.Int64HistogramOption
delegate atomic.Value //instrument.Int64Histogram
}
+12 -12
View File
@@ -136,7 +136,7 @@ func (m *meter) setDelegate(provider metric.MeterProvider) {
m.registry.Init()
}
func (m *meter) Int64Counter(name string, options ...instrument.Int64Option) (instrument.Int64Counter, error) {
func (m *meter) Int64Counter(name string, options ...instrument.Int64CounterOption) (instrument.Int64Counter, error) {
if del, ok := m.delegate.Load().(metric.Meter); ok {
return del.Int64Counter(name, options...)
}
@@ -147,7 +147,7 @@ func (m *meter) Int64Counter(name string, options ...instrument.Int64Option) (in
return i, nil
}
func (m *meter) Int64UpDownCounter(name string, options ...instrument.Int64Option) (instrument.Int64UpDownCounter, error) {
func (m *meter) Int64UpDownCounter(name string, options ...instrument.Int64UpDownCounterOption) (instrument.Int64UpDownCounter, error) {
if del, ok := m.delegate.Load().(metric.Meter); ok {
return del.Int64UpDownCounter(name, options...)
}
@@ -158,7 +158,7 @@ func (m *meter) Int64UpDownCounter(name string, options ...instrument.Int64Optio
return i, nil
}
func (m *meter) Int64Histogram(name string, options ...instrument.Int64Option) (instrument.Int64Histogram, error) {
func (m *meter) Int64Histogram(name string, options ...instrument.Int64HistogramOption) (instrument.Int64Histogram, error) {
if del, ok := m.delegate.Load().(metric.Meter); ok {
return del.Int64Histogram(name, options...)
}
@@ -169,7 +169,7 @@ func (m *meter) Int64Histogram(name string, options ...instrument.Int64Option) (
return i, nil
}
func (m *meter) Int64ObservableCounter(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableCounter, error) {
func (m *meter) Int64ObservableCounter(name string, options ...instrument.Int64ObservableCounterOption) (instrument.Int64ObservableCounter, error) {
if del, ok := m.delegate.Load().(metric.Meter); ok {
return del.Int64ObservableCounter(name, options...)
}
@@ -180,7 +180,7 @@ func (m *meter) Int64ObservableCounter(name string, options ...instrument.Int64O
return i, nil
}
func (m *meter) Int64ObservableUpDownCounter(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableUpDownCounter, error) {
func (m *meter) Int64ObservableUpDownCounter(name string, options ...instrument.Int64ObservableUpDownCounterOption) (instrument.Int64ObservableUpDownCounter, error) {
if del, ok := m.delegate.Load().(metric.Meter); ok {
return del.Int64ObservableUpDownCounter(name, options...)
}
@@ -191,7 +191,7 @@ func (m *meter) Int64ObservableUpDownCounter(name string, options ...instrument.
return i, nil
}
func (m *meter) Int64ObservableGauge(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableGauge, error) {
func (m *meter) Int64ObservableGauge(name string, options ...instrument.Int64ObservableGaugeOption) (instrument.Int64ObservableGauge, error) {
if del, ok := m.delegate.Load().(metric.Meter); ok {
return del.Int64ObservableGauge(name, options...)
}
@@ -202,7 +202,7 @@ func (m *meter) Int64ObservableGauge(name string, options ...instrument.Int64Obs
return i, nil
}
func (m *meter) Float64Counter(name string, options ...instrument.Float64Option) (instrument.Float64Counter, error) {
func (m *meter) Float64Counter(name string, options ...instrument.Float64CounterOption) (instrument.Float64Counter, error) {
if del, ok := m.delegate.Load().(metric.Meter); ok {
return del.Float64Counter(name, options...)
}
@@ -213,7 +213,7 @@ func (m *meter) Float64Counter(name string, options ...instrument.Float64Option)
return i, nil
}
func (m *meter) Float64UpDownCounter(name string, options ...instrument.Float64Option) (instrument.Float64UpDownCounter, error) {
func (m *meter) Float64UpDownCounter(name string, options ...instrument.Float64UpDownCounterOption) (instrument.Float64UpDownCounter, error) {
if del, ok := m.delegate.Load().(metric.Meter); ok {
return del.Float64UpDownCounter(name, options...)
}
@@ -224,7 +224,7 @@ func (m *meter) Float64UpDownCounter(name string, options ...instrument.Float64O
return i, nil
}
func (m *meter) Float64Histogram(name string, options ...instrument.Float64Option) (instrument.Float64Histogram, error) {
func (m *meter) Float64Histogram(name string, options ...instrument.Float64HistogramOption) (instrument.Float64Histogram, error) {
if del, ok := m.delegate.Load().(metric.Meter); ok {
return del.Float64Histogram(name, options...)
}
@@ -235,7 +235,7 @@ func (m *meter) Float64Histogram(name string, options ...instrument.Float64Optio
return i, nil
}
func (m *meter) Float64ObservableCounter(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableCounter, error) {
func (m *meter) Float64ObservableCounter(name string, options ...instrument.Float64ObservableCounterOption) (instrument.Float64ObservableCounter, error) {
if del, ok := m.delegate.Load().(metric.Meter); ok {
return del.Float64ObservableCounter(name, options...)
}
@@ -246,7 +246,7 @@ func (m *meter) Float64ObservableCounter(name string, options ...instrument.Floa
return i, nil
}
func (m *meter) Float64ObservableUpDownCounter(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableUpDownCounter, error) {
func (m *meter) Float64ObservableUpDownCounter(name string, options ...instrument.Float64ObservableUpDownCounterOption) (instrument.Float64ObservableUpDownCounter, error) {
if del, ok := m.delegate.Load().(metric.Meter); ok {
return del.Float64ObservableUpDownCounter(name, options...)
}
@@ -257,7 +257,7 @@ func (m *meter) Float64ObservableUpDownCounter(name string, options ...instrumen
return i, nil
}
func (m *meter) Float64ObservableGauge(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableGauge, error) {
func (m *meter) Float64ObservableGauge(name string, options ...instrument.Float64ObservableGaugeOption) (instrument.Float64ObservableGauge, error) {
if del, ok := m.delegate.Load().(metric.Meter); ok {
return del.Float64ObservableGauge(name, options...)
}
+12 -12
View File
@@ -52,62 +52,62 @@ type testMeter struct {
callbacks []metric.Callback
}
func (m *testMeter) Int64Counter(name string, options ...instrument.Int64Option) (instrument.Int64Counter, error) {
func (m *testMeter) Int64Counter(name string, options ...instrument.Int64CounterOption) (instrument.Int64Counter, error) {
m.siCount++
return &testCountingIntInstrument{}, nil
}
func (m *testMeter) Int64UpDownCounter(name string, options ...instrument.Int64Option) (instrument.Int64UpDownCounter, error) {
func (m *testMeter) Int64UpDownCounter(name string, options ...instrument.Int64UpDownCounterOption) (instrument.Int64UpDownCounter, error) {
m.siUDCount++
return &testCountingIntInstrument{}, nil
}
func (m *testMeter) Int64Histogram(name string, options ...instrument.Int64Option) (instrument.Int64Histogram, error) {
func (m *testMeter) Int64Histogram(name string, options ...instrument.Int64HistogramOption) (instrument.Int64Histogram, error) {
m.siHist++
return &testCountingIntInstrument{}, nil
}
func (m *testMeter) Int64ObservableCounter(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableCounter, error) {
func (m *testMeter) Int64ObservableCounter(name string, options ...instrument.Int64ObservableCounterOption) (instrument.Int64ObservableCounter, error) {
m.aiCount++
return &testCountingIntInstrument{}, nil
}
func (m *testMeter) Int64ObservableUpDownCounter(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableUpDownCounter, error) {
func (m *testMeter) Int64ObservableUpDownCounter(name string, options ...instrument.Int64ObservableUpDownCounterOption) (instrument.Int64ObservableUpDownCounter, error) {
m.aiUDCount++
return &testCountingIntInstrument{}, nil
}
func (m *testMeter) Int64ObservableGauge(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableGauge, error) {
func (m *testMeter) Int64ObservableGauge(name string, options ...instrument.Int64ObservableGaugeOption) (instrument.Int64ObservableGauge, error) {
m.aiGauge++
return &testCountingIntInstrument{}, nil
}
func (m *testMeter) Float64Counter(name string, options ...instrument.Float64Option) (instrument.Float64Counter, error) {
func (m *testMeter) Float64Counter(name string, options ...instrument.Float64CounterOption) (instrument.Float64Counter, error) {
m.sfCount++
return &testCountingFloatInstrument{}, nil
}
func (m *testMeter) Float64UpDownCounter(name string, options ...instrument.Float64Option) (instrument.Float64UpDownCounter, error) {
func (m *testMeter) Float64UpDownCounter(name string, options ...instrument.Float64UpDownCounterOption) (instrument.Float64UpDownCounter, error) {
m.sfUDCount++
return &testCountingFloatInstrument{}, nil
}
func (m *testMeter) Float64Histogram(name string, options ...instrument.Float64Option) (instrument.Float64Histogram, error) {
func (m *testMeter) Float64Histogram(name string, options ...instrument.Float64HistogramOption) (instrument.Float64Histogram, error) {
m.sfHist++
return &testCountingFloatInstrument{}, nil
}
func (m *testMeter) Float64ObservableCounter(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableCounter, error) {
func (m *testMeter) Float64ObservableCounter(name string, options ...instrument.Float64ObservableCounterOption) (instrument.Float64ObservableCounter, error) {
m.afCount++
return &testCountingFloatInstrument{}, nil
}
func (m *testMeter) Float64ObservableUpDownCounter(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableUpDownCounter, error) {
func (m *testMeter) Float64ObservableUpDownCounter(name string, options ...instrument.Float64ObservableUpDownCounterOption) (instrument.Float64ObservableUpDownCounter, error) {
m.afUDCount++
return &testCountingFloatInstrument{}, nil
}
func (m *testMeter) Float64ObservableGauge(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableGauge, error) {
func (m *testMeter) Float64ObservableGauge(name string, options ...instrument.Float64ObservableGaugeOption) (instrument.Float64ObservableGauge, error) {
m.afGauge++
return &testCountingFloatInstrument{}, nil
}
+140 -39
View File
@@ -39,6 +39,46 @@ type Float64Observable interface {
// Warning: methods may be added to this interface in minor releases.
type Float64ObservableCounter interface{ Float64Observable }
// Float64ObservableCounterConfig contains options for asynchronous counter
// instruments that record int64 values.
type Float64ObservableCounterConfig struct {
description string
unit string
callbacks []Float64Callback
}
// NewFloat64ObservableCounterConfig returns a new
// [Float64ObservableCounterConfig] with all opts applied.
func NewFloat64ObservableCounterConfig(opts ...Float64ObservableCounterOption) Float64ObservableCounterConfig {
var config Float64ObservableCounterConfig
for _, o := range opts {
config = o.applyFloat64ObservableCounter(config)
}
return config
}
// Description returns the configured description.
func (c Float64ObservableCounterConfig) Description() string {
return c.description
}
// Unit returns the configured unit.
func (c Float64ObservableCounterConfig) Unit() string {
return c.unit
}
// Callbacks returns the configured callbacks.
func (c Float64ObservableCounterConfig) Callbacks() []Float64Callback {
return c.callbacks
}
// Float64ObservableCounterOption applies options to a
// [Float64ObservableCounterConfig]. See [Float64ObservableOption] and [Option]
// for other options that can be used as a Float64ObservableCounterOption.
type Float64ObservableCounterOption interface {
applyFloat64ObservableCounter(Float64ObservableCounterConfig) Float64ObservableCounterConfig
}
// Float64ObservableUpDownCounter is an instrument used to asynchronously
// record float64 measurements once per collection cycle. Observations are only
// made within a callback for this instrument. The value observed is assumed
@@ -47,6 +87,47 @@ type Float64ObservableCounter interface{ Float64Observable }
// Warning: methods may be added to this interface in minor releases.
type Float64ObservableUpDownCounter interface{ Float64Observable }
// Float64ObservableUpDownCounterConfig contains options for asynchronous
// counter instruments that record int64 values.
type Float64ObservableUpDownCounterConfig struct {
description string
unit string
callbacks []Float64Callback
}
// NewFloat64ObservableUpDownCounterConfig returns a new
// [Float64ObservableUpDownCounterConfig] with all opts applied.
func NewFloat64ObservableUpDownCounterConfig(opts ...Float64ObservableUpDownCounterOption) Float64ObservableUpDownCounterConfig {
var config Float64ObservableUpDownCounterConfig
for _, o := range opts {
config = o.applyFloat64ObservableUpDownCounter(config)
}
return config
}
// Description returns the configured description.
func (c Float64ObservableUpDownCounterConfig) Description() string {
return c.description
}
// Unit returns the configured unit.
func (c Float64ObservableUpDownCounterConfig) Unit() string {
return c.unit
}
// Callbacks returns the configured callbacks.
func (c Float64ObservableUpDownCounterConfig) Callbacks() []Float64Callback {
return c.callbacks
}
// Float64ObservableUpDownCounterOption applies options to a
// [Float64ObservableUpDownCounterConfig]. See [Float64ObservableOption] and
// [Option] for other options that can be used as a
// Float64ObservableUpDownCounterOption.
type Float64ObservableUpDownCounterOption interface {
applyFloat64ObservableUpDownCounter(Float64ObservableUpDownCounterConfig) Float64ObservableUpDownCounterConfig
}
// Float64ObservableGauge is an instrument used to asynchronously record
// instantaneous float64 measurements once per collection cycle. Observations
// are only made within a callback for this instrument.
@@ -54,6 +135,47 @@ type Float64ObservableUpDownCounter interface{ Float64Observable }
// Warning: methods may be added to this interface in minor releases.
type Float64ObservableGauge interface{ Float64Observable }
// Float64ObservableGaugeConfig contains options for asynchronous counter
// instruments that record int64 values.
type Float64ObservableGaugeConfig struct {
description string
unit string
callbacks []Float64Callback
}
// NewFloat64ObservableGaugeConfig returns a new [Float64ObservableGaugeConfig]
// with all opts applied.
func NewFloat64ObservableGaugeConfig(opts ...Float64ObservableGaugeOption) Float64ObservableGaugeConfig {
var config Float64ObservableGaugeConfig
for _, o := range opts {
config = o.applyFloat64ObservableGauge(config)
}
return config
}
// Description returns the configured description.
func (c Float64ObservableGaugeConfig) Description() string {
return c.description
}
// Unit returns the configured unit.
func (c Float64ObservableGaugeConfig) Unit() string {
return c.unit
}
// Callbacks returns the configured callbacks.
func (c Float64ObservableGaugeConfig) Callbacks() []Float64Callback {
return c.callbacks
}
// Float64ObservableGaugeOption applies options to a
// [Float64ObservableGaugeConfig]. See [Float64ObservableOption] and
// [Option] for other options that can be used as a
// Float64ObservableGaugeOption.
type Float64ObservableGaugeOption interface {
applyFloat64ObservableGauge(Float64ObservableGaugeConfig) Float64ObservableGaugeConfig
}
// Float64Observer is a recorder of float64 measurements.
//
// Warning: methods may be added to this interface in minor releases.
@@ -77,54 +199,33 @@ type Float64Observer interface {
// The function needs to be concurrent safe.
type Float64Callback func(context.Context, Float64Observer) error
// Float64ObserverConfig contains options for Observable instruments that
// observe float64 values.
type Float64ObserverConfig struct {
description string
unit string
callbacks []Float64Callback
// Float64ObservableOption applies options to float64 Observer instruments.
type Float64ObservableOption interface {
Float64ObservableCounterOption
Float64ObservableUpDownCounterOption
Float64ObservableGaugeOption
}
// NewFloat64ObserverConfig returns a new Float64ObserverConfig with all opts
// applied.
func NewFloat64ObserverConfig(opts ...Float64ObserverOption) Float64ObserverConfig {
var config Float64ObserverConfig
for _, o := range opts {
config = o.applyFloat64Observer(config)
}
return config
type float64CallbackOpt struct {
cback Float64Callback
}
// Description returns the Config description.
func (c Float64ObserverConfig) Description() string {
return c.description
func (o float64CallbackOpt) applyFloat64ObservableCounter(cfg Float64ObservableCounterConfig) Float64ObservableCounterConfig {
cfg.callbacks = append(cfg.callbacks, o.cback)
return cfg
}
// Unit returns the Config unit.
func (c Float64ObserverConfig) Unit() string {
return c.unit
func (o float64CallbackOpt) applyFloat64ObservableUpDownCounter(cfg Float64ObservableUpDownCounterConfig) Float64ObservableUpDownCounterConfig {
cfg.callbacks = append(cfg.callbacks, o.cback)
return cfg
}
// Callbacks returns the Config callbacks.
func (c Float64ObserverConfig) Callbacks() []Float64Callback {
return c.callbacks
}
// Float64ObserverOption applies options to float64 Observer instruments.
type Float64ObserverOption interface {
applyFloat64Observer(Float64ObserverConfig) Float64ObserverConfig
}
type float64ObserverOptionFunc func(Float64ObserverConfig) Float64ObserverConfig
func (fn float64ObserverOptionFunc) applyFloat64Observer(cfg Float64ObserverConfig) Float64ObserverConfig {
return fn(cfg)
func (o float64CallbackOpt) applyFloat64ObservableGauge(cfg Float64ObservableGaugeConfig) Float64ObservableGaugeConfig {
cfg.callbacks = append(cfg.callbacks, o.cback)
return cfg
}
// WithFloat64Callback adds callback to be called for an instrument.
func WithFloat64Callback(callback Float64Callback) Float64ObserverOption {
return float64ObserverOptionFunc(func(cfg Float64ObserverConfig) Float64ObserverConfig {
cfg.callbacks = append(cfg.callbacks, callback)
return cfg
})
func WithFloat64Callback(callback Float64Callback) Float64ObservableOption {
return float64CallbackOpt{callback}
}
+49 -18
View File
@@ -24,31 +24,62 @@ import (
"go.opentelemetry.io/otel/attribute"
)
func TestFloat64ObserverOptions(t *testing.T) {
func TestFloat64ObservableConfiguration(t *testing.T) {
const (
token float64 = 43
desc = "Instrument description."
uBytes = "By"
)
got := NewFloat64ObserverConfig(
WithDescription(desc),
WithUnit(uBytes),
WithFloat64Callback(func(ctx context.Context, obsrv Float64Observer) error {
obsrv.Observe(token)
return nil
}),
)
assert.Equal(t, desc, got.Description(), "description")
assert.Equal(t, uBytes, got.Unit(), "unit")
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")
// Functions are not comparable.
cBacks := got.Callbacks()
require.Len(t, cBacks, 1, "callbacks")
o := &float64Observer{}
err := cBacks[0](context.Background(), o)
require.NoError(t, err)
assert.Equal(t, token, o.got, "callback not set")
// Functions are not comparable.
cBacks := got.Callbacks()
require.Len(t, cBacks, 1, "callbacks")
o := &float64Observer{}
err := cBacks[0](context.Background(), o)
require.NoError(t, err)
assert.Equal(t, token, o.got, "callback not set")
}
}
cback := func(ctx context.Context, obsrv Float64Observer) error {
obsrv.Observe(token)
return nil
}
t.Run("Float64ObservableCounter", run(
NewFloat64ObservableCounterConfig(
WithDescription(desc),
WithUnit(uBytes),
WithFloat64Callback(cback),
),
))
t.Run("Float64ObservableUpDownCounter", run(
NewFloat64ObservableUpDownCounterConfig(
WithDescription(desc),
WithUnit(uBytes),
WithFloat64Callback(cback),
),
))
t.Run("Float64ObservableGauge", run(
NewFloat64ObservableGaugeConfig(
WithDescription(desc),
WithUnit(uBytes),
WithFloat64Callback(cback),
),
))
}
type float64ObservableConfig interface {
Description() string
Unit() string
Callbacks() []Float64Callback
}
type float64Observer struct {
+143 -44
View File
@@ -39,6 +39,46 @@ type Int64Observable interface {
// Warning: methods may be added to this interface in minor releases.
type Int64ObservableCounter interface{ Int64Observable }
// Int64ObservableCounterConfig contains options for asynchronous counter
// instruments that record int64 values.
type Int64ObservableCounterConfig struct {
description string
unit string
callbacks []Int64Callback
}
// NewInt64ObservableCounterConfig returns a new [Int64ObservableCounterConfig]
// with all opts applied.
func NewInt64ObservableCounterConfig(opts ...Int64ObservableCounterOption) Int64ObservableCounterConfig {
var config Int64ObservableCounterConfig
for _, o := range opts {
config = o.applyInt64ObservableCounter(config)
}
return config
}
// Description returns the configured description.
func (c Int64ObservableCounterConfig) Description() string {
return c.description
}
// Unit returns the configured unit.
func (c Int64ObservableCounterConfig) Unit() string {
return c.unit
}
// Callbacks returns the configured callbacks.
func (c Int64ObservableCounterConfig) Callbacks() []Int64Callback {
return c.callbacks
}
// Int64ObservableCounterOption applies options to a
// [Int64ObservableCounterConfig]. See [Int64ObservableOption] and [Option] for
// other options that can be used as an Int64ObservableCounterOption.
type Int64ObservableCounterOption interface {
applyInt64ObservableCounter(Int64ObservableCounterConfig) Int64ObservableCounterConfig
}
// Int64ObservableUpDownCounter is an instrument used to asynchronously record
// int64 measurements once per collection cycle. Observations are only made
// within a callback for this instrument. The value observed is assumed the to
@@ -47,6 +87,47 @@ type Int64ObservableCounter interface{ Int64Observable }
// Warning: methods may be added to this interface in minor releases.
type Int64ObservableUpDownCounter interface{ Int64Observable }
// Int64ObservableUpDownCounterConfig contains options for asynchronous counter
// instruments that record int64 values.
type Int64ObservableUpDownCounterConfig struct {
description string
unit string
callbacks []Int64Callback
}
// NewInt64ObservableUpDownCounterConfig returns a new
// [Int64ObservableUpDownCounterConfig] with all opts applied.
func NewInt64ObservableUpDownCounterConfig(opts ...Int64ObservableUpDownCounterOption) Int64ObservableUpDownCounterConfig {
var config Int64ObservableUpDownCounterConfig
for _, o := range opts {
config = o.applyInt64ObservableUpDownCounter(config)
}
return config
}
// Description returns the configured description.
func (c Int64ObservableUpDownCounterConfig) Description() string {
return c.description
}
// Unit returns the configured unit.
func (c Int64ObservableUpDownCounterConfig) Unit() string {
return c.unit
}
// Callbacks returns the configured callbacks.
func (c Int64ObservableUpDownCounterConfig) Callbacks() []Int64Callback {
return c.callbacks
}
// Int64ObservableUpDownCounterOption applies options to a
// [Int64ObservableUpDownCounterConfig]. See [Int64ObservableOption] and
// [Option] for other options that can be used as an
// Int64ObservableUpDownCounterOption.
type Int64ObservableUpDownCounterOption interface {
applyInt64ObservableUpDownCounter(Int64ObservableUpDownCounterConfig) Int64ObservableUpDownCounterConfig
}
// Int64ObservableGauge is an instrument used to asynchronously record
// instantaneous int64 measurements once per collection cycle. Observations are
// only made within a callback for this instrument.
@@ -54,6 +135,46 @@ type Int64ObservableUpDownCounter interface{ Int64Observable }
// Warning: methods may be added to this interface in minor releases.
type Int64ObservableGauge interface{ Int64Observable }
// Int64ObservableGaugeConfig contains options for asynchronous counter
// instruments that record int64 values.
type Int64ObservableGaugeConfig struct {
description string
unit string
callbacks []Int64Callback
}
// NewInt64ObservableGaugeConfig returns a new [Int64ObservableGaugeConfig]
// with all opts applied.
func NewInt64ObservableGaugeConfig(opts ...Int64ObservableGaugeOption) Int64ObservableGaugeConfig {
var config Int64ObservableGaugeConfig
for _, o := range opts {
config = o.applyInt64ObservableGauge(config)
}
return config
}
// Description returns the configured description.
func (c Int64ObservableGaugeConfig) Description() string {
return c.description
}
// Unit returns the configured unit.
func (c Int64ObservableGaugeConfig) Unit() string {
return c.unit
}
// Callbacks returns the configured callbacks.
func (c Int64ObservableGaugeConfig) Callbacks() []Int64Callback {
return c.callbacks
}
// Int64ObservableGaugeOption applies options to a
// [Int64ObservableGaugeConfig]. See [Int64ObservableOption] and [Option] for
// other options that can be used as an Int64ObservableGaugeOption.
type Int64ObservableGaugeOption interface {
applyInt64ObservableGauge(Int64ObservableGaugeConfig) Int64ObservableGaugeConfig
}
// Int64Observer is a recorder of int64 measurements.
//
// Warning: methods may be added to this interface in minor releases.
@@ -61,70 +182,48 @@ type Int64Observer interface {
Observe(value int64, attributes ...attribute.KeyValue)
}
// Int64Callback is a function registered with a Meter that makes
// observations for a Int64Observerable instrument it is registered with.
// Calls to the Int64Observer record measurement values for the
// Int64Observable.
// Int64Callback is a function registered with a Meter that makes observations
// for an Int64Observerable instrument it is registered with. Calls to the
// Int64Observer record measurement values for the Int64Observable.
//
// The function needs to complete in a finite amount of time and the deadline
// of the passed context is expected to be honored.
//
// The function needs to make unique observations across all registered
// Int64Callback. Meaning, it should not report measurements with the same
// Int64Callbacks. Meaning, it should not report measurements with the same
// attributes as another Int64Callbacks also registered for the same
// instrument.
//
// The function needs to be concurrent safe.
type Int64Callback func(context.Context, Int64Observer) error
// Int64ObserverConfig contains options for Observable instruments that
// observe int64 values.
type Int64ObserverConfig struct {
description string
unit string
callbacks []Int64Callback
// Int64ObservableOption applies options to int64 Observer instruments.
type Int64ObservableOption interface {
Int64ObservableCounterOption
Int64ObservableUpDownCounterOption
Int64ObservableGaugeOption
}
// NewInt64ObserverConfig returns a new Int64ObserverConfig with all opts
// applied.
func NewInt64ObserverConfig(opts ...Int64ObserverOption) Int64ObserverConfig {
var config Int64ObserverConfig
for _, o := range opts {
config = o.applyInt64Observer(config)
}
return config
type int64CallbackOpt struct {
cback Int64Callback
}
// Description returns the Config description.
func (c Int64ObserverConfig) Description() string {
return c.description
func (o int64CallbackOpt) applyInt64ObservableCounter(cfg Int64ObservableCounterConfig) Int64ObservableCounterConfig {
cfg.callbacks = append(cfg.callbacks, o.cback)
return cfg
}
// Unit returns the Config unit.
func (c Int64ObserverConfig) Unit() string {
return c.unit
func (o int64CallbackOpt) applyInt64ObservableUpDownCounter(cfg Int64ObservableUpDownCounterConfig) Int64ObservableUpDownCounterConfig {
cfg.callbacks = append(cfg.callbacks, o.cback)
return cfg
}
// Callbacks returns the Config callbacks.
func (c Int64ObserverConfig) Callbacks() []Int64Callback {
return c.callbacks
}
// Int64ObserverOption applies options to int64 Observer instruments.
type Int64ObserverOption interface {
applyInt64Observer(Int64ObserverConfig) Int64ObserverConfig
}
type int64ObserverOptionFunc func(Int64ObserverConfig) Int64ObserverConfig
func (fn int64ObserverOptionFunc) applyInt64Observer(cfg Int64ObserverConfig) Int64ObserverConfig {
return fn(cfg)
func (o int64CallbackOpt) applyInt64ObservableGauge(cfg Int64ObservableGaugeConfig) Int64ObservableGaugeConfig {
cfg.callbacks = append(cfg.callbacks, o.cback)
return cfg
}
// WithInt64Callback adds callback to be called for an instrument.
func WithInt64Callback(callback Int64Callback) Int64ObserverOption {
return int64ObserverOptionFunc(func(cfg Int64ObserverConfig) Int64ObserverConfig {
cfg.callbacks = append(cfg.callbacks, callback)
return cfg
})
func WithInt64Callback(callback Int64Callback) Int64ObservableOption {
return int64CallbackOpt{callback}
}
+49 -18
View File
@@ -24,31 +24,62 @@ import (
"go.opentelemetry.io/otel/attribute"
)
func TestInt64ObserverOptions(t *testing.T) {
func TestInt64ObservableConfiguration(t *testing.T) {
const (
token int64 = 43
desc = "Instrument description."
uBytes = "By"
)
got := NewInt64ObserverConfig(
WithDescription(desc),
WithUnit(uBytes),
WithInt64Callback(func(_ context.Context, obsrv Int64Observer) error {
obsrv.Observe(token)
return nil
}),
)
assert.Equal(t, desc, got.Description(), "description")
assert.Equal(t, uBytes, got.Unit(), "unit")
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")
// Functions are not comparable.
cBacks := got.Callbacks()
require.Len(t, cBacks, 1, "callbacks")
o := &int64Observer{}
err := cBacks[0](context.Background(), o)
require.NoError(t, err)
assert.Equal(t, token, o.got, "callback not set")
// Functions are not comparable.
cBacks := got.Callbacks()
require.Len(t, cBacks, 1, "callbacks")
o := &int64Observer{}
err := cBacks[0](context.Background(), o)
require.NoError(t, err)
assert.Equal(t, token, o.got, "callback not set")
}
}
cback := func(ctx context.Context, obsrv Int64Observer) error {
obsrv.Observe(token)
return nil
}
t.Run("Int64ObservableCounter", run(
NewInt64ObservableCounterConfig(
WithDescription(desc),
WithUnit(uBytes),
WithInt64Callback(cback),
),
))
t.Run("Int64ObservableUpDownCounter", run(
NewInt64ObservableUpDownCounterConfig(
WithDescription(desc),
WithUnit(uBytes),
WithInt64Callback(cback),
),
))
t.Run("Int64ObservableGauge", run(
NewInt64ObservableGaugeConfig(
WithDescription(desc),
WithUnit(uBytes),
WithInt64Callback(cback),
),
))
}
type int64ObservableConfig interface {
Description() string
Unit() string
Callbacks() []Int64Callback
}
type int64Observer struct {
+101 -12
View File
@@ -22,30 +22,79 @@ type Observable interface {
// Option applies options to all instruments.
type Option interface {
Float64ObserverOption
Int64ObserverOption
Float64Option
Int64Option
Int64CounterOption
Int64UpDownCounterOption
Int64HistogramOption
Int64ObservableCounterOption
Int64ObservableUpDownCounterOption
Int64ObservableGaugeOption
Float64CounterOption
Float64UpDownCounterOption
Float64HistogramOption
Float64ObservableCounterOption
Float64ObservableUpDownCounterOption
Float64ObservableGaugeOption
}
type descOpt string
func (o descOpt) applyFloat64(c Float64Config) Float64Config {
func (o descOpt) applyFloat64Counter(c Float64CounterConfig) Float64CounterConfig {
c.description = string(o)
return c
}
func (o descOpt) applyInt64(c Int64Config) Int64Config {
func (o descOpt) applyFloat64UpDownCounter(c Float64UpDownCounterConfig) Float64UpDownCounterConfig {
c.description = string(o)
return c
}
func (o descOpt) applyFloat64Observer(c Float64ObserverConfig) Float64ObserverConfig {
func (o descOpt) applyFloat64Histogram(c Float64HistogramConfig) Float64HistogramConfig {
c.description = string(o)
return c
}
func (o descOpt) applyInt64Observer(c Int64ObserverConfig) Int64ObserverConfig {
func (o descOpt) applyFloat64ObservableCounter(c Float64ObservableCounterConfig) Float64ObservableCounterConfig {
c.description = string(o)
return c
}
func (o descOpt) applyFloat64ObservableUpDownCounter(c Float64ObservableUpDownCounterConfig) Float64ObservableUpDownCounterConfig {
c.description = string(o)
return c
}
func (o descOpt) applyFloat64ObservableGauge(c Float64ObservableGaugeConfig) Float64ObservableGaugeConfig {
c.description = string(o)
return c
}
func (o descOpt) applyInt64Counter(c Int64CounterConfig) Int64CounterConfig {
c.description = string(o)
return c
}
func (o descOpt) applyInt64UpDownCounter(c Int64UpDownCounterConfig) Int64UpDownCounterConfig {
c.description = string(o)
return c
}
func (o descOpt) applyInt64Histogram(c Int64HistogramConfig) Int64HistogramConfig {
c.description = string(o)
return c
}
func (o descOpt) applyInt64ObservableCounter(c Int64ObservableCounterConfig) Int64ObservableCounterConfig {
c.description = string(o)
return c
}
func (o descOpt) applyInt64ObservableUpDownCounter(c Int64ObservableUpDownCounterConfig) Int64ObservableUpDownCounterConfig {
c.description = string(o)
return c
}
func (o descOpt) applyInt64ObservableGauge(c Int64ObservableGaugeConfig) Int64ObservableGaugeConfig {
c.description = string(o)
return c
}
@@ -55,22 +104,62 @@ func WithDescription(desc string) Option { return descOpt(desc) }
type unitOpt string
func (o unitOpt) applyFloat64(c Float64Config) Float64Config {
func (o unitOpt) applyFloat64Counter(c Float64CounterConfig) Float64CounterConfig {
c.unit = string(o)
return c
}
func (o unitOpt) applyInt64(c Int64Config) Int64Config {
func (o unitOpt) applyFloat64UpDownCounter(c Float64UpDownCounterConfig) Float64UpDownCounterConfig {
c.unit = string(o)
return c
}
func (o unitOpt) applyFloat64Observer(c Float64ObserverConfig) Float64ObserverConfig {
func (o unitOpt) applyFloat64Histogram(c Float64HistogramConfig) Float64HistogramConfig {
c.unit = string(o)
return c
}
func (o unitOpt) applyInt64Observer(c Int64ObserverConfig) Int64ObserverConfig {
func (o unitOpt) applyFloat64ObservableCounter(c Float64ObservableCounterConfig) Float64ObservableCounterConfig {
c.unit = string(o)
return c
}
func (o unitOpt) applyFloat64ObservableUpDownCounter(c Float64ObservableUpDownCounterConfig) Float64ObservableUpDownCounterConfig {
c.unit = string(o)
return c
}
func (o unitOpt) applyFloat64ObservableGauge(c Float64ObservableGaugeConfig) Float64ObservableGaugeConfig {
c.unit = string(o)
return c
}
func (o unitOpt) applyInt64Counter(c Int64CounterConfig) Int64CounterConfig {
c.unit = string(o)
return c
}
func (o unitOpt) applyInt64UpDownCounter(c Int64UpDownCounterConfig) Int64UpDownCounterConfig {
c.unit = string(o)
return c
}
func (o unitOpt) applyInt64Histogram(c Int64HistogramConfig) Int64HistogramConfig {
c.unit = string(o)
return c
}
func (o unitOpt) applyInt64ObservableCounter(c Int64ObservableCounterConfig) Int64ObservableCounterConfig {
c.unit = string(o)
return c
}
func (o unitOpt) applyInt64ObservableUpDownCounter(c Int64ObservableUpDownCounterConfig) Int64ObservableUpDownCounterConfig {
c.unit = string(o)
return c
}
func (o unitOpt) applyInt64ObservableGauge(c Int64ObservableGaugeConfig) Int64ObservableGaugeConfig {
c.unit = string(o)
return c
}
+83 -15
View File
@@ -28,6 +28,39 @@ type Float64Counter interface {
Add(ctx context.Context, incr float64, attrs ...attribute.KeyValue)
}
// Float64CounterConfig contains options for synchronous counter instruments that
// record int64 values.
type Float64CounterConfig struct {
description string
unit string
}
// NewFloat64CounterConfig returns a new [Float64CounterConfig] with all opts
// applied.
func NewFloat64CounterConfig(opts ...Float64CounterOption) Float64CounterConfig {
var config Float64CounterConfig
for _, o := range opts {
config = o.applyFloat64Counter(config)
}
return config
}
// Description returns the configured description.
func (c Float64CounterConfig) Description() string {
return c.description
}
// Unit returns the configured unit.
func (c Float64CounterConfig) Unit() string {
return c.unit
}
// Float64CounterOption applies options to a [Float64CounterConfig]. See
// [Option] for other options that can be used as a Float64CounterOption.
type Float64CounterOption interface {
applyFloat64Counter(Float64CounterConfig) Float64CounterConfig
}
// Float64UpDownCounter is an instrument that records increasing or decreasing
// float64 values.
//
@@ -37,6 +70,40 @@ type Float64UpDownCounter interface {
Add(ctx context.Context, incr float64, attrs ...attribute.KeyValue)
}
// Float64UpDownCounterConfig contains options for synchronous counter
// instruments that record int64 values.
type Float64UpDownCounterConfig struct {
description string
unit string
}
// NewFloat64UpDownCounterConfig returns a new [Float64UpDownCounterConfig]
// with all opts applied.
func NewFloat64UpDownCounterConfig(opts ...Float64UpDownCounterOption) Float64UpDownCounterConfig {
var config Float64UpDownCounterConfig
for _, o := range opts {
config = o.applyFloat64UpDownCounter(config)
}
return config
}
// Description returns the configured description.
func (c Float64UpDownCounterConfig) Description() string {
return c.description
}
// Unit returns the configured unit.
func (c Float64UpDownCounterConfig) Unit() string {
return c.unit
}
// Float64UpDownCounterOption applies options to a
// [Float64UpDownCounterConfig]. See [Option] for other options that can be
// used as a Float64UpDownCounterOption.
type Float64UpDownCounterOption interface {
applyFloat64UpDownCounter(Float64UpDownCounterConfig) Float64UpDownCounterConfig
}
// Float64Histogram is an instrument that records a distribution of float64
// values.
//
@@ -46,34 +113,35 @@ type Float64Histogram interface {
Record(ctx context.Context, incr float64, attrs ...attribute.KeyValue)
}
// Float64Config contains options for Observable instruments that
// observe float64 values.
type Float64Config struct {
// Float64HistogramConfig contains options for synchronous counter instruments
// that record int64 values.
type Float64HistogramConfig struct {
description string
unit string
}
// Float64Config contains options for Synchronous instruments that record
// float64 values.
func NewFloat64Config(opts ...Float64Option) Float64Config {
var config Float64Config
// NewFloat64HistogramConfig returns a new [Float64HistogramConfig] with all
// opts applied.
func NewFloat64HistogramConfig(opts ...Float64HistogramOption) Float64HistogramConfig {
var config Float64HistogramConfig
for _, o := range opts {
config = o.applyFloat64(config)
config = o.applyFloat64Histogram(config)
}
return config
}
// Description returns the Config description.
func (c Float64Config) Description() string {
// Description returns the configured description.
func (c Float64HistogramConfig) Description() string {
return c.description
}
// Unit returns the Config unit.
func (c Float64Config) Unit() string {
// Unit returns the configured unit.
func (c Float64HistogramConfig) Unit() string {
return c.unit
}
// Float64Option applies options to synchronous float64 instruments.
type Float64Option interface {
applyFloat64(Float64Config) Float64Config
// Float64HistogramOption applies options to a [Float64HistogramConfig]. See
// [Option] for other options that can be used as a Float64HistogramOption.
type Float64HistogramOption interface {
applyFloat64Histogram(Float64HistogramConfig) Float64HistogramConfig
}
+24 -4
View File
@@ -20,14 +20,34 @@ import (
"github.com/stretchr/testify/assert"
)
func TestFloat64Options(t *testing.T) {
func TestFloat64Configuration(t *testing.T) {
const (
token float64 = 43
desc = "Instrument description."
uBytes = "By"
)
got := NewFloat64Config(WithDescription(desc), WithUnit(uBytes))
assert.Equal(t, desc, got.Description(), "description")
assert.Equal(t, uBytes, got.Unit(), "unit")
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")
}
}
t.Run("Float64Counter", run(
NewFloat64CounterConfig(WithDescription(desc), WithUnit(uBytes)),
))
t.Run("Float64UpDownCounter", run(
NewFloat64UpDownCounterConfig(WithDescription(desc), WithUnit(uBytes)),
))
t.Run("Float64Histogram", run(
NewFloat64HistogramConfig(WithDescription(desc), WithUnit(uBytes)),
))
}
type float64Config interface {
Description() string
Unit() string
}
+82 -14
View File
@@ -28,6 +28,39 @@ type Int64Counter interface {
Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue)
}
// Int64CounterConfig contains options for synchronous counter instruments that
// record int64 values.
type Int64CounterConfig struct {
description string
unit string
}
// NewInt64CounterConfig returns a new [Int64CounterConfig] with all opts
// applied.
func NewInt64CounterConfig(opts ...Int64CounterOption) Int64CounterConfig {
var config Int64CounterConfig
for _, o := range opts {
config = o.applyInt64Counter(config)
}
return config
}
// Description returns the configured description.
func (c Int64CounterConfig) Description() string {
return c.description
}
// Unit returns the configured unit.
func (c Int64CounterConfig) Unit() string {
return c.unit
}
// Int64CounterOption applies options to a [Int64CounterConfig]. See [Option]
// for other options that can be used as an Int64CounterOption.
type Int64CounterOption interface {
applyInt64Counter(Int64CounterConfig) Int64CounterConfig
}
// Int64UpDownCounter is an instrument that records increasing or decreasing
// int64 values.
//
@@ -37,6 +70,40 @@ type Int64UpDownCounter interface {
Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue)
}
// Int64UpDownCounterConfig contains options for synchronous counter
// instruments that record int64 values.
type Int64UpDownCounterConfig struct {
description string
unit string
}
// NewInt64UpDownCounterConfig returns a new [Int64UpDownCounterConfig] with
// all opts applied.
func NewInt64UpDownCounterConfig(opts ...Int64UpDownCounterOption) Int64UpDownCounterConfig {
var config Int64UpDownCounterConfig
for _, o := range opts {
config = o.applyInt64UpDownCounter(config)
}
return config
}
// Description returns the configured description.
func (c Int64UpDownCounterConfig) Description() string {
return c.description
}
// Unit returns the configured unit.
func (c Int64UpDownCounterConfig) Unit() string {
return c.unit
}
// Int64UpDownCounterOption applies options to a [Int64UpDownCounterConfig].
// See [Option] for other options that can be used as an
// Int64UpDownCounterOption.
type Int64UpDownCounterOption interface {
applyInt64UpDownCounter(Int64UpDownCounterConfig) Int64UpDownCounterConfig
}
// Int64Histogram is an instrument that records a distribution of int64
// values.
//
@@ -46,34 +113,35 @@ type Int64Histogram interface {
Record(ctx context.Context, incr int64, attrs ...attribute.KeyValue)
}
// Int64Config contains options for Synchronous instruments that record int64
// values.
type Int64Config struct {
// Int64HistogramConfig contains options for synchronous counter instruments
// that record int64 values.
type Int64HistogramConfig struct {
description string
unit string
}
// NewInt64Config returns a new Int64Config with all opts
// NewInt64HistogramConfig returns a new [Int64HistogramConfig] with all opts
// applied.
func NewInt64Config(opts ...Int64Option) Int64Config {
var config Int64Config
func NewInt64HistogramConfig(opts ...Int64HistogramOption) Int64HistogramConfig {
var config Int64HistogramConfig
for _, o := range opts {
config = o.applyInt64(config)
config = o.applyInt64Histogram(config)
}
return config
}
// Description returns the Config description.
func (c Int64Config) Description() string {
// Description returns the configured description.
func (c Int64HistogramConfig) Description() string {
return c.description
}
// Unit returns the Config unit.
func (c Int64Config) Unit() string {
// Unit returns the configured unit.
func (c Int64HistogramConfig) Unit() string {
return c.unit
}
// Int64Option applies options to synchronous int64 instruments.
type Int64Option interface {
applyInt64(Int64Config) Int64Config
// Int64HistogramOption applies options to a [Int64HistogramConfig]. See
// [Option] for other options that can be used as an Int64HistogramOption.
type Int64HistogramOption interface {
applyInt64Histogram(Int64HistogramConfig) Int64HistogramConfig
}
+24 -4
View File
@@ -20,14 +20,34 @@ import (
"github.com/stretchr/testify/assert"
)
func TestInt64Options(t *testing.T) {
func TestInt64Configuration(t *testing.T) {
const (
token int64 = 43
desc = "Instrument description."
uBytes = "By"
)
got := NewInt64Config(WithDescription(desc), WithUnit(uBytes))
assert.Equal(t, desc, got.Description(), "description")
assert.Equal(t, uBytes, got.Unit(), "unit")
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")
}
}
t.Run("Int64Counter", run(
NewInt64CounterConfig(WithDescription(desc), WithUnit(uBytes)),
))
t.Run("Int64UpDownCounter", run(
NewInt64UpDownCounterConfig(WithDescription(desc), WithUnit(uBytes)),
))
t.Run("Int64Histogram", run(
NewInt64HistogramConfig(WithDescription(desc), WithUnit(uBytes)),
))
}
type int64Config interface {
Description() string
Unit() string
}
+12 -12
View File
@@ -45,56 +45,56 @@ type Meter interface {
// Int64Counter returns a new instrument identified by name and configured
// with options. The instrument is used to synchronously record increasing
// int64 measurements during a computational operation.
Int64Counter(name string, options ...instrument.Int64Option) (instrument.Int64Counter, error)
Int64Counter(name string, options ...instrument.Int64CounterOption) (instrument.Int64Counter, error)
// Int64UpDownCounter returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// int64 measurements during a computational operation.
Int64UpDownCounter(name string, options ...instrument.Int64Option) (instrument.Int64UpDownCounter, error)
Int64UpDownCounter(name string, options ...instrument.Int64UpDownCounterOption) (instrument.Int64UpDownCounter, error)
// Int64Histogram returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// the distribution of int64 measurements during a computational operation.
Int64Histogram(name string, options ...instrument.Int64Option) (instrument.Int64Histogram, error)
Int64Histogram(name string, options ...instrument.Int64HistogramOption) (instrument.Int64Histogram, error)
// Int64ObservableCounter returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// increasing int64 measurements once per a measurement collection cycle.
Int64ObservableCounter(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableCounter, error)
Int64ObservableCounter(name string, options ...instrument.Int64ObservableCounterOption) (instrument.Int64ObservableCounter, error)
// Int64ObservableUpDownCounter returns a new instrument identified by name
// and configured with options. The instrument is used to asynchronously
// record int64 measurements once per a measurement collection cycle.
Int64ObservableUpDownCounter(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableUpDownCounter, error)
Int64ObservableUpDownCounter(name string, options ...instrument.Int64ObservableUpDownCounterOption) (instrument.Int64ObservableUpDownCounter, error)
// Int64ObservableGauge returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// instantaneous int64 measurements once per a measurement collection
// cycle.
Int64ObservableGauge(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableGauge, error)
Int64ObservableGauge(name string, options ...instrument.Int64ObservableGaugeOption) (instrument.Int64ObservableGauge, error)
// Float64Counter returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// increasing float64 measurements during a computational operation.
Float64Counter(name string, options ...instrument.Float64Option) (instrument.Float64Counter, error)
Float64Counter(name string, options ...instrument.Float64CounterOption) (instrument.Float64Counter, error)
// Float64UpDownCounter returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// float64 measurements during a computational operation.
Float64UpDownCounter(name string, options ...instrument.Float64Option) (instrument.Float64UpDownCounter, error)
Float64UpDownCounter(name string, options ...instrument.Float64UpDownCounterOption) (instrument.Float64UpDownCounter, error)
// Float64Histogram returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// the distribution of float64 measurements during a computational
// operation.
Float64Histogram(name string, options ...instrument.Float64Option) (instrument.Float64Histogram, error)
Float64Histogram(name string, options ...instrument.Float64HistogramOption) (instrument.Float64Histogram, error)
// Float64ObservableCounter returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// increasing float64 measurements once per a measurement collection cycle.
Float64ObservableCounter(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableCounter, error)
Float64ObservableCounter(name string, options ...instrument.Float64ObservableCounterOption) (instrument.Float64ObservableCounter, error)
// Float64ObservableUpDownCounter returns a new instrument identified by
// name and configured with options. The instrument is used to
// asynchronously record float64 measurements once per a measurement
// collection cycle.
Float64ObservableUpDownCounter(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableUpDownCounter, error)
Float64ObservableUpDownCounter(name string, options ...instrument.Float64ObservableUpDownCounterOption) (instrument.Float64ObservableUpDownCounter, error)
// Float64ObservableGauge returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// instantaneous float64 measurements once per a measurement collection
// cycle.
Float64ObservableGauge(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableGauge, error)
Float64ObservableGauge(name string, options ...instrument.Float64ObservableGaugeOption) (instrument.Float64ObservableGauge, error)
// RegisterCallback registers f to be called during the collection of a
// measurement cycle.
+12 -12
View File
@@ -39,51 +39,51 @@ func NewNoopMeter() Meter {
type noopMeter struct{}
func (noopMeter) Int64Counter(string, ...instrument.Int64Option) (instrument.Int64Counter, error) {
func (noopMeter) Int64Counter(string, ...instrument.Int64CounterOption) (instrument.Int64Counter, error) {
return nonrecordingSyncInt64Instrument{}, nil
}
func (noopMeter) Int64UpDownCounter(string, ...instrument.Int64Option) (instrument.Int64UpDownCounter, error) {
func (noopMeter) Int64UpDownCounter(string, ...instrument.Int64UpDownCounterOption) (instrument.Int64UpDownCounter, error) {
return nonrecordingSyncInt64Instrument{}, nil
}
func (noopMeter) Int64Histogram(string, ...instrument.Int64Option) (instrument.Int64Histogram, error) {
func (noopMeter) Int64Histogram(string, ...instrument.Int64HistogramOption) (instrument.Int64Histogram, error) {
return nonrecordingSyncInt64Instrument{}, nil
}
func (noopMeter) Int64ObservableCounter(string, ...instrument.Int64ObserverOption) (instrument.Int64ObservableCounter, error) {
func (noopMeter) Int64ObservableCounter(string, ...instrument.Int64ObservableCounterOption) (instrument.Int64ObservableCounter, error) {
return nonrecordingAsyncInt64Instrument{}, nil
}
func (noopMeter) Int64ObservableUpDownCounter(string, ...instrument.Int64ObserverOption) (instrument.Int64ObservableUpDownCounter, error) {
func (noopMeter) Int64ObservableUpDownCounter(string, ...instrument.Int64ObservableUpDownCounterOption) (instrument.Int64ObservableUpDownCounter, error) {
return nonrecordingAsyncInt64Instrument{}, nil
}
func (noopMeter) Int64ObservableGauge(string, ...instrument.Int64ObserverOption) (instrument.Int64ObservableGauge, error) {
func (noopMeter) Int64ObservableGauge(string, ...instrument.Int64ObservableGaugeOption) (instrument.Int64ObservableGauge, error) {
return nonrecordingAsyncInt64Instrument{}, nil
}
func (noopMeter) Float64Counter(string, ...instrument.Float64Option) (instrument.Float64Counter, error) {
func (noopMeter) Float64Counter(string, ...instrument.Float64CounterOption) (instrument.Float64Counter, error) {
return nonrecordingSyncFloat64Instrument{}, nil
}
func (noopMeter) Float64UpDownCounter(string, ...instrument.Float64Option) (instrument.Float64UpDownCounter, error) {
func (noopMeter) Float64UpDownCounter(string, ...instrument.Float64UpDownCounterOption) (instrument.Float64UpDownCounter, error) {
return nonrecordingSyncFloat64Instrument{}, nil
}
func (noopMeter) Float64Histogram(string, ...instrument.Float64Option) (instrument.Float64Histogram, error) {
func (noopMeter) Float64Histogram(string, ...instrument.Float64HistogramOption) (instrument.Float64Histogram, error) {
return nonrecordingSyncFloat64Instrument{}, nil
}
func (noopMeter) Float64ObservableCounter(string, ...instrument.Float64ObserverOption) (instrument.Float64ObservableCounter, error) {
func (noopMeter) Float64ObservableCounter(string, ...instrument.Float64ObservableCounterOption) (instrument.Float64ObservableCounter, error) {
return nonrecordingAsyncFloat64Instrument{}, nil
}
func (noopMeter) Float64ObservableUpDownCounter(string, ...instrument.Float64ObserverOption) (instrument.Float64ObservableUpDownCounter, error) {
func (noopMeter) Float64ObservableUpDownCounter(string, ...instrument.Float64ObservableUpDownCounterOption) (instrument.Float64ObservableUpDownCounter, error) {
return nonrecordingAsyncFloat64Instrument{}, nil
}
func (noopMeter) Float64ObservableGauge(string, ...instrument.Float64ObserverOption) (instrument.Float64ObservableGauge, error) {
func (noopMeter) Float64ObservableGauge(string, ...instrument.Float64ObservableGaugeOption) (instrument.Float64ObservableGauge, error) {
return nonrecordingAsyncFloat64Instrument{}, nil
}
@@ -30,7 +30,7 @@ type meter struct {
aggregations []metricdata.Aggregation
}
func (p *meter) Int64Counter(string, ...instrument.Int64Option) (instrument.Int64Counter, error) {
func (p *meter) Int64Counter(string, ...instrument.Int64CounterOption) (instrument.Int64Counter, error) {
// This is an example of how a meter would create an aggregator for a new
// counter. At this point the provider would determine the aggregation and
// temporality to used based on the Reader and View configuration. Assume
@@ -46,7 +46,7 @@ func (p *meter) Int64Counter(string, ...instrument.Int64Option) (instrument.Int6
return count, nil
}
func (p *meter) Int64UpDownCounter(string, ...instrument.Int64Option) (instrument.Int64UpDownCounter, error) {
func (p *meter) Int64UpDownCounter(string, ...instrument.Int64UpDownCounterOption) (instrument.Int64UpDownCounter, error) {
// This is an example of how a meter would create an aggregator for a new
// up-down counter. At this point the provider would determine the
// aggregation and temporality to used based on the Reader and View
@@ -63,7 +63,7 @@ func (p *meter) Int64UpDownCounter(string, ...instrument.Int64Option) (instrumen
return upDownCount, nil
}
func (p *meter) Int64Histogram(string, ...instrument.Int64Option) (instrument.Int64Histogram, error) {
func (p *meter) Int64Histogram(string, ...instrument.Int64HistogramOption) (instrument.Int64Histogram, error) {
// This is an example of how a meter would create an aggregator for a new
// histogram. At this point the provider would determine the aggregation
// and temporality to used based on the Reader and View configuration.
+24 -24
View File
@@ -58,8 +58,8 @@ var _ metric.Meter = (*meter)(nil)
// Int64Counter returns a new instrument identified by name and configured with
// options. The instrument is used to synchronously record increasing int64
// measurements during a computational operation.
func (m *meter) Int64Counter(name string, options ...instrument.Int64Option) (instrument.Int64Counter, error) {
cfg := instrument.NewInt64Config(options...)
func (m *meter) Int64Counter(name string, options ...instrument.Int64CounterOption) (instrument.Int64Counter, error) {
cfg := instrument.NewInt64CounterConfig(options...)
const kind = InstrumentKindCounter
return m.int64IP.lookup(kind, name, cfg.Description(), cfg.Unit())
}
@@ -67,8 +67,8 @@ func (m *meter) Int64Counter(name string, options ...instrument.Int64Option) (in
// Int64UpDownCounter returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// int64 measurements during a computational operation.
func (m *meter) Int64UpDownCounter(name string, options ...instrument.Int64Option) (instrument.Int64UpDownCounter, error) {
cfg := instrument.NewInt64Config(options...)
func (m *meter) Int64UpDownCounter(name string, options ...instrument.Int64UpDownCounterOption) (instrument.Int64UpDownCounter, error) {
cfg := instrument.NewInt64UpDownCounterConfig(options...)
const kind = InstrumentKindUpDownCounter
return m.int64IP.lookup(kind, name, cfg.Description(), cfg.Unit())
}
@@ -76,8 +76,8 @@ func (m *meter) Int64UpDownCounter(name string, options ...instrument.Int64Optio
// Int64Histogram returns a new instrument identified by name and configured
// with options. The instrument is used to synchronously record the
// distribution of int64 measurements during a computational operation.
func (m *meter) Int64Histogram(name string, options ...instrument.Int64Option) (instrument.Int64Histogram, error) {
cfg := instrument.NewInt64Config(options...)
func (m *meter) Int64Histogram(name string, options ...instrument.Int64HistogramOption) (instrument.Int64Histogram, error) {
cfg := instrument.NewInt64HistogramConfig(options...)
const kind = InstrumentKindHistogram
return m.int64IP.lookup(kind, name, cfg.Description(), cfg.Unit())
}
@@ -85,8 +85,8 @@ func (m *meter) Int64Histogram(name string, options ...instrument.Int64Option) (
// Int64ObservableCounter returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// increasing int64 measurements once per a measurement collection cycle.
func (m *meter) Int64ObservableCounter(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableCounter, error) {
cfg := instrument.NewInt64ObserverConfig(options...)
func (m *meter) Int64ObservableCounter(name string, options ...instrument.Int64ObservableCounterOption) (instrument.Int64ObservableCounter, error) {
cfg := instrument.NewInt64ObservableCounterConfig(options...)
const kind = InstrumentKindObservableCounter
p := int64ObservProvider{m.int64IP}
inst, err := p.lookup(kind, name, cfg.Description(), cfg.Unit())
@@ -100,8 +100,8 @@ func (m *meter) Int64ObservableCounter(name string, options ...instrument.Int64O
// Int64ObservableUpDownCounter returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// int64 measurements once per a measurement collection cycle.
func (m *meter) Int64ObservableUpDownCounter(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableUpDownCounter, error) {
cfg := instrument.NewInt64ObserverConfig(options...)
func (m *meter) Int64ObservableUpDownCounter(name string, options ...instrument.Int64ObservableUpDownCounterOption) (instrument.Int64ObservableUpDownCounter, error) {
cfg := instrument.NewInt64ObservableUpDownCounterConfig(options...)
const kind = InstrumentKindObservableUpDownCounter
p := int64ObservProvider{m.int64IP}
inst, err := p.lookup(kind, name, cfg.Description(), cfg.Unit())
@@ -115,8 +115,8 @@ func (m *meter) Int64ObservableUpDownCounter(name string, options ...instrument.
// Int64ObservableGauge returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// instantaneous int64 measurements once per a measurement collection cycle.
func (m *meter) Int64ObservableGauge(name string, options ...instrument.Int64ObserverOption) (instrument.Int64ObservableGauge, error) {
cfg := instrument.NewInt64ObserverConfig(options...)
func (m *meter) Int64ObservableGauge(name string, options ...instrument.Int64ObservableGaugeOption) (instrument.Int64ObservableGauge, error) {
cfg := instrument.NewInt64ObservableGaugeConfig(options...)
const kind = InstrumentKindObservableGauge
p := int64ObservProvider{m.int64IP}
inst, err := p.lookup(kind, name, cfg.Description(), cfg.Unit())
@@ -130,8 +130,8 @@ func (m *meter) Int64ObservableGauge(name string, options ...instrument.Int64Obs
// Float64Counter returns a new instrument identified by name and configured
// with options. The instrument is used to synchronously record increasing
// float64 measurements during a computational operation.
func (m *meter) Float64Counter(name string, options ...instrument.Float64Option) (instrument.Float64Counter, error) {
cfg := instrument.NewFloat64Config(options...)
func (m *meter) Float64Counter(name string, options ...instrument.Float64CounterOption) (instrument.Float64Counter, error) {
cfg := instrument.NewFloat64CounterConfig(options...)
const kind = InstrumentKindCounter
return m.float64IP.lookup(kind, name, cfg.Description(), cfg.Unit())
}
@@ -139,8 +139,8 @@ func (m *meter) Float64Counter(name string, options ...instrument.Float64Option)
// Float64UpDownCounter returns a new instrument identified by name and
// configured with options. The instrument is used to synchronously record
// float64 measurements during a computational operation.
func (m *meter) Float64UpDownCounter(name string, options ...instrument.Float64Option) (instrument.Float64UpDownCounter, error) {
cfg := instrument.NewFloat64Config(options...)
func (m *meter) Float64UpDownCounter(name string, options ...instrument.Float64UpDownCounterOption) (instrument.Float64UpDownCounter, error) {
cfg := instrument.NewFloat64UpDownCounterConfig(options...)
const kind = InstrumentKindUpDownCounter
return m.float64IP.lookup(kind, name, cfg.Description(), cfg.Unit())
}
@@ -148,8 +148,8 @@ func (m *meter) Float64UpDownCounter(name string, options ...instrument.Float64O
// Float64Histogram returns a new instrument identified by name and configured
// with options. The instrument is used to synchronously record the
// distribution of float64 measurements during a computational operation.
func (m *meter) Float64Histogram(name string, options ...instrument.Float64Option) (instrument.Float64Histogram, error) {
cfg := instrument.NewFloat64Config(options...)
func (m *meter) Float64Histogram(name string, options ...instrument.Float64HistogramOption) (instrument.Float64Histogram, error) {
cfg := instrument.NewFloat64HistogramConfig(options...)
const kind = InstrumentKindHistogram
return m.float64IP.lookup(kind, name, cfg.Description(), cfg.Unit())
}
@@ -157,8 +157,8 @@ func (m *meter) Float64Histogram(name string, options ...instrument.Float64Optio
// Float64ObservableCounter returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// increasing float64 measurements once per a measurement collection cycle.
func (m *meter) Float64ObservableCounter(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableCounter, error) {
cfg := instrument.NewFloat64ObserverConfig(options...)
func (m *meter) Float64ObservableCounter(name string, options ...instrument.Float64ObservableCounterOption) (instrument.Float64ObservableCounter, error) {
cfg := instrument.NewFloat64ObservableCounterConfig(options...)
const kind = InstrumentKindObservableCounter
p := float64ObservProvider{m.float64IP}
inst, err := p.lookup(kind, name, cfg.Description(), cfg.Unit())
@@ -172,8 +172,8 @@ func (m *meter) Float64ObservableCounter(name string, options ...instrument.Floa
// Float64ObservableUpDownCounter returns a new instrument identified by name
// and configured with options. The instrument is used to asynchronously record
// float64 measurements once per a measurement collection cycle.
func (m *meter) Float64ObservableUpDownCounter(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableUpDownCounter, error) {
cfg := instrument.NewFloat64ObserverConfig(options...)
func (m *meter) Float64ObservableUpDownCounter(name string, options ...instrument.Float64ObservableUpDownCounterOption) (instrument.Float64ObservableUpDownCounter, error) {
cfg := instrument.NewFloat64ObservableUpDownCounterConfig(options...)
const kind = InstrumentKindObservableUpDownCounter
p := float64ObservProvider{m.float64IP}
inst, err := p.lookup(kind, name, cfg.Description(), cfg.Unit())
@@ -187,8 +187,8 @@ func (m *meter) Float64ObservableUpDownCounter(name string, options ...instrumen
// Float64ObservableGauge returns a new instrument identified by name and
// configured with options. The instrument is used to asynchronously record
// instantaneous float64 measurements once per a measurement collection cycle.
func (m *meter) Float64ObservableGauge(name string, options ...instrument.Float64ObserverOption) (instrument.Float64ObservableGauge, error) {
cfg := instrument.NewFloat64ObserverConfig(options...)
func (m *meter) Float64ObservableGauge(name string, options ...instrument.Float64ObservableGaugeOption) (instrument.Float64ObservableGauge, error) {
cfg := instrument.NewFloat64ObservableGaugeConfig(options...)
const kind = InstrumentKindObservableGauge
p := float64ObservProvider{m.float64IP}
inst, err := p.lookup(kind, name, cfg.Description(), cfg.Unit())