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

Unify metric API into the one otel/metric package #4018

Merged
merged 10 commits into from
Apr 27, 2023
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Fix a data race in `SpanProcessor` returned by `NewSimpleSpanProcessor` in `go.opentelemetry.io/otel/sdk/trace`. (#3951)
- Automatically figure out the default aggregation with `aggregation.Default`. (#3967)

### Deprecated

- The `go.opentelemetry.io/otel/metric/instrument` package is deprecated.
Use the equivalent types added to `go.opentelemetry.io/otel/metric` instead. (#4018)

## [1.15.0-rc.2/0.38.0-rc.2] 2023-03-23

This is a release candidate for the v1.15.0/v0.38.0 release.
Expand Down
9 changes: 4 additions & 5 deletions example/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/prometheus"
api "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/sdk/metric"
)

Expand All @@ -50,19 +49,19 @@ func main() {
// Start the prometheus HTTP server and pass the exporter Collector to it
go serveMetrics()

opt := instrument.WithAttributes(
opt := api.WithAttributes(
attribute.Key("A").String("B"),
attribute.Key("C").String("D"),
)

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

gauge, err := meter.Float64ObservableGauge("bar", instrument.WithDescription("a fun little gauge"))
gauge, err := meter.Float64ObservableGauge("bar", api.WithDescription("a fun little gauge"))
if err != nil {
log.Fatal(err)
}
Expand All @@ -76,7 +75,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", api.WithDescription("a very nice histogram"))
if err != nil {
log.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions example/view/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

"go.opentelemetry.io/otel/attribute"
otelprom "go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/metric/instrument"
api "go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregation"
Expand Down Expand Up @@ -64,18 +64,18 @@ func main() {
// Start the prometheus HTTP server and pass the exporter Collector to it
go serveMetrics()

opt := instrument.WithAttributes(
opt := api.WithAttributes(
attribute.Key("A").String("B"),
attribute.Key("C").String("D"),
)

counter, err := meter.Float64Counter("foo", instrument.WithDescription("a simple counter"))
counter, err := meter.Float64Counter("foo", api.WithDescription("a simple counter"))
if err != nil {
log.Fatal(err)
}
counter.Add(ctx, 5, opt)

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