Skip to content

Commit

Permalink
Unify metric API into the one otel/metric package (#4018)
Browse files Browse the repository at this point in the history
* Move instrument into metric

* Update metric docs to include instrument

* Update package names

* Update all imports of sdk/metric/instrument

* Rename Option to InstrumentOption

* Deprecate otel/metric/instrument

* Add changelog entry
  • Loading branch information
MrAlias authored Apr 27, 2023
1 parent 94f6c4f commit 15d6ba2
Show file tree
Hide file tree
Showing 32 changed files with 968 additions and 545 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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
Loading

0 comments on commit 15d6ba2

Please sign in to comment.