Skip to content

Commit 15d6ba2

Browse files
authored
Unify metric API into the one otel/metric package (#4018)
* 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
1 parent 94f6c4f commit 15d6ba2

32 files changed

+968
-545
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
5959
- Fix a data race in `SpanProcessor` returned by `NewSimpleSpanProcessor` in `go.opentelemetry.io/otel/sdk/trace`. (#3951)
6060
- Automatically figure out the default aggregation with `aggregation.Default`. (#3967)
6161

62+
### Deprecated
63+
64+
- The `go.opentelemetry.io/otel/metric/instrument` package is deprecated.
65+
Use the equivalent types added to `go.opentelemetry.io/otel/metric` instead. (#4018)
66+
6267
## [1.15.0-rc.2/0.38.0-rc.2] 2023-03-23
6368

6469
This is a release candidate for the v1.15.0/v0.38.0 release.

example/prometheus/main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"go.opentelemetry.io/otel/attribute"
3030
"go.opentelemetry.io/otel/exporters/prometheus"
3131
api "go.opentelemetry.io/otel/metric"
32-
"go.opentelemetry.io/otel/metric/instrument"
3332
"go.opentelemetry.io/otel/sdk/metric"
3433
)
3534

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

53-
opt := instrument.WithAttributes(
52+
opt := api.WithAttributes(
5453
attribute.Key("A").String("B"),
5554
attribute.Key("C").String("D"),
5655
)
5756

5857
// This is the equivalent of prometheus.NewCounterVec
59-
counter, err := meter.Float64Counter("foo", instrument.WithDescription("a simple counter"))
58+
counter, err := meter.Float64Counter("foo", api.WithDescription("a simple counter"))
6059
if err != nil {
6160
log.Fatal(err)
6261
}
6362
counter.Add(ctx, 5, opt)
6463

65-
gauge, err := meter.Float64ObservableGauge("bar", instrument.WithDescription("a fun little gauge"))
64+
gauge, err := meter.Float64ObservableGauge("bar", api.WithDescription("a fun little gauge"))
6665
if err != nil {
6766
log.Fatal(err)
6867
}
@@ -76,7 +75,7 @@ func main() {
7675
}
7776

7877
// This is the equivalent of prometheus.NewHistogramVec
79-
histogram, err := meter.Float64Histogram("baz", instrument.WithDescription("a very nice histogram"))
78+
histogram, err := meter.Float64Histogram("baz", api.WithDescription("a very nice histogram"))
8079
if err != nil {
8180
log.Fatal(err)
8281
}

example/view/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
"go.opentelemetry.io/otel/attribute"
2828
otelprom "go.opentelemetry.io/otel/exporters/prometheus"
29-
"go.opentelemetry.io/otel/metric/instrument"
29+
api "go.opentelemetry.io/otel/metric"
3030
"go.opentelemetry.io/otel/sdk/instrumentation"
3131
"go.opentelemetry.io/otel/sdk/metric"
3232
"go.opentelemetry.io/otel/sdk/metric/aggregation"
@@ -64,18 +64,18 @@ func main() {
6464
// Start the prometheus HTTP server and pass the exporter Collector to it
6565
go serveMetrics()
6666

67-
opt := instrument.WithAttributes(
67+
opt := api.WithAttributes(
6868
attribute.Key("A").String("B"),
6969
attribute.Key("C").String("D"),
7070
)
7171

72-
counter, err := meter.Float64Counter("foo", instrument.WithDescription("a simple counter"))
72+
counter, err := meter.Float64Counter("foo", api.WithDescription("a simple counter"))
7373
if err != nil {
7474
log.Fatal(err)
7575
}
7676
counter.Add(ctx, 5, opt)
7777

78-
histogram, err := meter.Float64Histogram("custom_histogram", instrument.WithDescription("a histogram with custom buckets and rename"))
78+
histogram, err := meter.Float64Histogram("custom_histogram", api.WithDescription("a histogram with custom buckets and rename"))
7979
if err != nil {
8080
log.Fatal(err)
8181
}

0 commit comments

Comments
 (0)