Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove metric instrument provider API #3530

Merged
merged 15 commits into from
Jan 3, 2023
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### 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`

### Removed

- The deprecated `go.opentelemetry.io/otel/sdk/metric/view` package is removed. (#3520)
Expand Down
6 changes: 3 additions & 3 deletions example/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions example/view/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion exporters/prometheus/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
86 changes: 43 additions & 43 deletions exporters/prometheus/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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
Expand All @@ -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...)
},
Expand All @@ -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...)
Expand All @@ -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...)
Expand All @@ -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...)
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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"))

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading