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

Use generics for metric instrument API #3973

Closed
wants to merge 13 commits into from
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,37 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
This adds an implementation requirement to set the interface default behavior for unimplemented methods. (#3916)
- Move No-Op implementation from `go.opentelemetry.io/otel/metric` into its own package `go.opentelemetry.io/otel/metric/noop`. (#3941)
- `metric.NewNoopMeterProvider` is replaced with `noop.NewMeterProvider`
- The `go.opentelemetry.io/otel/metric/instrument` API is refactored to use generics. (#3973)
- `Counter[N]` replaces `Int64Counter` and `Float64Counter`
- `CounterConfig[N]` replaces `Int64CounterConfig` and `Float64CounterConfig`
- `CounterOption[N]` replaces `Int64CounterOption` and `Float64CounterOption`
- `NewCounterConfig[N]` replaces `NewInt64CounterConfig` and `NewFloat64CounterConfig`
- `UpDownCounter[N]` replaces `Int64UpDownCounter` and `Float64UpDownCounter`
- `UpDownCounterConfig[N]` replaces `Int64UpDownCounterConfig` and `Float64UpDownCounterConfig`
- `UpDownCounterOption[N]` replaces `Int64UpDownCounterOption` and `Float64UpDownCounterOption`
- `NewUpDownCounterConfig[N]` replaces `NewInt64UpDownCounterConfig` and `NewFloat64UpDownCounterConfig`
- `Histogram[N]` replaces `Int64Histogram` and `Float64Histogram`
- `HistogramConfig[N]` replaces `Int64HistogramConfig` and `Float64HistogramConfig`
- `HistogramOption[N]` replaces `Int64HistogramOption` and `Float64HistogramOption`
- `NewHistogramConfig[N]` replaces `NewInt64HistogramConfig` and `NewFloat64HistogramConfig`
- `ObservableCounter[N]` replaces `Int64ObservableCounter` and `Float64ObservableCounter`
- `ObservableCounterConfig[N]` replaces `Int64ObservableCounterConfig` and `Float64ObservableCounterConfig`
- `ObservableCounterOption[N]` replaces `Int64ObservableCounterOption` and `Float64ObservableCounterOption`
- `NewObservableCounterConfig[N]` replaces `NewInt64ObservableCounterConfig` and `NewFloat64ObservableCounterConfig`
- `ObservableUpDownCounter[N]` replaces `Int64ObservableUpDownCounter` and `Float64ObservableUpDownCounter`
- `ObservableUpDownCounterConfig[N]` replaces `Int64ObservableUpDownCounterConfig` and `Float64ObservableUpDownCounterConfig`
- `ObservableUpDownCounterOption[N]` replaces `Int64ObservableUpDownCounterOption` and `Float64ObservableUpDownCounterOption`
- `NewObservableUpDownCounterConfig[N]` replaces `NewInt64ObservableUpDownCounterConfig` and `NewFloat64ObservableUpDownCounterConfig`
- `ObservableGauge[N]` replaces `Int64ObservableGauge` and `Float64ObservableGauge`
- `ObservableGaugeConfig[N]` replaces `Int64ObservableGaugeConfig` and `Float64ObservableGaugeConfig`
- `ObservableGaugeOption[N]` replaces `Int64ObservableGaugeOption` and `Float64ObservableGaugeOption`
- `NewObservableGaugeConfig[N]` replaces `NewInt64ObservableGaugeConfig` and `NewFloat64ObservableGaugeConfig`
- `ObserverT[N]` replaces `Int64Observer` and `Float64Observer`
- `ObservableOption[N]` replaces `Int64ObservableOption` and `Float64ObservableOption`
- `WithCallback[N]` replaces `WithInt64Callback` and `WithFloat64Callback`
- `Option[N]` replaces `Option`
- `WithDescription[N]` replaces `WithDescription`
- `WithUnit[N]` replaces `WithUnit`

### Fixed

Expand Down
6 changes: 3 additions & 3 deletions example/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ func main() {
}

// This is the equivalent of prometheus.NewCounterVec
counter, err := meter.Float64Counter("foo", instrument.WithDescription("a simple counter"))
counter, err := meter.Float64Counter("foo", instrument.WithDescription[float64]("a simple counter"))
if err != nil {
log.Fatal(err)
}
counter.Add(ctx, 5, attrs...)

gauge, err := meter.Float64ObservableGauge("bar", instrument.WithDescription("a fun little gauge"))
gauge, err := meter.Float64ObservableGauge("bar", instrument.WithDescription[float64]("a fun little gauge"))
if err != nil {
log.Fatal(err)
}
Expand All @@ -76,7 +76,7 @@ func main() {
}

// This is the equivalent of prometheus.NewHistogramVec
histogram, err := meter.Float64Histogram("baz", instrument.WithDescription("a very nice histogram"))
histogram, err := meter.Float64Histogram("baz", instrument.WithDescription[float64]("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.Float64Counter("foo", instrument.WithDescription("a simple counter"))
counter, err := meter.Float64Counter("foo", instrument.WithDescription[float64]("a simple counter"))
if err != nil {
log.Fatal(err)
}
counter.Add(ctx, 5, attrs...)

histogram, err := meter.Float64Histogram("custom_histogram", instrument.WithDescription("a histogram with custom buckets and rename"))
histogram, err := meter.Float64Histogram("custom_histogram", instrument.WithDescription[float64]("a histogram with custom buckets and rename"))
if err != nil {
log.Fatal(err)
}
Expand Down
Loading