diff --git a/CHANGELOG.md b/CHANGELOG.md index e444b1fa1..ac597c109 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,12 +14,28 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm This `Registration` can be used to unregister callbacks. (#3522) - Add `Producer` interface and `Reader.RegisterProducer(Producer)` to `go.opentelemetry.io/otel/sdk/metric` to enable external metric Producers. (#3524) -### Removed - -- The deprecated `go.opentelemetry.io/otel/sdk/metric/view` package is removed. (#3520) - ### Changed +- The `InstrumentProvider` from `go.opentelemetry.io/otel/sdk/metric/asyncint64` is removed. + Use the new creation methods of the `Meter` in `go.opentelemetry.io/otel/sdk/metric` instead. (#3530) + - The `Counter` method is replaced by `Meter.Int64ObservableCounter` + - The `UpDownCounter` method is replaced by `Meter.Int64ObservableUpDownCounter` + - The `Gauge` method is replaced by `Meter.Int64ObservableGauge` +- The `InstrumentProvider` from `go.opentelemetry.io/otel/sdk/metric/asyncfloat64` is removed. + Use the new creation methods of the `Meter` in `go.opentelemetry.io/otel/sdk/metric` instead. (#3530) + - The `Counter` method is replaced by `Meter.Float64ObservableCounter` + - The `UpDownCounter` method is replaced by `Meter.Float64ObservableUpDownCounter` + - The `Gauge` method is replaced by `Meter.Float64ObservableGauge` +- The `InstrumentProvider` from `go.opentelemetry.io/otel/sdk/metric/syncint64` is removed. + Use the new creation methods of the `Meter` in `go.opentelemetry.io/otel/sdk/metric` instead. (#3530) + - The `Counter` method is replaced by `Meter.Int64Counter` + - The `UpDownCounter` method is replaced by `Meter.Int64UpDownCounter` + - The `Histogram` method is replaced by `Meter.Int64Histogram` +- The `InstrumentProvider` from `go.opentelemetry.io/otel/sdk/metric/syncfloat64` is removed. + Use the new creation methods of the `Meter` in `go.opentelemetry.io/otel/sdk/metric` instead. (#3530) + - The `Counter` method is replaced by `Meter.Float64Counter` + - The `UpDownCounter` method is replaced by `Meter.Float64UpDownCounter` + - The `Histogram` method is replaced by `Meter.Float64Histogram` - Global error handler uses an atomic value instead of a mutex. (#3543) - Add `Producer` interface and `Reader.RegisterProducer(Producer)` to `go.opentelemetry.io/otel/sdk/metric` to enable external metric Producers. (#3524) - Add `NewMetricProducer` to `go.opentelemetry.io/otel/bridge/opencensus`, which can be used to pass OpenCensus metrics to an OpenTelemetry Reader. (#3541) @@ -33,6 +49,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The `NewMetricExporter` in `go.opentelemetry.io/otel/bridge/opencensus` is deprecated. Use `NewMetricProducer` instead. (#3541) +### Removed + +- The deprecated `go.opentelemetry.io/otel/sdk/metric/view` package is removed. (#3520) + ## [1.11.2/0.34.0] 2022-12-05 ### Added diff --git a/example/prometheus/main.go b/example/prometheus/main.go index 390159945..6bc9563d7 100644 --- a/example/prometheus/main.go +++ b/example/prometheus/main.go @@ -58,13 +58,13 @@ func main() { } // This is the equivalent of prometheus.NewCounterVec - counter, err := meter.SyncFloat64().Counter("foo", instrument.WithDescription("a simple counter")) + counter, err := meter.Float64Counter("foo", instrument.WithDescription("a simple counter")) if err != nil { log.Fatal(err) } counter.Add(ctx, 5, attrs...) - gauge, err := meter.AsyncFloat64().Gauge("bar", instrument.WithDescription("a fun little gauge")) + gauge, err := meter.Float64ObservableGauge("bar", instrument.WithDescription("a fun little gauge")) if err != nil { log.Fatal(err) } @@ -77,7 +77,7 @@ func main() { } // This is the equivalent of prometheus.NewHistogramVec - histogram, err := meter.SyncFloat64().Histogram("baz", instrument.WithDescription("a very nice histogram")) + histogram, err := meter.Float64Histogram("baz", instrument.WithDescription("a very nice histogram")) if err != nil { log.Fatal(err) } diff --git a/example/view/main.go b/example/view/main.go index cdced744a..b609e4873 100644 --- a/example/view/main.go +++ b/example/view/main.go @@ -69,13 +69,13 @@ func main() { attribute.Key("C").String("D"), } - counter, err := meter.SyncFloat64().Counter("foo", instrument.WithDescription("a simple counter")) + counter, err := meter.Float64Counter("foo", instrument.WithDescription("a simple counter")) if err != nil { log.Fatal(err) } counter.Add(ctx, 5, attrs...) - histogram, err := meter.SyncFloat64().Histogram("custom_histogram", instrument.WithDescription("a histogram with custom buckets and rename")) + histogram, err := meter.Float64Histogram("custom_histogram", instrument.WithDescription("a histogram with custom buckets and rename")) if err != nil { log.Fatal(err) } diff --git a/exporters/prometheus/benchmark_test.go b/exporters/prometheus/benchmark_test.go index 6c6d67cae..1d7139b5c 100644 --- a/exporters/prometheus/benchmark_test.go +++ b/exporters/prometheus/benchmark_test.go @@ -34,7 +34,7 @@ func benchmarkCollect(b *testing.B, n int) { meter := provider.Meter("testmeter") for i := 0; i < n; i++ { - counter, err := meter.SyncFloat64().Counter(fmt.Sprintf("foo_%d", i)) + counter, err := meter.Float64Counter(fmt.Sprintf("foo_%d", i)) require.NoError(b, err) counter.Add(ctx, float64(i)) } diff --git a/exporters/prometheus/exporter_test.go b/exporters/prometheus/exporter_test.go index 88027fe7f..be1cceb6c 100644 --- a/exporters/prometheus/exporter_test.go +++ b/exporters/prometheus/exporter_test.go @@ -53,7 +53,7 @@ func TestPrometheusExporter(t *testing.T) { attribute.Key("E").Bool(true), attribute.Key("F").Int(42), } - counter, err := meter.SyncFloat64().Counter( + counter, err := meter.Float64Counter( "foo", instrument.WithDescription("a simple counter"), instrument.WithUnit(unit.Milliseconds), @@ -80,7 +80,7 @@ func TestPrometheusExporter(t *testing.T) { attribute.Key("A").String("B"), attribute.Key("C").String("D"), } - gauge, err := meter.SyncFloat64().UpDownCounter( + gauge, err := meter.Float64UpDownCounter( "bar", instrument.WithDescription("a fun little gauge"), instrument.WithUnit(unit.Dimensionless), @@ -98,7 +98,7 @@ func TestPrometheusExporter(t *testing.T) { attribute.Key("A").String("B"), attribute.Key("C").String("D"), } - histogram, err := meter.SyncFloat64().Histogram( + histogram, err := meter.Float64Histogram( "histogram_baz", instrument.WithDescription("a very nice histogram"), instrument.WithUnit(unit.Bytes), @@ -124,7 +124,7 @@ func TestPrometheusExporter(t *testing.T) { attribute.Key("C.D").String("Y"), attribute.Key("C/D").String("Z"), } - counter, err := meter.SyncFloat64().Counter( + counter, err := meter.Float64Counter( "foo", instrument.WithDescription("a sanitary counter"), // This unit is not added to @@ -145,21 +145,21 @@ func TestPrometheusExporter(t *testing.T) { attribute.Key("C").String("D"), } // Valid. - gauge, err := meter.SyncFloat64().UpDownCounter("bar", instrument.WithDescription("a fun little gauge")) + gauge, err := meter.Float64UpDownCounter("bar", instrument.WithDescription("a fun little gauge")) require.NoError(t, err) gauge.Add(ctx, 100, attrs...) gauge.Add(ctx, -25, attrs...) // Invalid, will be renamed. - gauge, err = meter.SyncFloat64().UpDownCounter("invalid.gauge.name", instrument.WithDescription("a gauge with an invalid name")) + gauge, err = meter.Float64UpDownCounter("invalid.gauge.name", instrument.WithDescription("a gauge with an invalid name")) require.NoError(t, err) gauge.Add(ctx, 100, attrs...) - counter, err := meter.SyncFloat64().Counter("0invalid.counter.name", instrument.WithDescription("a counter with an invalid name")) + counter, err := meter.Float64Counter("0invalid.counter.name", instrument.WithDescription("a counter with an invalid name")) require.NoError(t, err) counter.Add(ctx, 100, attrs...) - histogram, err := meter.SyncFloat64().Histogram("invalid.hist.name", instrument.WithDescription("a histogram with an invalid name")) + histogram, err := meter.Float64Histogram("invalid.hist.name", instrument.WithDescription("a histogram with an invalid name")) require.NoError(t, err) histogram.Record(ctx, 23, attrs...) }, @@ -175,7 +175,7 @@ func TestPrometheusExporter(t *testing.T) { attribute.Key("E").Bool(true), attribute.Key("F").Int(42), } - counter, err := meter.SyncFloat64().Counter("foo", instrument.WithDescription("a simple counter")) + counter, err := meter.Float64Counter("foo", instrument.WithDescription("a simple counter")) require.NoError(t, err) counter.Add(ctx, 5, attrs...) counter.Add(ctx, 10.3, attrs...) @@ -196,7 +196,7 @@ func TestPrometheusExporter(t *testing.T) { attribute.Key("E").Bool(true), attribute.Key("F").Int(42), } - counter, err := meter.SyncFloat64().Counter("foo", instrument.WithDescription("a simple counter")) + counter, err := meter.Float64Counter("foo", instrument.WithDescription("a simple counter")) require.NoError(t, err) counter.Add(ctx, 5, attrs...) counter.Add(ctx, 10.3, attrs...) @@ -214,7 +214,7 @@ func TestPrometheusExporter(t *testing.T) { attribute.Key("E").Bool(true), attribute.Key("F").Int(42), } - counter, err := meter.SyncFloat64().Counter("foo", instrument.WithDescription("a simple counter")) + counter, err := meter.Float64Counter("foo", instrument.WithDescription("a simple counter")) require.NoError(t, err) counter.Add(ctx, 5, attrs...) counter.Add(ctx, 10.3, attrs...) @@ -230,7 +230,7 @@ func TestPrometheusExporter(t *testing.T) { attribute.Key("A").String("B"), attribute.Key("C").String("D"), } - gauge, err := meter.SyncInt64().UpDownCounter( + gauge, err := meter.Int64UpDownCounter( "bar", instrument.WithDescription("a fun little gauge"), instrument.WithUnit(unit.Dimensionless), @@ -249,7 +249,7 @@ func TestPrometheusExporter(t *testing.T) { attribute.Key("A").String("B"), attribute.Key("C").String("D"), } - counter, err := meter.SyncInt64().Counter( + counter, err := meter.Int64Counter( "bar", instrument.WithDescription("a fun little counter"), instrument.WithUnit(unit.Bytes), @@ -364,18 +364,18 @@ func TestMultiScopes(t *testing.T) { ) fooCounter, err := provider.Meter("meterfoo", otelmetric.WithInstrumentationVersion("v0.1.0")). - SyncInt64().Counter( - "foo", - instrument.WithUnit(unit.Milliseconds), - instrument.WithDescription("meter foo counter")) + Int64Counter( + "foo", + instrument.WithUnit(unit.Milliseconds), + instrument.WithDescription("meter foo counter")) assert.NoError(t, err) fooCounter.Add(ctx, 100, attribute.String("type", "foo")) barCounter, err := provider.Meter("meterbar", otelmetric.WithInstrumentationVersion("v0.1.0")). - SyncInt64().Counter( - "bar", - instrument.WithUnit(unit.Milliseconds), - instrument.WithDescription("meter bar counter")) + Int64Counter( + "bar", + instrument.WithUnit(unit.Milliseconds), + instrument.WithDescription("meter bar counter")) assert.NoError(t, err) barCounter.Add(ctx, 200, attribute.String("type", "bar")) @@ -398,13 +398,13 @@ func TestDuplicateMetrics(t *testing.T) { { name: "no_conflict_two_counters", recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { - fooA, err := meterA.SyncInt64().Counter("foo", + fooA, err := meterA.Int64Counter("foo", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter counter foo")) assert.NoError(t, err) fooA.Add(ctx, 100, attribute.String("A", "B")) - fooB, err := meterB.SyncInt64().Counter("foo", + fooB, err := meterB.Int64Counter("foo", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter counter foo")) assert.NoError(t, err) @@ -415,13 +415,13 @@ func TestDuplicateMetrics(t *testing.T) { { name: "no_conflict_two_updowncounters", recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { - fooA, err := meterA.SyncInt64().UpDownCounter("foo", + fooA, err := meterA.Int64UpDownCounter("foo", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter gauge foo")) assert.NoError(t, err) fooA.Add(ctx, 100, attribute.String("A", "B")) - fooB, err := meterB.SyncInt64().UpDownCounter("foo", + fooB, err := meterB.Int64UpDownCounter("foo", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter gauge foo")) assert.NoError(t, err) @@ -432,13 +432,13 @@ func TestDuplicateMetrics(t *testing.T) { { name: "no_conflict_two_histograms", recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { - fooA, err := meterA.SyncInt64().Histogram("foo", + fooA, err := meterA.Int64Histogram("foo", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter histogram foo")) assert.NoError(t, err) fooA.Record(ctx, 100, attribute.String("A", "B")) - fooB, err := meterB.SyncInt64().Histogram("foo", + fooB, err := meterB.Int64Histogram("foo", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter histogram foo")) assert.NoError(t, err) @@ -449,13 +449,13 @@ func TestDuplicateMetrics(t *testing.T) { { name: "conflict_help_two_counters", recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { - barA, err := meterA.SyncInt64().Counter("bar", + barA, err := meterA.Int64Counter("bar", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter a bar")) assert.NoError(t, err) barA.Add(ctx, 100, attribute.String("type", "bar")) - barB, err := meterB.SyncInt64().Counter("bar", + barB, err := meterB.Int64Counter("bar", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter b bar")) assert.NoError(t, err) @@ -469,13 +469,13 @@ func TestDuplicateMetrics(t *testing.T) { { name: "conflict_help_two_updowncounters", recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { - barA, err := meterA.SyncInt64().UpDownCounter("bar", + barA, err := meterA.Int64UpDownCounter("bar", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter a bar")) assert.NoError(t, err) barA.Add(ctx, 100, attribute.String("type", "bar")) - barB, err := meterB.SyncInt64().UpDownCounter("bar", + barB, err := meterB.Int64UpDownCounter("bar", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter b bar")) assert.NoError(t, err) @@ -489,13 +489,13 @@ func TestDuplicateMetrics(t *testing.T) { { name: "conflict_help_two_histograms", recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { - barA, err := meterA.SyncInt64().Histogram("bar", + barA, err := meterA.Int64Histogram("bar", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter a bar")) assert.NoError(t, err) barA.Record(ctx, 100, attribute.String("A", "B")) - barB, err := meterB.SyncInt64().Histogram("bar", + barB, err := meterB.Int64Histogram("bar", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter b bar")) assert.NoError(t, err) @@ -509,13 +509,13 @@ func TestDuplicateMetrics(t *testing.T) { { name: "conflict_unit_two_counters", recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { - bazA, err := meterA.SyncInt64().Counter("bar", + bazA, err := meterA.Int64Counter("bar", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter bar")) assert.NoError(t, err) bazA.Add(ctx, 100, attribute.String("type", "bar")) - bazB, err := meterB.SyncInt64().Counter("bar", + bazB, err := meterB.Int64Counter("bar", instrument.WithUnit(unit.Milliseconds), instrument.WithDescription("meter bar")) assert.NoError(t, err) @@ -527,13 +527,13 @@ func TestDuplicateMetrics(t *testing.T) { { name: "conflict_unit_two_updowncounters", recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { - barA, err := meterA.SyncInt64().UpDownCounter("bar", + barA, err := meterA.Int64UpDownCounter("bar", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter gauge bar")) assert.NoError(t, err) barA.Add(ctx, 100, attribute.String("type", "bar")) - barB, err := meterB.SyncInt64().UpDownCounter("bar", + barB, err := meterB.Int64UpDownCounter("bar", instrument.WithUnit(unit.Milliseconds), instrument.WithDescription("meter gauge bar")) assert.NoError(t, err) @@ -545,13 +545,13 @@ func TestDuplicateMetrics(t *testing.T) { { name: "conflict_unit_two_histograms", recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { - barA, err := meterA.SyncInt64().Histogram("bar", + barA, err := meterA.Int64Histogram("bar", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter histogram bar")) assert.NoError(t, err) barA.Record(ctx, 100, attribute.String("A", "B")) - barB, err := meterB.SyncInt64().Histogram("bar", + barB, err := meterB.Int64Histogram("bar", instrument.WithUnit(unit.Milliseconds), instrument.WithDescription("meter histogram bar")) assert.NoError(t, err) @@ -563,13 +563,13 @@ func TestDuplicateMetrics(t *testing.T) { { name: "conflict_type_counter_and_updowncounter", recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { - counter, err := meterA.SyncInt64().Counter("foo", + counter, err := meterA.Int64Counter("foo", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter foo")) assert.NoError(t, err) counter.Add(ctx, 100, attribute.String("type", "foo")) - gauge, err := meterA.SyncInt64().UpDownCounter("foo_total", + gauge, err := meterA.Int64UpDownCounter("foo_total", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter foo")) assert.NoError(t, err) @@ -584,13 +584,13 @@ func TestDuplicateMetrics(t *testing.T) { { name: "conflict_type_histogram_and_updowncounter", recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) { - fooA, err := meterA.SyncInt64().UpDownCounter("foo", + fooA, err := meterA.Int64UpDownCounter("foo", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter gauge foo")) assert.NoError(t, err) fooA.Add(ctx, 100, attribute.String("A", "B")) - fooHistogramA, err := meterA.SyncInt64().Histogram("foo", + fooHistogramA, err := meterA.Int64Histogram("foo", instrument.WithUnit(unit.Bytes), instrument.WithDescription("meter histogram foo")) assert.NoError(t, err) diff --git a/metric/example_test.go b/metric/example_test.go index dc22989f6..08741f77d 100644 --- a/metric/example_test.go +++ b/metric/example_test.go @@ -31,7 +31,7 @@ func ExampleMeter_synchronous() { // In a library or program this would be provided by otel.GetMeterProvider(). meterProvider := metric.NewNoopMeterProvider() - workDuration, err := meterProvider.Meter("go.opentelemetry.io/otel/metric#SyncExample").SyncInt64().Histogram( + workDuration, err := meterProvider.Meter("go.opentelemetry.io/otel/metric#SyncExample").Int64Histogram( "workDuration", instrument.WithUnit(unit.Milliseconds)) if err != nil { @@ -52,7 +52,7 @@ func ExampleMeter_asynchronous_single() { meterProvider := metric.NewNoopMeterProvider() meter := meterProvider.Meter("go.opentelemetry.io/otel/metric#AsyncExample") - memoryUsage, err := meter.AsyncInt64().Gauge( + memoryUsage, err := meter.Int64ObservableGauge( "MemoryUsage", instrument.WithUnit(unit.Bytes), ) @@ -82,9 +82,9 @@ func ExampleMeter_asynchronous_multiple() { meter := meterProvider.Meter("go.opentelemetry.io/otel/metric#MultiAsyncExample") // This is just a sample of memory stats to record from the Memstats - heapAlloc, _ := meter.AsyncInt64().UpDownCounter("heapAllocs") - gcCount, _ := meter.AsyncInt64().Counter("gcCount") - gcPause, _ := meter.SyncFloat64().Histogram("gcPause") + heapAlloc, _ := meter.Int64ObservableUpDownCounter("heapAllocs") + gcCount, _ := meter.Int64ObservableCounter("gcCount") + gcPause, _ := meter.Float64Histogram("gcPause") _, err := meter.RegisterCallback([]instrument.Asynchronous{ heapAlloc, diff --git a/metric/instrument/asyncfloat64/asyncfloat64.go b/metric/instrument/asyncfloat64/asyncfloat64.go index 330a14c2f..038e55db0 100644 --- a/metric/instrument/asyncfloat64/asyncfloat64.go +++ b/metric/instrument/asyncfloat64/asyncfloat64.go @@ -21,20 +21,6 @@ import ( "go.opentelemetry.io/otel/metric/instrument" ) -// InstrumentProvider provides access to individual instruments. -// -// Warning: methods may be added to this interface in minor releases. -type InstrumentProvider interface { - // Counter creates an instrument for recording increasing values. - Counter(name string, opts ...instrument.Option) (Counter, error) - - // UpDownCounter creates an instrument for recording changes of a value. - UpDownCounter(name string, opts ...instrument.Option) (UpDownCounter, error) - - // Gauge creates an instrument for recording the current value. - Gauge(name string, opts ...instrument.Option) (Gauge, error) -} - // Counter is an instrument that records increasing values. // // Warning: methods may be added to this interface in minor releases. diff --git a/metric/instrument/asyncint64/asyncint64.go b/metric/instrument/asyncint64/asyncint64.go index 4fce9963c..0d727e08f 100644 --- a/metric/instrument/asyncint64/asyncint64.go +++ b/metric/instrument/asyncint64/asyncint64.go @@ -21,20 +21,6 @@ import ( "go.opentelemetry.io/otel/metric/instrument" ) -// InstrumentProvider provides access to individual instruments. -// -// Warning: methods may be added to this interface in minor releases. -type InstrumentProvider interface { - // Counter creates an instrument for recording increasing values. - Counter(name string, opts ...instrument.Option) (Counter, error) - - // UpDownCounter creates an instrument for recording changes of a value. - UpDownCounter(name string, opts ...instrument.Option) (UpDownCounter, error) - - // Gauge creates an instrument for recording the current value. - Gauge(name string, opts ...instrument.Option) (Gauge, error) -} - // Counter is an instrument that records increasing values. // // Warning: methods may be added to this interface in minor releases. diff --git a/metric/instrument/syncfloat64/syncfloat64.go b/metric/instrument/syncfloat64/syncfloat64.go index 2ec192f70..dff6b77b4 100644 --- a/metric/instrument/syncfloat64/syncfloat64.go +++ b/metric/instrument/syncfloat64/syncfloat64.go @@ -21,18 +21,6 @@ import ( "go.opentelemetry.io/otel/metric/instrument" ) -// InstrumentProvider provides access to individual instruments. -// -// Warning: methods may be added to this interface in minor releases. -type InstrumentProvider interface { - // Counter creates an instrument for recording increasing values. - Counter(name string, opts ...instrument.Option) (Counter, error) - // UpDownCounter creates an instrument for recording changes of a value. - UpDownCounter(name string, opts ...instrument.Option) (UpDownCounter, error) - // Histogram creates an instrument for recording a distribution of values. - Histogram(name string, opts ...instrument.Option) (Histogram, error) -} - // Counter is an instrument that records increasing values. // // Warning: methods may be added to this interface in minor releases. diff --git a/metric/instrument/syncint64/syncint64.go b/metric/instrument/syncint64/syncint64.go index 03b5d53e6..2611c513c 100644 --- a/metric/instrument/syncint64/syncint64.go +++ b/metric/instrument/syncint64/syncint64.go @@ -21,18 +21,6 @@ import ( "go.opentelemetry.io/otel/metric/instrument" ) -// InstrumentProvider provides access to individual instruments. -// -// Warning: methods may be added to this interface in minor releases. -type InstrumentProvider interface { - // Counter creates an instrument for recording increasing values. - Counter(name string, opts ...instrument.Option) (Counter, error) - // UpDownCounter creates an instrument for recording changes of a value. - UpDownCounter(name string, opts ...instrument.Option) (UpDownCounter, error) - // Histogram creates an instrument for recording a distribution of values. - Histogram(name string, opts ...instrument.Option) (Histogram, error) -} - // Counter is an instrument that records increasing values. // // Warning: methods may be added to this interface in minor releases. diff --git a/metric/internal/global/instruments.go b/metric/internal/global/instruments.go index 7cce2bd15..9d28d5884 100644 --- a/metric/internal/global/instruments.go +++ b/metric/internal/global/instruments.go @@ -38,7 +38,7 @@ type afCounter struct { } func (i *afCounter) setDelegate(m metric.Meter) { - ctr, err := m.AsyncFloat64().Counter(i.name, i.opts...) + ctr, err := m.Float64ObservableCounter(i.name, i.opts...) if err != nil { otel.Handle(err) return @@ -69,7 +69,7 @@ type afUpDownCounter struct { } func (i *afUpDownCounter) setDelegate(m metric.Meter) { - ctr, err := m.AsyncFloat64().UpDownCounter(i.name, i.opts...) + ctr, err := m.Float64ObservableUpDownCounter(i.name, i.opts...) if err != nil { otel.Handle(err) return @@ -100,7 +100,7 @@ type afGauge struct { } func (i *afGauge) setDelegate(m metric.Meter) { - ctr, err := m.AsyncFloat64().Gauge(i.name, i.opts...) + ctr, err := m.Float64ObservableGauge(i.name, i.opts...) if err != nil { otel.Handle(err) return @@ -131,7 +131,7 @@ type aiCounter struct { } func (i *aiCounter) setDelegate(m metric.Meter) { - ctr, err := m.AsyncInt64().Counter(i.name, i.opts...) + ctr, err := m.Int64ObservableCounter(i.name, i.opts...) if err != nil { otel.Handle(err) return @@ -162,7 +162,7 @@ type aiUpDownCounter struct { } func (i *aiUpDownCounter) setDelegate(m metric.Meter) { - ctr, err := m.AsyncInt64().UpDownCounter(i.name, i.opts...) + ctr, err := m.Int64ObservableUpDownCounter(i.name, i.opts...) if err != nil { otel.Handle(err) return @@ -193,7 +193,7 @@ type aiGauge struct { } func (i *aiGauge) setDelegate(m metric.Meter) { - ctr, err := m.AsyncInt64().Gauge(i.name, i.opts...) + ctr, err := m.Int64ObservableGauge(i.name, i.opts...) if err != nil { otel.Handle(err) return @@ -225,7 +225,7 @@ type sfCounter struct { } func (i *sfCounter) setDelegate(m metric.Meter) { - ctr, err := m.SyncFloat64().Counter(i.name, i.opts...) + ctr, err := m.Float64Counter(i.name, i.opts...) if err != nil { otel.Handle(err) return @@ -249,7 +249,7 @@ type sfUpDownCounter struct { } func (i *sfUpDownCounter) setDelegate(m metric.Meter) { - ctr, err := m.SyncFloat64().UpDownCounter(i.name, i.opts...) + ctr, err := m.Float64UpDownCounter(i.name, i.opts...) if err != nil { otel.Handle(err) return @@ -273,7 +273,7 @@ type sfHistogram struct { } func (i *sfHistogram) setDelegate(m metric.Meter) { - ctr, err := m.SyncFloat64().Histogram(i.name, i.opts...) + ctr, err := m.Float64Histogram(i.name, i.opts...) if err != nil { otel.Handle(err) return @@ -297,7 +297,7 @@ type siCounter struct { } func (i *siCounter) setDelegate(m metric.Meter) { - ctr, err := m.SyncInt64().Counter(i.name, i.opts...) + ctr, err := m.Int64Counter(i.name, i.opts...) if err != nil { otel.Handle(err) return @@ -321,7 +321,7 @@ type siUpDownCounter struct { } func (i *siUpDownCounter) setDelegate(m metric.Meter) { - ctr, err := m.SyncInt64().UpDownCounter(i.name, i.opts...) + ctr, err := m.Int64UpDownCounter(i.name, i.opts...) if err != nil { otel.Handle(err) return @@ -345,7 +345,7 @@ type siHistogram struct { } func (i *siHistogram) setDelegate(m metric.Meter) { - ctr, err := m.SyncInt64().Histogram(i.name, i.opts...) + ctr, err := m.Int64Histogram(i.name, i.opts...) if err != nil { otel.Handle(err) return diff --git a/metric/internal/global/meter.go b/metric/internal/global/meter.go index e8c835784..940728cb2 100644 --- a/metric/internal/global/meter.go +++ b/metric/internal/global/meter.go @@ -147,24 +147,136 @@ func (m *meter) setDelegate(provider metric.MeterProvider) { m.registry.Init() } -// AsyncInt64 is the namespace for the Asynchronous Integer instruments. -// -// To Observe data with instruments it must be registered in a callback. -func (m *meter) AsyncInt64() asyncint64.InstrumentProvider { +func (m *meter) Int64Counter(name string, options ...instrument.Option) (syncint64.Counter, error) { if del, ok := m.delegate.Load().(metric.Meter); ok { - return del.AsyncInt64() + return del.Int64Counter(name, options...) } - return (*aiInstProvider)(m) + m.mtx.Lock() + defer m.mtx.Unlock() + i := &siCounter{name: name, opts: options} + m.instruments = append(m.instruments, i) + return i, nil } -// AsyncFloat64 is the namespace for the Asynchronous Float instruments. -// -// To Observe data with instruments it must be registered in a callback. -func (m *meter) AsyncFloat64() asyncfloat64.InstrumentProvider { +func (m *meter) Int64UpDownCounter(name string, options ...instrument.Option) (syncint64.UpDownCounter, error) { if del, ok := m.delegate.Load().(metric.Meter); ok { - return del.AsyncFloat64() + return del.Int64UpDownCounter(name, options...) } - return (*afInstProvider)(m) + m.mtx.Lock() + defer m.mtx.Unlock() + i := &siUpDownCounter{name: name, opts: options} + m.instruments = append(m.instruments, i) + return i, nil +} + +func (m *meter) Int64Histogram(name string, options ...instrument.Option) (syncint64.Histogram, error) { + if del, ok := m.delegate.Load().(metric.Meter); ok { + return del.Int64Histogram(name, options...) + } + m.mtx.Lock() + defer m.mtx.Unlock() + i := &siHistogram{name: name, opts: options} + m.instruments = append(m.instruments, i) + return i, nil +} + +func (m *meter) Int64ObservableCounter(name string, options ...instrument.Option) (asyncint64.Counter, error) { + if del, ok := m.delegate.Load().(metric.Meter); ok { + return del.Int64ObservableCounter(name, options...) + } + m.mtx.Lock() + defer m.mtx.Unlock() + i := &aiCounter{name: name, opts: options} + m.instruments = append(m.instruments, i) + return i, nil +} + +func (m *meter) Int64ObservableUpDownCounter(name string, options ...instrument.Option) (asyncint64.UpDownCounter, error) { + if del, ok := m.delegate.Load().(metric.Meter); ok { + return del.Int64ObservableUpDownCounter(name, options...) + } + m.mtx.Lock() + defer m.mtx.Unlock() + i := &aiUpDownCounter{name: name, opts: options} + m.instruments = append(m.instruments, i) + return i, nil +} + +func (m *meter) Int64ObservableGauge(name string, options ...instrument.Option) (asyncint64.Gauge, error) { + if del, ok := m.delegate.Load().(metric.Meter); ok { + return del.Int64ObservableGauge(name, options...) + } + m.mtx.Lock() + defer m.mtx.Unlock() + i := &aiGauge{name: name, opts: options} + m.instruments = append(m.instruments, i) + return i, nil +} + +func (m *meter) Float64Counter(name string, options ...instrument.Option) (syncfloat64.Counter, error) { + if del, ok := m.delegate.Load().(metric.Meter); ok { + return del.Float64Counter(name, options...) + } + m.mtx.Lock() + defer m.mtx.Unlock() + i := &sfCounter{name: name, opts: options} + m.instruments = append(m.instruments, i) + return i, nil +} + +func (m *meter) Float64UpDownCounter(name string, options ...instrument.Option) (syncfloat64.UpDownCounter, error) { + if del, ok := m.delegate.Load().(metric.Meter); ok { + return del.Float64UpDownCounter(name, options...) + } + m.mtx.Lock() + defer m.mtx.Unlock() + i := &sfUpDownCounter{name: name, opts: options} + m.instruments = append(m.instruments, i) + return i, nil +} + +func (m *meter) Float64Histogram(name string, options ...instrument.Option) (syncfloat64.Histogram, error) { + if del, ok := m.delegate.Load().(metric.Meter); ok { + return del.Float64Histogram(name, options...) + } + m.mtx.Lock() + defer m.mtx.Unlock() + i := &sfHistogram{name: name, opts: options} + m.instruments = append(m.instruments, i) + return i, nil +} + +func (m *meter) Float64ObservableCounter(name string, options ...instrument.Option) (asyncfloat64.Counter, error) { + if del, ok := m.delegate.Load().(metric.Meter); ok { + return del.Float64ObservableCounter(name, options...) + } + m.mtx.Lock() + defer m.mtx.Unlock() + i := &afCounter{name: name, opts: options} + m.instruments = append(m.instruments, i) + return i, nil +} + +func (m *meter) Float64ObservableUpDownCounter(name string, options ...instrument.Option) (asyncfloat64.UpDownCounter, error) { + if del, ok := m.delegate.Load().(metric.Meter); ok { + return del.Float64ObservableUpDownCounter(name, options...) + } + m.mtx.Lock() + defer m.mtx.Unlock() + i := &afUpDownCounter{name: name, opts: options} + m.instruments = append(m.instruments, i) + return i, nil +} + +func (m *meter) Float64ObservableGauge(name string, options ...instrument.Option) (asyncfloat64.Gauge, error) { + if del, ok := m.delegate.Load().(metric.Meter); ok { + return del.Float64ObservableGauge(name, options...) + } + m.mtx.Lock() + defer m.mtx.Unlock() + i := &afGauge{name: name, opts: options} + m.instruments = append(m.instruments, i) + return i, nil } // RegisterCallback captures the function that will be called during Collect. @@ -209,22 +321,6 @@ func unwrapInstruments(instruments []instrument.Asynchronous) []instrument.Async return out } -// SyncInt64 is the namespace for the Synchronous Integer instruments. -func (m *meter) SyncInt64() syncint64.InstrumentProvider { - if del, ok := m.delegate.Load().(metric.Meter); ok { - return del.SyncInt64() - } - return (*siInstProvider)(m) -} - -// SyncFloat64 is the namespace for the Synchronous Float instruments. -func (m *meter) SyncFloat64() syncfloat64.InstrumentProvider { - if del, ok := m.delegate.Load().(metric.Meter); ok { - return del.SyncFloat64() - } - return (*sfInstProvider)(m) -} - type registration struct { instruments []instrument.Asynchronous function func(context.Context) @@ -264,119 +360,3 @@ func (c *registration) Unregister() error { err, c.unreg = c.unreg(), nil return err } - -type afInstProvider meter - -// Counter creates an instrument for recording increasing values. -func (ip *afInstProvider) Counter(name string, opts ...instrument.Option) (asyncfloat64.Counter, error) { - ip.mtx.Lock() - defer ip.mtx.Unlock() - ctr := &afCounter{name: name, opts: opts} - ip.instruments = append(ip.instruments, ctr) - return ctr, nil -} - -// UpDownCounter creates an instrument for recording changes of a value. -func (ip *afInstProvider) UpDownCounter(name string, opts ...instrument.Option) (asyncfloat64.UpDownCounter, error) { - ip.mtx.Lock() - defer ip.mtx.Unlock() - ctr := &afUpDownCounter{name: name, opts: opts} - ip.instruments = append(ip.instruments, ctr) - return ctr, nil -} - -// Gauge creates an instrument for recording the current value. -func (ip *afInstProvider) Gauge(name string, opts ...instrument.Option) (asyncfloat64.Gauge, error) { - ip.mtx.Lock() - defer ip.mtx.Unlock() - ctr := &afGauge{name: name, opts: opts} - ip.instruments = append(ip.instruments, ctr) - return ctr, nil -} - -type aiInstProvider meter - -// Counter creates an instrument for recording increasing values. -func (ip *aiInstProvider) Counter(name string, opts ...instrument.Option) (asyncint64.Counter, error) { - ip.mtx.Lock() - defer ip.mtx.Unlock() - ctr := &aiCounter{name: name, opts: opts} - ip.instruments = append(ip.instruments, ctr) - return ctr, nil -} - -// UpDownCounter creates an instrument for recording changes of a value. -func (ip *aiInstProvider) UpDownCounter(name string, opts ...instrument.Option) (asyncint64.UpDownCounter, error) { - ip.mtx.Lock() - defer ip.mtx.Unlock() - ctr := &aiUpDownCounter{name: name, opts: opts} - ip.instruments = append(ip.instruments, ctr) - return ctr, nil -} - -// Gauge creates an instrument for recording the current value. -func (ip *aiInstProvider) Gauge(name string, opts ...instrument.Option) (asyncint64.Gauge, error) { - ip.mtx.Lock() - defer ip.mtx.Unlock() - ctr := &aiGauge{name: name, opts: opts} - ip.instruments = append(ip.instruments, ctr) - return ctr, nil -} - -type sfInstProvider meter - -// Counter creates an instrument for recording increasing values. -func (ip *sfInstProvider) Counter(name string, opts ...instrument.Option) (syncfloat64.Counter, error) { - ip.mtx.Lock() - defer ip.mtx.Unlock() - ctr := &sfCounter{name: name, opts: opts} - ip.instruments = append(ip.instruments, ctr) - return ctr, nil -} - -// UpDownCounter creates an instrument for recording changes of a value. -func (ip *sfInstProvider) UpDownCounter(name string, opts ...instrument.Option) (syncfloat64.UpDownCounter, error) { - ip.mtx.Lock() - defer ip.mtx.Unlock() - ctr := &sfUpDownCounter{name: name, opts: opts} - ip.instruments = append(ip.instruments, ctr) - return ctr, nil -} - -// Histogram creates an instrument for recording a distribution of values. -func (ip *sfInstProvider) Histogram(name string, opts ...instrument.Option) (syncfloat64.Histogram, error) { - ip.mtx.Lock() - defer ip.mtx.Unlock() - ctr := &sfHistogram{name: name, opts: opts} - ip.instruments = append(ip.instruments, ctr) - return ctr, nil -} - -type siInstProvider meter - -// Counter creates an instrument for recording increasing values. -func (ip *siInstProvider) Counter(name string, opts ...instrument.Option) (syncint64.Counter, error) { - ip.mtx.Lock() - defer ip.mtx.Unlock() - ctr := &siCounter{name: name, opts: opts} - ip.instruments = append(ip.instruments, ctr) - return ctr, nil -} - -// UpDownCounter creates an instrument for recording changes of a value. -func (ip *siInstProvider) UpDownCounter(name string, opts ...instrument.Option) (syncint64.UpDownCounter, error) { - ip.mtx.Lock() - defer ip.mtx.Unlock() - ctr := &siUpDownCounter{name: name, opts: opts} - ip.instruments = append(ip.instruments, ctr) - return ctr, nil -} - -// Histogram creates an instrument for recording a distribution of values. -func (ip *siInstProvider) Histogram(name string, opts ...instrument.Option) (syncint64.Histogram, error) { - ip.mtx.Lock() - defer ip.mtx.Unlock() - ctr := &siHistogram{name: name, opts: opts} - ip.instruments = append(ip.instruments, ctr) - return ctr, nil -} diff --git a/metric/internal/global/meter_test.go b/metric/internal/global/meter_test.go index 15a0bf877..903ed340a 100644 --- a/metric/internal/global/meter_test.go +++ b/metric/internal/global/meter_test.go @@ -56,18 +56,18 @@ func TestMeterRace(t *testing.T) { go func() { for i, once := 0, false; ; i++ { name := fmt.Sprintf("a%d", i) - _, _ = mtr.AsyncFloat64().Counter(name) - _, _ = mtr.AsyncFloat64().UpDownCounter(name) - _, _ = mtr.AsyncFloat64().Gauge(name) - _, _ = mtr.AsyncInt64().Counter(name) - _, _ = mtr.AsyncInt64().UpDownCounter(name) - _, _ = mtr.AsyncInt64().Gauge(name) - _, _ = mtr.SyncFloat64().Counter(name) - _, _ = mtr.SyncFloat64().UpDownCounter(name) - _, _ = mtr.SyncFloat64().Histogram(name) - _, _ = mtr.SyncInt64().Counter(name) - _, _ = mtr.SyncInt64().UpDownCounter(name) - _, _ = mtr.SyncInt64().Histogram(name) + _, _ = mtr.Float64ObservableCounter(name) + _, _ = mtr.Float64ObservableUpDownCounter(name) + _, _ = mtr.Float64ObservableGauge(name) + _, _ = mtr.Int64ObservableCounter(name) + _, _ = mtr.Int64ObservableUpDownCounter(name) + _, _ = mtr.Int64ObservableGauge(name) + _, _ = mtr.Float64Counter(name) + _, _ = mtr.Float64UpDownCounter(name) + _, _ = mtr.Float64Histogram(name) + _, _ = mtr.Int64Counter(name) + _, _ = mtr.Int64UpDownCounter(name) + _, _ = mtr.Int64Histogram(name) _, _ = mtr.RegisterCallback(nil, func(ctx context.Context) {}) if !once { wg.Done() @@ -116,18 +116,18 @@ func TestUnregisterRace(t *testing.T) { } func testSetupAllInstrumentTypes(t *testing.T, m metric.Meter) (syncfloat64.Counter, asyncfloat64.Counter) { - afcounter, err := m.AsyncFloat64().Counter("test_Async_Counter") + afcounter, err := m.Float64ObservableCounter("test_Async_Counter") require.NoError(t, err) - _, err = m.AsyncFloat64().UpDownCounter("test_Async_UpDownCounter") + _, err = m.Float64ObservableUpDownCounter("test_Async_UpDownCounter") assert.NoError(t, err) - _, err = m.AsyncFloat64().Gauge("test_Async_Gauge") + _, err = m.Float64ObservableGauge("test_Async_Gauge") assert.NoError(t, err) - _, err = m.AsyncInt64().Counter("test_Async_Counter") + _, err = m.Int64ObservableCounter("test_Async_Counter") assert.NoError(t, err) - _, err = m.AsyncInt64().UpDownCounter("test_Async_UpDownCounter") + _, err = m.Int64ObservableUpDownCounter("test_Async_UpDownCounter") assert.NoError(t, err) - _, err = m.AsyncInt64().Gauge("test_Async_Gauge") + _, err = m.Int64ObservableGauge("test_Async_Gauge") assert.NoError(t, err) _, err = m.RegisterCallback([]instrument.Asynchronous{afcounter}, func(ctx context.Context) { @@ -135,18 +135,18 @@ func testSetupAllInstrumentTypes(t *testing.T, m metric.Meter) (syncfloat64.Coun }) require.NoError(t, err) - sfcounter, err := m.SyncFloat64().Counter("test_Async_Counter") + sfcounter, err := m.Float64Counter("test_Async_Counter") require.NoError(t, err) - _, err = m.SyncFloat64().UpDownCounter("test_Async_UpDownCounter") + _, err = m.Float64UpDownCounter("test_Async_UpDownCounter") assert.NoError(t, err) - _, err = m.SyncFloat64().Histogram("test_Async_Histogram") + _, err = m.Float64Histogram("test_Async_Histogram") assert.NoError(t, err) - _, err = m.SyncInt64().Counter("test_Async_Counter") + _, err = m.Int64Counter("test_Async_Counter") assert.NoError(t, err) - _, err = m.SyncInt64().UpDownCounter("test_Async_UpDownCounter") + _, err = m.Int64UpDownCounter("test_Async_UpDownCounter") assert.NoError(t, err) - _, err = m.SyncInt64().Histogram("test_Async_Histogram") + _, err = m.Int64Histogram("test_Async_Histogram") assert.NoError(t, err) return sfcounter, afcounter @@ -194,10 +194,18 @@ func TestMeterProviderDelegatesCalls(t *testing.T) { // Calls to Meter() after setDelegate() should be executed by the delegate require.IsType(t, &testMeter{}, meter) tMeter := meter.(*testMeter) - assert.Equal(t, 3, tMeter.afCount) - assert.Equal(t, 3, tMeter.aiCount) - assert.Equal(t, 3, tMeter.sfCount) - assert.Equal(t, 3, tMeter.siCount) + assert.Equal(t, 1, tMeter.afCount) + assert.Equal(t, 1, tMeter.afUDCount) + assert.Equal(t, 1, tMeter.afGauge) + assert.Equal(t, 1, tMeter.aiCount) + assert.Equal(t, 1, tMeter.aiUDCount) + assert.Equal(t, 1, tMeter.aiGauge) + assert.Equal(t, 1, tMeter.sfCount) + assert.Equal(t, 1, tMeter.sfUDCount) + assert.Equal(t, 1, tMeter.sfHist) + assert.Equal(t, 1, tMeter.siCount) + assert.Equal(t, 1, tMeter.siUDCount) + assert.Equal(t, 1, tMeter.siHist) assert.Equal(t, 1, len(tMeter.callbacks)) // Because the Meter was provided by testmeterProvider it should also return our test instrument @@ -236,10 +244,18 @@ func TestMeterDelegatesCalls(t *testing.T) { require.IsType(t, &meter{}, m) tMeter := m.(*meter).delegate.Load().(*testMeter) require.NotNil(t, tMeter) - assert.Equal(t, 3, tMeter.afCount) - assert.Equal(t, 3, tMeter.aiCount) - assert.Equal(t, 3, tMeter.sfCount) - assert.Equal(t, 3, tMeter.siCount) + assert.Equal(t, 1, tMeter.afCount) + assert.Equal(t, 1, tMeter.afUDCount) + assert.Equal(t, 1, tMeter.afGauge) + assert.Equal(t, 1, tMeter.aiCount) + assert.Equal(t, 1, tMeter.aiUDCount) + assert.Equal(t, 1, tMeter.aiGauge) + assert.Equal(t, 1, tMeter.sfCount) + assert.Equal(t, 1, tMeter.sfUDCount) + assert.Equal(t, 1, tMeter.sfHist) + assert.Equal(t, 1, tMeter.siCount) + assert.Equal(t, 1, tMeter.siUDCount) + assert.Equal(t, 1, tMeter.siHist) // Because the Meter was provided by testmeterProvider it should also return our test instrument require.IsType(t, &testCountingFloatInstrument{}, ctr, "the meter did not delegate calls to the meter") @@ -276,10 +292,18 @@ func TestMeterDefersDelegations(t *testing.T) { require.IsType(t, &meter{}, m) tMeter := m.(*meter).delegate.Load().(*testMeter) require.NotNil(t, tMeter) - assert.Equal(t, 3, tMeter.afCount) - assert.Equal(t, 3, tMeter.aiCount) - assert.Equal(t, 3, tMeter.sfCount) - assert.Equal(t, 3, tMeter.siCount) + assert.Equal(t, 1, tMeter.afCount) + assert.Equal(t, 1, tMeter.afUDCount) + assert.Equal(t, 1, tMeter.afGauge) + assert.Equal(t, 1, tMeter.aiCount) + assert.Equal(t, 1, tMeter.aiUDCount) + assert.Equal(t, 1, tMeter.aiGauge) + assert.Equal(t, 1, tMeter.sfCount) + assert.Equal(t, 1, tMeter.sfUDCount) + assert.Equal(t, 1, tMeter.sfHist) + assert.Equal(t, 1, tMeter.siCount) + assert.Equal(t, 1, tMeter.siUDCount) + assert.Equal(t, 1, tMeter.siHist) // Because the Meter was a delegate it should return a delegated instrument @@ -296,7 +320,7 @@ func TestRegistrationDelegation(t *testing.T) { require.IsType(t, &meter{}, m) mImpl := m.(*meter) - actr, err := m.AsyncFloat64().Counter("test_Async_Counter") + actr, err := m.Float64ObservableCounter("test_Async_Counter") require.NoError(t, err) var called0 bool diff --git a/metric/internal/global/meter_types_test.go b/metric/internal/global/meter_types_test.go index 53dfbc752..b77f79268 100644 --- a/metric/internal/global/meter_types_test.go +++ b/metric/internal/global/meter_types_test.go @@ -36,28 +36,83 @@ func (p *testMeterProvider) Meter(name string, opts ...metric.MeterOption) metri } type testMeter struct { - afCount int - aiCount int - sfCount int - siCount int + afCount int + afUDCount int + afGauge int + + aiCount int + aiUDCount int + aiGauge int + + sfCount int + sfUDCount int + sfHist int + + siCount int + siUDCount int + siHist int callbacks []func(context.Context) } -// AsyncInt64 is the namespace for the Asynchronous Integer instruments. -// -// To Observe data with instruments it must be registered in a callback. -func (m *testMeter) AsyncInt64() asyncint64.InstrumentProvider { - m.aiCount++ - return &testAIInstrumentProvider{} +func (m *testMeter) Int64Counter(name string, options ...instrument.Option) (syncint64.Counter, error) { + m.siCount++ + return &testCountingIntInstrument{}, nil } -// AsyncFloat64 is the namespace for the Asynchronous Float instruments -// -// To Observe data with instruments it must be registered in a callback. -func (m *testMeter) AsyncFloat64() asyncfloat64.InstrumentProvider { +func (m *testMeter) Int64UpDownCounter(name string, options ...instrument.Option) (syncint64.UpDownCounter, error) { + m.siUDCount++ + return &testCountingIntInstrument{}, nil +} + +func (m *testMeter) Int64Histogram(name string, options ...instrument.Option) (syncint64.Histogram, error) { + m.siHist++ + return &testCountingIntInstrument{}, nil +} + +func (m *testMeter) Int64ObservableCounter(name string, options ...instrument.Option) (asyncint64.Counter, error) { + m.aiCount++ + return &testCountingIntInstrument{}, nil +} + +func (m *testMeter) Int64ObservableUpDownCounter(name string, options ...instrument.Option) (asyncint64.UpDownCounter, error) { + m.aiUDCount++ + return &testCountingIntInstrument{}, nil +} + +func (m *testMeter) Int64ObservableGauge(name string, options ...instrument.Option) (asyncint64.Gauge, error) { + m.aiGauge++ + return &testCountingIntInstrument{}, nil +} + +func (m *testMeter) Float64Counter(name string, options ...instrument.Option) (syncfloat64.Counter, error) { + m.sfCount++ + return &testCountingFloatInstrument{}, nil +} + +func (m *testMeter) Float64UpDownCounter(name string, options ...instrument.Option) (syncfloat64.UpDownCounter, error) { + m.sfUDCount++ + return &testCountingFloatInstrument{}, nil +} + +func (m *testMeter) Float64Histogram(name string, options ...instrument.Option) (syncfloat64.Histogram, error) { + m.sfHist++ + return &testCountingFloatInstrument{}, nil +} + +func (m *testMeter) Float64ObservableCounter(name string, options ...instrument.Option) (asyncfloat64.Counter, error) { m.afCount++ - return &testAFInstrumentProvider{} + return &testCountingFloatInstrument{}, nil +} + +func (m *testMeter) Float64ObservableUpDownCounter(name string, options ...instrument.Option) (asyncfloat64.UpDownCounter, error) { + m.afUDCount++ + return &testCountingFloatInstrument{}, nil +} + +func (m *testMeter) Float64ObservableGauge(name string, options ...instrument.Option) (asyncfloat64.Gauge, error) { + m.afGauge++ + return &testCountingFloatInstrument{}, nil } // RegisterCallback captures the function that will be called during Collect. @@ -82,18 +137,6 @@ func (r testReg) Unregister() error { return nil } -// SyncInt64 is the namespace for the Synchronous Integer instruments. -func (m *testMeter) SyncInt64() syncint64.InstrumentProvider { - m.siCount++ - return &testSIInstrumentProvider{} -} - -// SyncFloat64 is the namespace for the Synchronous Float instruments. -func (m *testMeter) SyncFloat64() syncfloat64.InstrumentProvider { - m.sfCount++ - return &testSFInstrumentProvider{} -} - // This enables async collection. func (m *testMeter) collect() { ctx := context.Background() @@ -105,71 +148,3 @@ func (m *testMeter) collect() { f(ctx) } } - -type testAFInstrumentProvider struct{} - -// Counter creates an instrument for recording increasing values. -func (ip testAFInstrumentProvider) Counter(name string, opts ...instrument.Option) (asyncfloat64.Counter, error) { - return &testCountingFloatInstrument{}, nil -} - -// UpDownCounter creates an instrument for recording changes of a value. -func (ip testAFInstrumentProvider) UpDownCounter(name string, opts ...instrument.Option) (asyncfloat64.UpDownCounter, error) { - return &testCountingFloatInstrument{}, nil -} - -// Gauge creates an instrument for recording the current value. -func (ip testAFInstrumentProvider) Gauge(name string, opts ...instrument.Option) (asyncfloat64.Gauge, error) { - return &testCountingFloatInstrument{}, nil -} - -type testAIInstrumentProvider struct{} - -// Counter creates an instrument for recording increasing values. -func (ip testAIInstrumentProvider) Counter(name string, opts ...instrument.Option) (asyncint64.Counter, error) { - return &testCountingIntInstrument{}, nil -} - -// UpDownCounter creates an instrument for recording changes of a value. -func (ip testAIInstrumentProvider) UpDownCounter(name string, opts ...instrument.Option) (asyncint64.UpDownCounter, error) { - return &testCountingIntInstrument{}, nil -} - -// Gauge creates an instrument for recording the current value. -func (ip testAIInstrumentProvider) Gauge(name string, opts ...instrument.Option) (asyncint64.Gauge, error) { - return &testCountingIntInstrument{}, nil -} - -type testSFInstrumentProvider struct{} - -// Counter creates an instrument for recording increasing values. -func (ip testSFInstrumentProvider) Counter(name string, opts ...instrument.Option) (syncfloat64.Counter, error) { - return &testCountingFloatInstrument{}, nil -} - -// UpDownCounter creates an instrument for recording changes of a value. -func (ip testSFInstrumentProvider) UpDownCounter(name string, opts ...instrument.Option) (syncfloat64.UpDownCounter, error) { - return &testCountingFloatInstrument{}, nil -} - -// Histogram creates an instrument for recording a distribution of values. -func (ip testSFInstrumentProvider) Histogram(name string, opts ...instrument.Option) (syncfloat64.Histogram, error) { - return &testCountingFloatInstrument{}, nil -} - -type testSIInstrumentProvider struct{} - -// Counter creates an instrument for recording increasing values. -func (ip testSIInstrumentProvider) Counter(name string, opts ...instrument.Option) (syncint64.Counter, error) { - return &testCountingIntInstrument{}, nil -} - -// UpDownCounter creates an instrument for recording changes of a value. -func (ip testSIInstrumentProvider) UpDownCounter(name string, opts ...instrument.Option) (syncint64.UpDownCounter, error) { - return &testCountingIntInstrument{}, nil -} - -// Histogram creates an instrument for recording a distribution of values. -func (ip testSIInstrumentProvider) Histogram(name string, opts ...instrument.Option) (syncint64.Histogram, error) { - return &testCountingIntInstrument{}, nil -} diff --git a/metric/meter.go b/metric/meter.go index 3a505264c..83f2d6a81 100644 --- a/metric/meter.go +++ b/metric/meter.go @@ -41,20 +41,59 @@ type MeterProvider interface { // // Warning: methods may be added to this interface in minor releases. type Meter interface { - // AsyncInt64 is the namespace for the Asynchronous Integer instruments. - // - // To Observe data with instruments it must be registered in a callback. - AsyncInt64() asyncint64.InstrumentProvider + // 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.Option) (syncint64.Counter, 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.Option) (syncint64.UpDownCounter, 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.Option) (syncint64.Histogram, 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.Option) (asyncint64.Counter, 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.Option) (asyncint64.UpDownCounter, 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.Option) (asyncint64.Gauge, error) - // AsyncFloat64 is the namespace for the Asynchronous Float instruments - // - // To Observe data with instruments it must be registered in a callback. - AsyncFloat64() asyncfloat64.InstrumentProvider - - // SyncInt64 is the namespace for the Synchronous Integer instruments - SyncInt64() syncint64.InstrumentProvider - // SyncFloat64 is the namespace for the Synchronous Float instruments - SyncFloat64() syncfloat64.InstrumentProvider + // 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.Option) (syncfloat64.Counter, 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.Option) (syncfloat64.UpDownCounter, 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.Option) (syncfloat64.Histogram, 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.Option) (asyncfloat64.Counter, 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.Option) (asyncfloat64.UpDownCounter, 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.Option) (asyncfloat64.Gauge, error) // RegisterCallback registers f to be called during the collection of a // measurement cycle. diff --git a/metric/noop.go b/metric/noop.go index 7454a7903..568257c09 100644 --- a/metric/noop.go +++ b/metric/noop.go @@ -43,24 +43,52 @@ func NewNoopMeter() Meter { type noopMeter struct{} -// AsyncInt64 creates an instrument that does not record any metrics. -func (noopMeter) AsyncInt64() asyncint64.InstrumentProvider { - return nonrecordingAsyncInt64Instrument{} +func (noopMeter) Int64Counter(string, ...instrument.Option) (syncint64.Counter, error) { + return nonrecordingSyncInt64Instrument{}, nil } -// AsyncFloat64 creates an instrument that does not record any metrics. -func (noopMeter) AsyncFloat64() asyncfloat64.InstrumentProvider { - return nonrecordingAsyncFloat64Instrument{} +func (noopMeter) Int64UpDownCounter(string, ...instrument.Option) (syncint64.UpDownCounter, error) { + return nonrecordingSyncInt64Instrument{}, nil } -// SyncInt64 creates an instrument that does not record any metrics. -func (noopMeter) SyncInt64() syncint64.InstrumentProvider { - return nonrecordingSyncInt64Instrument{} +func (noopMeter) Int64Histogram(string, ...instrument.Option) (syncint64.Histogram, error) { + return nonrecordingSyncInt64Instrument{}, nil } -// SyncFloat64 creates an instrument that does not record any metrics. -func (noopMeter) SyncFloat64() syncfloat64.InstrumentProvider { - return nonrecordingSyncFloat64Instrument{} +func (noopMeter) Int64ObservableCounter(string, ...instrument.Option) (asyncint64.Counter, error) { + return nonrecordingAsyncInt64Instrument{}, nil +} + +func (noopMeter) Int64ObservableUpDownCounter(string, ...instrument.Option) (asyncint64.UpDownCounter, error) { + return nonrecordingAsyncInt64Instrument{}, nil +} + +func (noopMeter) Int64ObservableGauge(string, ...instrument.Option) (asyncint64.Gauge, error) { + return nonrecordingAsyncInt64Instrument{}, nil +} + +func (noopMeter) Float64Counter(string, ...instrument.Option) (syncfloat64.Counter, error) { + return nonrecordingSyncFloat64Instrument{}, nil +} + +func (noopMeter) Float64UpDownCounter(string, ...instrument.Option) (syncfloat64.UpDownCounter, error) { + return nonrecordingSyncFloat64Instrument{}, nil +} + +func (noopMeter) Float64Histogram(string, ...instrument.Option) (syncfloat64.Histogram, error) { + return nonrecordingSyncFloat64Instrument{}, nil +} + +func (noopMeter) Float64ObservableCounter(string, ...instrument.Option) (asyncfloat64.Counter, error) { + return nonrecordingAsyncFloat64Instrument{}, nil +} + +func (noopMeter) Float64ObservableUpDownCounter(string, ...instrument.Option) (asyncfloat64.UpDownCounter, error) { + return nonrecordingAsyncFloat64Instrument{}, nil +} + +func (noopMeter) Float64ObservableGauge(string, ...instrument.Option) (asyncfloat64.Gauge, error) { + return nonrecordingAsyncFloat64Instrument{}, nil } // RegisterCallback creates a register callback that does not record any metrics. @@ -77,10 +105,9 @@ type nonrecordingAsyncFloat64Instrument struct { } var ( - _ asyncfloat64.InstrumentProvider = nonrecordingAsyncFloat64Instrument{} - _ asyncfloat64.Counter = nonrecordingAsyncFloat64Instrument{} - _ asyncfloat64.UpDownCounter = nonrecordingAsyncFloat64Instrument{} - _ asyncfloat64.Gauge = nonrecordingAsyncFloat64Instrument{} + _ asyncfloat64.Counter = nonrecordingAsyncFloat64Instrument{} + _ asyncfloat64.UpDownCounter = nonrecordingAsyncFloat64Instrument{} + _ asyncfloat64.Gauge = nonrecordingAsyncFloat64Instrument{} ) func (n nonrecordingAsyncFloat64Instrument) Counter(string, ...instrument.Option) (asyncfloat64.Counter, error) { @@ -104,10 +131,9 @@ type nonrecordingAsyncInt64Instrument struct { } var ( - _ asyncint64.InstrumentProvider = nonrecordingAsyncInt64Instrument{} - _ asyncint64.Counter = nonrecordingAsyncInt64Instrument{} - _ asyncint64.UpDownCounter = nonrecordingAsyncInt64Instrument{} - _ asyncint64.Gauge = nonrecordingAsyncInt64Instrument{} + _ asyncint64.Counter = nonrecordingAsyncInt64Instrument{} + _ asyncint64.UpDownCounter = nonrecordingAsyncInt64Instrument{} + _ asyncint64.Gauge = nonrecordingAsyncInt64Instrument{} ) func (n nonrecordingAsyncInt64Instrument) Counter(string, ...instrument.Option) (asyncint64.Counter, error) { @@ -130,10 +156,9 @@ type nonrecordingSyncFloat64Instrument struct { } var ( - _ syncfloat64.InstrumentProvider = nonrecordingSyncFloat64Instrument{} - _ syncfloat64.Counter = nonrecordingSyncFloat64Instrument{} - _ syncfloat64.UpDownCounter = nonrecordingSyncFloat64Instrument{} - _ syncfloat64.Histogram = nonrecordingSyncFloat64Instrument{} + _ syncfloat64.Counter = nonrecordingSyncFloat64Instrument{} + _ syncfloat64.UpDownCounter = nonrecordingSyncFloat64Instrument{} + _ syncfloat64.Histogram = nonrecordingSyncFloat64Instrument{} ) func (n nonrecordingSyncFloat64Instrument) Counter(string, ...instrument.Option) (syncfloat64.Counter, error) { @@ -161,10 +186,9 @@ type nonrecordingSyncInt64Instrument struct { } var ( - _ syncint64.InstrumentProvider = nonrecordingSyncInt64Instrument{} - _ syncint64.Counter = nonrecordingSyncInt64Instrument{} - _ syncint64.UpDownCounter = nonrecordingSyncInt64Instrument{} - _ syncint64.Histogram = nonrecordingSyncInt64Instrument{} + _ syncint64.Counter = nonrecordingSyncInt64Instrument{} + _ syncint64.UpDownCounter = nonrecordingSyncInt64Instrument{} + _ syncint64.Histogram = nonrecordingSyncInt64Instrument{} ) func (n nonrecordingSyncInt64Instrument) Counter(string, ...instrument.Option) (syncint64.Counter, error) { diff --git a/metric/noop_test.go b/metric/noop_test.go index 4603cfce5..6c75c0198 100644 --- a/metric/noop_test.go +++ b/metric/noop_test.go @@ -34,19 +34,19 @@ func TestNewNoopMeterProvider(t *testing.T) { func TestSyncFloat64(t *testing.T) { meter := NewNoopMeterProvider().Meter("test instrumentation") assert.NotPanics(t, func() { - inst, err := meter.SyncFloat64().Counter("test instrument") + inst, err := meter.Float64Counter("test instrument") require.NoError(t, err) inst.Add(context.Background(), 1.0, attribute.String("key", "value")) }) assert.NotPanics(t, func() { - inst, err := meter.SyncFloat64().UpDownCounter("test instrument") + inst, err := meter.Float64UpDownCounter("test instrument") require.NoError(t, err) inst.Add(context.Background(), -1.0, attribute.String("key", "value")) }) assert.NotPanics(t, func() { - inst, err := meter.SyncFloat64().Histogram("test instrument") + inst, err := meter.Float64Histogram("test instrument") require.NoError(t, err) inst.Record(context.Background(), 1.0, attribute.String("key", "value")) }) @@ -55,19 +55,19 @@ func TestSyncFloat64(t *testing.T) { func TestSyncInt64(t *testing.T) { meter := NewNoopMeterProvider().Meter("test instrumentation") assert.NotPanics(t, func() { - inst, err := meter.SyncInt64().Counter("test instrument") + inst, err := meter.Int64Counter("test instrument") require.NoError(t, err) inst.Add(context.Background(), 1, attribute.String("key", "value")) }) assert.NotPanics(t, func() { - inst, err := meter.SyncInt64().UpDownCounter("test instrument") + inst, err := meter.Int64UpDownCounter("test instrument") require.NoError(t, err) inst.Add(context.Background(), -1, attribute.String("key", "value")) }) assert.NotPanics(t, func() { - inst, err := meter.SyncInt64().Histogram("test instrument") + inst, err := meter.Int64Histogram("test instrument") require.NoError(t, err) inst.Record(context.Background(), 1, attribute.String("key", "value")) }) @@ -76,19 +76,19 @@ func TestSyncInt64(t *testing.T) { func TestAsyncFloat64(t *testing.T) { meter := NewNoopMeterProvider().Meter("test instrumentation") assert.NotPanics(t, func() { - inst, err := meter.AsyncFloat64().Counter("test instrument") + inst, err := meter.Float64ObservableCounter("test instrument") require.NoError(t, err) inst.Observe(context.Background(), 1.0, attribute.String("key", "value")) }) assert.NotPanics(t, func() { - inst, err := meter.AsyncFloat64().UpDownCounter("test instrument") + inst, err := meter.Float64ObservableUpDownCounter("test instrument") require.NoError(t, err) inst.Observe(context.Background(), -1.0, attribute.String("key", "value")) }) assert.NotPanics(t, func() { - inst, err := meter.AsyncFloat64().Gauge("test instrument") + inst, err := meter.Float64ObservableGauge("test instrument") require.NoError(t, err) inst.Observe(context.Background(), 1.0, attribute.String("key", "value")) }) @@ -97,19 +97,19 @@ func TestAsyncFloat64(t *testing.T) { func TestAsyncInt64(t *testing.T) { meter := NewNoopMeterProvider().Meter("test instrumentation") assert.NotPanics(t, func() { - inst, err := meter.AsyncInt64().Counter("test instrument") + inst, err := meter.Int64ObservableCounter("test instrument") require.NoError(t, err) inst.Observe(context.Background(), 1, attribute.String("key", "value")) }) assert.NotPanics(t, func() { - inst, err := meter.AsyncInt64().UpDownCounter("test instrument") + inst, err := meter.Int64ObservableUpDownCounter("test instrument") require.NoError(t, err) inst.Observe(context.Background(), -1, attribute.String("key", "value")) }) assert.NotPanics(t, func() { - inst, err := meter.AsyncInt64().Gauge("test instrument") + inst, err := meter.Int64ObservableGauge("test instrument") require.NoError(t, err) inst.Observe(context.Background(), 1, attribute.String("key", "value")) }) diff --git a/sdk/metric/benchmark_test.go b/sdk/metric/benchmark_test.go index 9743c90cf..e77bf149e 100644 --- a/sdk/metric/benchmark_test.go +++ b/sdk/metric/benchmark_test.go @@ -26,7 +26,7 @@ func benchCounter(b *testing.B, views ...View) (context.Context, Reader, syncint ctx := context.Background() rdr := NewManualReader() provider := NewMeterProvider(WithReader(rdr), WithView(views...)) - cntr, _ := provider.Meter("test").SyncInt64().Counter("hello") + cntr, _ := provider.Meter("test").Int64Counter("hello") b.ResetTimer() b.ReportAllocs() return ctx, rdr, cntr diff --git a/sdk/metric/instrument_provider.go b/sdk/metric/instrument_provider.go deleted file mode 100644 index ade1f6415..000000000 --- a/sdk/metric/instrument_provider.go +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package metric // import "go.opentelemetry.io/otel/sdk/metric" - -import ( - "go.opentelemetry.io/otel/metric/instrument" - "go.opentelemetry.io/otel/metric/instrument/asyncfloat64" - "go.opentelemetry.io/otel/metric/instrument/asyncint64" - "go.opentelemetry.io/otel/metric/instrument/syncfloat64" - "go.opentelemetry.io/otel/metric/instrument/syncint64" - "go.opentelemetry.io/otel/sdk/instrumentation" -) - -// instProvider provides all OpenTelemetry instruments. -type instProvider[N int64 | float64] struct { - scope instrumentation.Scope - resolve resolver[N] -} - -func newInstProvider[N int64 | float64](s instrumentation.Scope, p pipelines, c instrumentCache[N]) *instProvider[N] { - return &instProvider[N]{scope: s, resolve: newResolver(p, c)} -} - -// lookup returns the resolved instrumentImpl. -func (p *instProvider[N]) lookup(kind InstrumentKind, name string, opts []instrument.Option) (*instrumentImpl[N], error) { - cfg := instrument.NewConfig(opts...) - i := Instrument{ - Name: name, - Description: cfg.Description(), - Unit: cfg.Unit(), - Kind: kind, - Scope: p.scope, - } - aggs, err := p.resolve.Aggregators(i) - return &instrumentImpl[N]{aggregators: aggs}, err -} - -type asyncInt64Provider struct { - *instProvider[int64] -} - -var _ asyncint64.InstrumentProvider = asyncInt64Provider{} - -// Counter creates an instrument for recording increasing values. -func (p asyncInt64Provider) Counter(name string, opts ...instrument.Option) (asyncint64.Counter, error) { - return p.lookup(InstrumentKindAsyncCounter, name, opts) -} - -// UpDownCounter creates an instrument for recording changes of a value. -func (p asyncInt64Provider) UpDownCounter(name string, opts ...instrument.Option) (asyncint64.UpDownCounter, error) { - return p.lookup(InstrumentKindAsyncUpDownCounter, name, opts) -} - -// Gauge creates an instrument for recording the current value. -func (p asyncInt64Provider) Gauge(name string, opts ...instrument.Option) (asyncint64.Gauge, error) { - return p.lookup(InstrumentKindAsyncGauge, name, opts) -} - -type asyncFloat64Provider struct { - *instProvider[float64] -} - -var _ asyncfloat64.InstrumentProvider = asyncFloat64Provider{} - -// Counter creates an instrument for recording increasing values. -func (p asyncFloat64Provider) Counter(name string, opts ...instrument.Option) (asyncfloat64.Counter, error) { - return p.lookup(InstrumentKindAsyncCounter, name, opts) -} - -// UpDownCounter creates an instrument for recording changes of a value. -func (p asyncFloat64Provider) UpDownCounter(name string, opts ...instrument.Option) (asyncfloat64.UpDownCounter, error) { - return p.lookup(InstrumentKindAsyncUpDownCounter, name, opts) -} - -// Gauge creates an instrument for recording the current value. -func (p asyncFloat64Provider) Gauge(name string, opts ...instrument.Option) (asyncfloat64.Gauge, error) { - return p.lookup(InstrumentKindAsyncGauge, name, opts) -} - -type syncInt64Provider struct { - *instProvider[int64] -} - -var _ syncint64.InstrumentProvider = syncInt64Provider{} - -// Counter creates an instrument for recording increasing values. -func (p syncInt64Provider) Counter(name string, opts ...instrument.Option) (syncint64.Counter, error) { - return p.lookup(InstrumentKindSyncCounter, name, opts) -} - -// UpDownCounter creates an instrument for recording changes of a value. -func (p syncInt64Provider) UpDownCounter(name string, opts ...instrument.Option) (syncint64.UpDownCounter, error) { - return p.lookup(InstrumentKindSyncUpDownCounter, name, opts) -} - -// Histogram creates an instrument for recording the current value. -func (p syncInt64Provider) Histogram(name string, opts ...instrument.Option) (syncint64.Histogram, error) { - return p.lookup(InstrumentKindSyncHistogram, name, opts) -} - -type syncFloat64Provider struct { - *instProvider[float64] -} - -var _ syncfloat64.InstrumentProvider = syncFloat64Provider{} - -// Counter creates an instrument for recording increasing values. -func (p syncFloat64Provider) Counter(name string, opts ...instrument.Option) (syncfloat64.Counter, error) { - return p.lookup(InstrumentKindSyncCounter, name, opts) -} - -// UpDownCounter creates an instrument for recording changes of a value. -func (p syncFloat64Provider) UpDownCounter(name string, opts ...instrument.Option) (syncfloat64.UpDownCounter, error) { - return p.lookup(InstrumentKindSyncUpDownCounter, name, opts) -} - -// Histogram creates an instrument for recording the current value. -func (p syncFloat64Provider) Histogram(name string, opts ...instrument.Option) (syncfloat64.Histogram, error) { - return p.lookup(InstrumentKindSyncHistogram, name, opts) -} diff --git a/sdk/metric/internal/aggregator_example_test.go b/sdk/metric/internal/aggregator_example_test.go index 16ca8a444..0f9850cbc 100644 --- a/sdk/metric/internal/aggregator_example_test.go +++ b/sdk/metric/internal/aggregator_example_test.go @@ -31,19 +31,11 @@ type meter struct { aggregations []metricdata.Aggregation } -func (m *meter) SyncInt64() syncint64.InstrumentProvider { - // The same would be done for all the other instrument providers. - return (*syncInt64Provider)(m) -} - -type syncInt64Provider meter - -func (p *syncInt64Provider) Counter(string, ...instrument.Option) (syncint64.Counter, error) { - // This is an example of how a synchronous int64 provider 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 here these are determined to be a - // cumulative sum. +func (p *meter) Int64Counter(string, ...instrument.Option) (syncint64.Counter, 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 + // here these are determined to be a cumulative sum. aggregator := NewCumulativeSum[int64](true) count := inst{aggregateFunc: aggregator.Aggregate} @@ -55,13 +47,12 @@ func (p *syncInt64Provider) Counter(string, ...instrument.Option) (syncint64.Cou return count, nil } -func (p *syncInt64Provider) UpDownCounter(string, ...instrument.Option) (syncint64.UpDownCounter, error) { - // This is an example of how a synchronous int64 provider 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 configuration. Assume here these are determined to be a - // last-value aggregation (the temporality does not affect the produced - // aggregations). +func (p *meter) Int64UpDownCounter(string, ...instrument.Option) (syncint64.UpDownCounter, 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 + // configuration. Assume here these are determined to be a last-value + // aggregation (the temporality does not affect the produced aggregations). aggregator := NewLastValue[int64]() upDownCount := inst{aggregateFunc: aggregator.Aggregate} @@ -73,12 +64,12 @@ func (p *syncInt64Provider) UpDownCounter(string, ...instrument.Option) (syncint return upDownCount, nil } -func (p *syncInt64Provider) Histogram(string, ...instrument.Option) (syncint64.Histogram, error) { - // This is an example of how a synchronous int64 provider 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. Assume here these are determined to be a delta - // explicit-bucket histogram. +func (p *meter) Int64Histogram(string, ...instrument.Option) (syncint64.Histogram, 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. + // Assume here these are determined to be a delta explicit-bucket + // histogram. aggregator := NewDeltaHistogram[int64](aggregation.ExplicitBucketHistogram{ Boundaries: []float64{0, 5, 10, 25, 50, 75, 100, 250, 500, 1000}, @@ -106,11 +97,10 @@ func (inst) Record(context.Context, int64, ...attribute.KeyValue) {} func Example() { m := meter{} - provider := m.SyncInt64() - _, _ = provider.Counter("counter example") - _, _ = provider.UpDownCounter("up-down counter example") - _, _ = provider.Histogram("histogram example") + _, _ = m.Int64Counter("counter example") + _, _ = m.Int64UpDownCounter("up-down counter example") + _, _ = m.Int64Histogram("histogram example") // Output: // using *internal.cumulativeSum[int64] aggregator for counter diff --git a/sdk/metric/meter.go b/sdk/metric/meter.go index c2c515af3..e4f17f51b 100644 --- a/sdk/metric/meter.go +++ b/sdk/metric/meter.go @@ -57,14 +57,88 @@ func newMeter(s instrumentation.Scope, p pipelines) *meter { // Compile-time check meter implements metric.Meter. var _ metric.Meter = (*meter)(nil) -// AsyncInt64 returns the asynchronous integer instrument provider. -func (m *meter) AsyncInt64() asyncint64.InstrumentProvider { - return asyncInt64Provider{m.instProviderInt64} +// 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.Option) (syncint64.Counter, error) { + return m.instProviderInt64.lookup(InstrumentKindSyncCounter, name, options) } -// AsyncFloat64 returns the asynchronous floating-point instrument provider. -func (m *meter) AsyncFloat64() asyncfloat64.InstrumentProvider { - return asyncFloat64Provider{m.instProviderFloat64} +// 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.Option) (syncint64.UpDownCounter, error) { + return m.instProviderInt64.lookup(InstrumentKindSyncUpDownCounter, name, options) +} + +// 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.Option) (syncint64.Histogram, error) { + return m.instProviderInt64.lookup(InstrumentKindSyncHistogram, name, options) +} + +// 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.Option) (asyncint64.Counter, error) { + return m.instProviderInt64.lookup(InstrumentKindAsyncCounter, name, options) +} + +// 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.Option) (asyncint64.UpDownCounter, error) { + return m.instProviderInt64.lookup(InstrumentKindAsyncUpDownCounter, name, options) +} + +// 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.Option) (asyncint64.Gauge, error) { + return m.instProviderInt64.lookup(InstrumentKindAsyncGauge, name, options) +} + +// 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.Option) (syncfloat64.Counter, error) { + return m.instProviderFloat64.lookup(InstrumentKindSyncCounter, name, options) +} + +// 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.Option) (syncfloat64.UpDownCounter, error) { + return m.instProviderFloat64.lookup(InstrumentKindSyncUpDownCounter, name, options) +} + +// 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.Option) (syncfloat64.Histogram, error) { + return m.instProviderFloat64.lookup(InstrumentKindSyncHistogram, name, options) +} + +// 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.Option) (asyncfloat64.Counter, error) { + return m.instProviderFloat64.lookup(InstrumentKindAsyncCounter, name, options) +} + +// 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.Option) (asyncfloat64.UpDownCounter, error) { + return m.instProviderFloat64.lookup(InstrumentKindAsyncUpDownCounter, name, options) +} + +// 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.Option) (asyncfloat64.Gauge, error) { + return m.instProviderFloat64.lookup(InstrumentKindAsyncGauge, name, options) } // RegisterCallback registers the function f to be called when any of the @@ -106,12 +180,26 @@ func (m *meter) registerCallback(c callback) (metric.Registration, error) { return m.pipes.registerCallback(c), nil } -// SyncInt64 returns the synchronous integer instrument provider. -func (m *meter) SyncInt64() syncint64.InstrumentProvider { - return syncInt64Provider{m.instProviderInt64} +// instProvider provides all OpenTelemetry instruments. +type instProvider[N int64 | float64] struct { + scope instrumentation.Scope + resolve resolver[N] } -// SyncFloat64 returns the synchronous floating-point instrument provider. -func (m *meter) SyncFloat64() syncfloat64.InstrumentProvider { - return syncFloat64Provider{m.instProviderFloat64} +func newInstProvider[N int64 | float64](s instrumentation.Scope, p pipelines, c instrumentCache[N]) *instProvider[N] { + return &instProvider[N]{scope: s, resolve: newResolver(p, c)} +} + +// lookup returns the resolved instrumentImpl. +func (p *instProvider[N]) lookup(kind InstrumentKind, name string, opts []instrument.Option) (*instrumentImpl[N], error) { + cfg := instrument.NewConfig(opts...) + i := Instrument{ + Name: name, + Description: cfg.Description(), + Unit: cfg.Unit(), + Kind: kind, + Scope: p.scope, + } + aggs, err := p.resolve.Aggregators(i) + return &instrumentImpl[N]{aggregators: aggs}, err } diff --git a/sdk/metric/meter_test.go b/sdk/metric/meter_test.go index d904b118a..e57b4acb7 100644 --- a/sdk/metric/meter_test.go +++ b/sdk/metric/meter_test.go @@ -44,51 +44,51 @@ func TestMeterInstrumentConcurrency(t *testing.T) { m := NewMeterProvider().Meter("inst-concurrency") go func() { - _, _ = m.AsyncFloat64().Counter("AFCounter") + _, _ = m.Float64ObservableCounter("AFCounter") wg.Done() }() go func() { - _, _ = m.AsyncFloat64().UpDownCounter("AFUpDownCounter") + _, _ = m.Float64ObservableUpDownCounter("AFUpDownCounter") wg.Done() }() go func() { - _, _ = m.AsyncFloat64().Gauge("AFGauge") + _, _ = m.Float64ObservableGauge("AFGauge") wg.Done() }() go func() { - _, _ = m.AsyncInt64().Counter("AICounter") + _, _ = m.Int64ObservableCounter("AICounter") wg.Done() }() go func() { - _, _ = m.AsyncInt64().UpDownCounter("AIUpDownCounter") + _, _ = m.Int64ObservableUpDownCounter("AIUpDownCounter") wg.Done() }() go func() { - _, _ = m.AsyncInt64().Gauge("AIGauge") + _, _ = m.Int64ObservableGauge("AIGauge") wg.Done() }() go func() { - _, _ = m.SyncFloat64().Counter("SFCounter") + _, _ = m.Float64Counter("SFCounter") wg.Done() }() go func() { - _, _ = m.SyncFloat64().UpDownCounter("SFUpDownCounter") + _, _ = m.Float64UpDownCounter("SFUpDownCounter") wg.Done() }() go func() { - _, _ = m.SyncFloat64().Histogram("SFHistogram") + _, _ = m.Float64Histogram("SFHistogram") wg.Done() }() go func() { - _, _ = m.SyncInt64().Counter("SICounter") + _, _ = m.Int64Counter("SICounter") wg.Done() }() go func() { - _, _ = m.SyncInt64().UpDownCounter("SIUpDownCounter") + _, _ = m.Int64UpDownCounter("SIUpDownCounter") wg.Done() }() go func() { - _, _ = m.SyncInt64().Histogram("SIHistogram") + _, _ = m.Int64Histogram("SIHistogram") wg.Done() }() @@ -136,10 +136,10 @@ func TestCallbackUnregisterConcurrency(t *testing.T) { provider := NewMeterProvider(WithReader(reader)) meter := provider.Meter("unregister-concurrency") - actr, err := meter.AsyncFloat64().Counter("counter") + actr, err := meter.Float64ObservableCounter("counter") require.NoError(t, err) - ag, err := meter.AsyncInt64().Gauge("gauge") + ag, err := meter.Int64ObservableGauge("gauge") require.NoError(t, err) i := []instrument.Asynchronous{actr} @@ -176,7 +176,7 @@ func TestMeterCreatesInstruments(t *testing.T) { { name: "AsyncInt64Count", fn: func(t *testing.T, m metric.Meter) { - ctr, err := m.AsyncInt64().Counter("aint") + ctr, err := m.Int64ObservableCounter("aint") assert.NoError(t, err) _, err = m.RegisterCallback([]instrument.Asynchronous{ctr}, func(ctx context.Context) { ctr.Observe(ctx, 3) @@ -200,7 +200,7 @@ func TestMeterCreatesInstruments(t *testing.T) { { name: "AsyncInt64UpDownCount", fn: func(t *testing.T, m metric.Meter) { - ctr, err := m.AsyncInt64().UpDownCounter("aint") + ctr, err := m.Int64ObservableUpDownCounter("aint") assert.NoError(t, err) _, err = m.RegisterCallback([]instrument.Asynchronous{ctr}, func(ctx context.Context) { ctr.Observe(ctx, 11) @@ -224,7 +224,7 @@ func TestMeterCreatesInstruments(t *testing.T) { { name: "AsyncInt64Gauge", fn: func(t *testing.T, m metric.Meter) { - gauge, err := m.AsyncInt64().Gauge("agauge") + gauge, err := m.Int64ObservableGauge("agauge") assert.NoError(t, err) _, err = m.RegisterCallback([]instrument.Asynchronous{gauge}, func(ctx context.Context) { gauge.Observe(ctx, 11) @@ -246,7 +246,7 @@ func TestMeterCreatesInstruments(t *testing.T) { { name: "AsyncFloat64Count", fn: func(t *testing.T, m metric.Meter) { - ctr, err := m.AsyncFloat64().Counter("afloat") + ctr, err := m.Float64ObservableCounter("afloat") assert.NoError(t, err) _, err = m.RegisterCallback([]instrument.Asynchronous{ctr}, func(ctx context.Context) { ctr.Observe(ctx, 3) @@ -270,7 +270,7 @@ func TestMeterCreatesInstruments(t *testing.T) { { name: "AsyncFloat64UpDownCount", fn: func(t *testing.T, m metric.Meter) { - ctr, err := m.AsyncFloat64().UpDownCounter("afloat") + ctr, err := m.Float64ObservableUpDownCounter("afloat") assert.NoError(t, err) _, err = m.RegisterCallback([]instrument.Asynchronous{ctr}, func(ctx context.Context) { ctr.Observe(ctx, 11) @@ -294,7 +294,7 @@ func TestMeterCreatesInstruments(t *testing.T) { { name: "AsyncFloat64Gauge", fn: func(t *testing.T, m metric.Meter) { - gauge, err := m.AsyncFloat64().Gauge("agauge") + gauge, err := m.Float64ObservableGauge("agauge") assert.NoError(t, err) _, err = m.RegisterCallback([]instrument.Asynchronous{gauge}, func(ctx context.Context) { gauge.Observe(ctx, 11) @@ -317,7 +317,7 @@ func TestMeterCreatesInstruments(t *testing.T) { { name: "SyncInt64Count", fn: func(t *testing.T, m metric.Meter) { - ctr, err := m.SyncInt64().Counter("sint") + ctr, err := m.Int64Counter("sint") assert.NoError(t, err) ctr.Add(context.Background(), 3) @@ -336,7 +336,7 @@ func TestMeterCreatesInstruments(t *testing.T) { { name: "SyncInt64UpDownCount", fn: func(t *testing.T, m metric.Meter) { - ctr, err := m.SyncInt64().UpDownCounter("sint") + ctr, err := m.Int64UpDownCounter("sint") assert.NoError(t, err) ctr.Add(context.Background(), 11) @@ -355,7 +355,7 @@ func TestMeterCreatesInstruments(t *testing.T) { { name: "SyncInt64Histogram", fn: func(t *testing.T, m metric.Meter) { - gauge, err := m.SyncInt64().Histogram("histogram") + gauge, err := m.Int64Histogram("histogram") assert.NoError(t, err) gauge.Record(context.Background(), 7) @@ -381,7 +381,7 @@ func TestMeterCreatesInstruments(t *testing.T) { { name: "SyncFloat64Count", fn: func(t *testing.T, m metric.Meter) { - ctr, err := m.SyncFloat64().Counter("sfloat") + ctr, err := m.Float64Counter("sfloat") assert.NoError(t, err) ctr.Add(context.Background(), 3) @@ -400,7 +400,7 @@ func TestMeterCreatesInstruments(t *testing.T) { { name: "SyncFloat64UpDownCount", fn: func(t *testing.T, m metric.Meter) { - ctr, err := m.SyncFloat64().UpDownCounter("sfloat") + ctr, err := m.Float64UpDownCounter("sfloat") assert.NoError(t, err) ctr.Add(context.Background(), 11) @@ -419,7 +419,7 @@ func TestMeterCreatesInstruments(t *testing.T) { { name: "SyncFloat64Histogram", fn: func(t *testing.T, m metric.Meter) { - gauge, err := m.SyncFloat64().Histogram("histogram") + gauge, err := m.Float64Histogram("histogram") assert.NoError(t, err) gauge.Record(context.Background(), 7) @@ -468,7 +468,7 @@ func TestMetersProvideScope(t *testing.T) { mp := NewMeterProvider(WithReader(rdr)) m1 := mp.Meter("scope1") - ctr1, err := m1.AsyncFloat64().Counter("ctr1") + ctr1, err := m1.Float64ObservableCounter("ctr1") assert.NoError(t, err) _, err = m1.RegisterCallback([]instrument.Asynchronous{ctr1}, func(ctx context.Context) { ctr1.Observe(ctx, 5) @@ -476,7 +476,7 @@ func TestMetersProvideScope(t *testing.T) { assert.NoError(t, err) m2 := mp.Meter("scope2") - ctr2, err := m2.AsyncInt64().Counter("ctr2") + ctr2, err := m2.Int64ObservableCounter("ctr2") assert.NoError(t, err) _, err = m1.RegisterCallback([]instrument.Asynchronous{ctr2}, func(ctx context.Context) { ctr2.Observe(ctx, 7) @@ -537,22 +537,22 @@ func TestUnregisterUnregisters(t *testing.T) { mp := NewMeterProvider(WithReader(r)) m := mp.Meter("TestUnregisterUnregisters") - int64Counter, err := m.AsyncInt64().Counter("int64.counter") + int64Counter, err := m.Int64ObservableCounter("int64.counter") require.NoError(t, err) - int64UpDownCounter, err := m.AsyncInt64().UpDownCounter("int64.up_down_counter") + int64UpDownCounter, err := m.Int64ObservableUpDownCounter("int64.up_down_counter") require.NoError(t, err) - int64Gauge, err := m.AsyncInt64().Gauge("int64.gauge") + int64Gauge, err := m.Int64ObservableGauge("int64.gauge") require.NoError(t, err) - floag64Counter, err := m.AsyncFloat64().Counter("floag64.counter") + floag64Counter, err := m.Float64ObservableCounter("floag64.counter") require.NoError(t, err) - floag64UpDownCounter, err := m.AsyncFloat64().UpDownCounter("floag64.up_down_counter") + floag64UpDownCounter, err := m.Float64ObservableUpDownCounter("floag64.up_down_counter") require.NoError(t, err) - floag64Gauge, err := m.AsyncFloat64().Gauge("floag64.gauge") + floag64Gauge, err := m.Float64ObservableGauge("floag64.gauge") require.NoError(t, err) var called bool @@ -587,22 +587,22 @@ func TestRegisterCallbackDropAggregations(t *testing.T) { mp := NewMeterProvider(WithReader(r)) m := mp.Meter("testRegisterCallbackDropAggregations") - int64Counter, err := m.AsyncInt64().Counter("int64.counter") + int64Counter, err := m.Int64ObservableCounter("int64.counter") require.NoError(t, err) - int64UpDownCounter, err := m.AsyncInt64().UpDownCounter("int64.up_down_counter") + int64UpDownCounter, err := m.Int64ObservableUpDownCounter("int64.up_down_counter") require.NoError(t, err) - int64Gauge, err := m.AsyncInt64().Gauge("int64.gauge") + int64Gauge, err := m.Int64ObservableGauge("int64.gauge") require.NoError(t, err) - floag64Counter, err := m.AsyncFloat64().Counter("floag64.counter") + floag64Counter, err := m.Float64ObservableCounter("floag64.counter") require.NoError(t, err) - floag64UpDownCounter, err := m.AsyncFloat64().UpDownCounter("floag64.up_down_counter") + floag64UpDownCounter, err := m.Float64ObservableUpDownCounter("floag64.up_down_counter") require.NoError(t, err) - floag64Gauge, err := m.AsyncFloat64().Gauge("floag64.gauge") + floag64Gauge, err := m.Float64ObservableGauge("floag64.gauge") require.NoError(t, err) var called bool @@ -634,7 +634,7 @@ func TestAttributeFilter(t *testing.T) { { name: "AsyncFloat64Counter", register: func(t *testing.T, mtr metric.Meter) error { - ctr, err := mtr.AsyncFloat64().Counter("afcounter") + ctr, err := mtr.Float64ObservableCounter("afcounter") if err != nil { return err } @@ -661,7 +661,7 @@ func TestAttributeFilter(t *testing.T) { { name: "AsyncFloat64UpDownCounter", register: func(t *testing.T, mtr metric.Meter) error { - ctr, err := mtr.AsyncFloat64().UpDownCounter("afupdowncounter") + ctr, err := mtr.Float64ObservableUpDownCounter("afupdowncounter") if err != nil { return err } @@ -688,7 +688,7 @@ func TestAttributeFilter(t *testing.T) { { name: "AsyncFloat64Gauge", register: func(t *testing.T, mtr metric.Meter) error { - ctr, err := mtr.AsyncFloat64().Gauge("afgauge") + ctr, err := mtr.Float64ObservableGauge("afgauge") if err != nil { return err } @@ -713,7 +713,7 @@ func TestAttributeFilter(t *testing.T) { { name: "AsyncInt64Counter", register: func(t *testing.T, mtr metric.Meter) error { - ctr, err := mtr.AsyncInt64().Counter("aicounter") + ctr, err := mtr.Int64ObservableCounter("aicounter") if err != nil { return err } @@ -740,7 +740,7 @@ func TestAttributeFilter(t *testing.T) { { name: "AsyncInt64UpDownCounter", register: func(t *testing.T, mtr metric.Meter) error { - ctr, err := mtr.AsyncInt64().UpDownCounter("aiupdowncounter") + ctr, err := mtr.Int64ObservableUpDownCounter("aiupdowncounter") if err != nil { return err } @@ -767,7 +767,7 @@ func TestAttributeFilter(t *testing.T) { { name: "AsyncInt64Gauge", register: func(t *testing.T, mtr metric.Meter) error { - ctr, err := mtr.AsyncInt64().Gauge("aigauge") + ctr, err := mtr.Int64ObservableGauge("aigauge") if err != nil { return err } @@ -792,7 +792,7 @@ func TestAttributeFilter(t *testing.T) { { name: "SyncFloat64Counter", register: func(t *testing.T, mtr metric.Meter) error { - ctr, err := mtr.SyncFloat64().Counter("sfcounter") + ctr, err := mtr.Float64Counter("sfcounter") if err != nil { return err } @@ -818,7 +818,7 @@ func TestAttributeFilter(t *testing.T) { { name: "SyncFloat64UpDownCounter", register: func(t *testing.T, mtr metric.Meter) error { - ctr, err := mtr.SyncFloat64().UpDownCounter("sfupdowncounter") + ctr, err := mtr.Float64UpDownCounter("sfupdowncounter") if err != nil { return err } @@ -844,7 +844,7 @@ func TestAttributeFilter(t *testing.T) { { name: "SyncFloat64Histogram", register: func(t *testing.T, mtr metric.Meter) error { - ctr, err := mtr.SyncFloat64().Histogram("sfhistogram") + ctr, err := mtr.Float64Histogram("sfhistogram") if err != nil { return err } @@ -874,7 +874,7 @@ func TestAttributeFilter(t *testing.T) { { name: "SyncInt64Counter", register: func(t *testing.T, mtr metric.Meter) error { - ctr, err := mtr.SyncInt64().Counter("sicounter") + ctr, err := mtr.Int64Counter("sicounter") if err != nil { return err } @@ -900,7 +900,7 @@ func TestAttributeFilter(t *testing.T) { { name: "SyncInt64UpDownCounter", register: func(t *testing.T, mtr metric.Meter) error { - ctr, err := mtr.SyncInt64().UpDownCounter("siupdowncounter") + ctr, err := mtr.Int64UpDownCounter("siupdowncounter") if err != nil { return err } @@ -926,7 +926,7 @@ func TestAttributeFilter(t *testing.T) { { name: "SyncInt64Histogram", register: func(t *testing.T, mtr metric.Meter) error { - ctr, err := mtr.SyncInt64().Histogram("sihistogram") + ctr, err := mtr.Int64Histogram("sihistogram") if err != nil { return err } @@ -1006,20 +1006,20 @@ func BenchmarkInstrumentCreation(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { - aiCounter, _ = meter.AsyncInt64().Counter("async.int64.counter") - aiUpDownCounter, _ = meter.AsyncInt64().UpDownCounter("async.int64.up.down.counter") - aiGauge, _ = meter.AsyncInt64().Gauge("async.int64.gauge") + aiCounter, _ = meter.Int64ObservableCounter("async.int64.counter") + aiUpDownCounter, _ = meter.Int64ObservableUpDownCounter("async.int64.up.down.counter") + aiGauge, _ = meter.Int64ObservableGauge("async.int64.gauge") - afCounter, _ = meter.AsyncFloat64().Counter("async.float64.counter") - afUpDownCounter, _ = meter.AsyncFloat64().UpDownCounter("async.float64.up.down.counter") - afGauge, _ = meter.AsyncFloat64().Gauge("async.float64.gauge") + afCounter, _ = meter.Float64ObservableCounter("async.float64.counter") + afUpDownCounter, _ = meter.Float64ObservableUpDownCounter("async.float64.up.down.counter") + afGauge, _ = meter.Float64ObservableGauge("async.float64.gauge") - siCounter, _ = meter.SyncInt64().Counter("sync.int64.counter") - siUpDownCounter, _ = meter.SyncInt64().UpDownCounter("sync.int64.up.down.counter") - siHistogram, _ = meter.SyncInt64().Histogram("sync.int64.histogram") + siCounter, _ = meter.Int64Counter("sync.int64.counter") + siUpDownCounter, _ = meter.Int64UpDownCounter("sync.int64.up.down.counter") + siHistogram, _ = meter.Int64Histogram("sync.int64.histogram") - sfCounter, _ = meter.SyncFloat64().Counter("sync.float64.counter") - sfUpDownCounter, _ = meter.SyncFloat64().UpDownCounter("sync.float64.up.down.counter") - sfHistogram, _ = meter.SyncFloat64().Histogram("sync.float64.histogram") + sfCounter, _ = meter.Float64Counter("sync.float64.counter") + sfUpDownCounter, _ = meter.Float64UpDownCounter("sync.float64.up.down.counter") + sfHistogram, _ = meter.Float64Histogram("sync.float64.histogram") } }