Skip to content

Commit 4607516

Browse files
authored
Rename metric SDK instrument kind to match API (#3562)
* Rename metric SDK instrument kind to match API Follow up to #3530. * Update CHANGELOG Fix trailing spaces and update PR number.
1 parent a54167d commit 4607516

11 files changed

+171
-163
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
4444
- `traceIDRatioSampler` (given by `TraceIDRatioBased(float64)`) now uses the rightmost bits for sampling decisions,
4545
fixing random sampling when using ID generators like `xray.IDGenerator`
4646
and increasing parity with other language implementations. (#3557)
47+
- The instrument kind names in `go.opentelemetry.io/otel/sdk/metric` are updated to match the API. (#3562)
48+
- `InstrumentKindSyncCounter` is renamed to `InstrumentKindCounter`
49+
- `InstrumentKindSyncUpDownCounter` is renamed to `InstrumentKindUpDownCounter`
50+
- `InstrumentKindSyncHistogram` is renamed to `InstrumentKindHistogram`
51+
- `InstrumentKindAsyncCounter` is renamed to `InstrumentKindObservableCounter`
52+
- `InstrumentKindAsyncUpDownCounter` is renamed to `InstrumentKindObservableUpDownCounter`
53+
- `InstrumentKindAsyncGauge` is renamed to `InstrumentKindObservableGauge`
4754

4855
### Deprecated
4956

sdk/metric/config_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ func TestWithReader(t *testing.T) {
135135
func TestWithView(t *testing.T) {
136136
c := newConfig([]Option{WithView(
137137
NewView(
138-
Instrument{Kind: InstrumentKindAsyncCounter},
138+
Instrument{Kind: InstrumentKindObservableCounter},
139139
Stream{Name: "a"},
140140
),
141141
NewView(
142-
Instrument{Kind: InstrumentKindSyncCounter},
142+
Instrument{Kind: InstrumentKindCounter},
143143
Stream{Name: "b"},
144144
),
145145
)})

sdk/metric/instrument.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,27 @@ const (
4444
// instrumentKindUndefined is an undefined instrument kind, it should not
4545
// be used by any initialized type.
4646
instrumentKindUndefined InstrumentKind = iota // nolint:deadcode,varcheck,unused
47-
// InstrumentKindSyncCounter identifies a group of instruments that record
47+
// InstrumentKindCounter identifies a group of instruments that record
4848
// increasing values synchronously with the code path they are measuring.
49-
InstrumentKindSyncCounter
50-
// InstrumentKindSyncUpDownCounter identifies a group of instruments that
49+
InstrumentKindCounter
50+
// InstrumentKindUpDownCounter identifies a group of instruments that
5151
// record increasing and decreasing values synchronously with the code path
5252
// they are measuring.
53-
InstrumentKindSyncUpDownCounter
54-
// InstrumentKindSyncHistogram identifies a group of instruments that
55-
// record a distribution of values synchronously with the code path they
56-
// are measuring.
57-
InstrumentKindSyncHistogram
58-
// InstrumentKindAsyncCounter identifies a group of instruments that record
59-
// increasing values in an asynchronous callback.
60-
InstrumentKindAsyncCounter
61-
// InstrumentKindAsyncUpDownCounter identifies a group of instruments that
62-
// record increasing and decreasing values in an asynchronous callback.
63-
InstrumentKindAsyncUpDownCounter
64-
// InstrumentKindAsyncGauge identifies a group of instruments that record
65-
// current values in an asynchronous callback.
66-
InstrumentKindAsyncGauge
53+
InstrumentKindUpDownCounter
54+
// InstrumentKindHistogram identifies a group of instruments that record a
55+
// distribution of values synchronously with the code path they are
56+
// measuring.
57+
InstrumentKindHistogram
58+
// InstrumentKindObservableCounter identifies a group of instruments that
59+
// record increasing values in an asynchronous callback.
60+
InstrumentKindObservableCounter
61+
// InstrumentKindObservableUpDownCounter identifies a group of instruments
62+
// that record increasing and decreasing values in an asynchronous
63+
// callback.
64+
InstrumentKindObservableUpDownCounter
65+
// InstrumentKindObservableGauge identifies a group of instruments that
66+
// record current values in an asynchronous callback.
67+
InstrumentKindObservableGauge
6768
)
6869

6970
type nonComparable [0]func() // nolint: unused // This is indeed used.

sdk/metric/meter.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -61,84 +61,84 @@ var _ metric.Meter = (*meter)(nil)
6161
// options. The instrument is used to synchronously record increasing int64
6262
// measurements during a computational operation.
6363
func (m *meter) Int64Counter(name string, options ...instrument.Option) (syncint64.Counter, error) {
64-
return m.instProviderInt64.lookup(InstrumentKindSyncCounter, name, options)
64+
return m.instProviderInt64.lookup(InstrumentKindCounter, name, options)
6565
}
6666

6767
// Int64UpDownCounter returns a new instrument identified by name and
6868
// configured with options. The instrument is used to synchronously record
6969
// int64 measurements during a computational operation.
7070
func (m *meter) Int64UpDownCounter(name string, options ...instrument.Option) (syncint64.UpDownCounter, error) {
71-
return m.instProviderInt64.lookup(InstrumentKindSyncUpDownCounter, name, options)
71+
return m.instProviderInt64.lookup(InstrumentKindUpDownCounter, name, options)
7272
}
7373

7474
// Int64Histogram returns a new instrument identified by name and configured
7575
// with options. The instrument is used to synchronously record the
7676
// distribution of int64 measurements during a computational operation.
7777
func (m *meter) Int64Histogram(name string, options ...instrument.Option) (syncint64.Histogram, error) {
78-
return m.instProviderInt64.lookup(InstrumentKindSyncHistogram, name, options)
78+
return m.instProviderInt64.lookup(InstrumentKindHistogram, name, options)
7979
}
8080

8181
// Int64ObservableCounter returns a new instrument identified by name and
8282
// configured with options. The instrument is used to asynchronously record
8383
// increasing int64 measurements once per a measurement collection cycle.
8484
func (m *meter) Int64ObservableCounter(name string, options ...instrument.Option) (asyncint64.Counter, error) {
85-
return m.instProviderInt64.lookup(InstrumentKindAsyncCounter, name, options)
85+
return m.instProviderInt64.lookup(InstrumentKindObservableCounter, name, options)
8686
}
8787

8888
// Int64ObservableUpDownCounter returns a new instrument identified by name and
8989
// configured with options. The instrument is used to asynchronously record
9090
// int64 measurements once per a measurement collection cycle.
9191
func (m *meter) Int64ObservableUpDownCounter(name string, options ...instrument.Option) (asyncint64.UpDownCounter, error) {
92-
return m.instProviderInt64.lookup(InstrumentKindAsyncUpDownCounter, name, options)
92+
return m.instProviderInt64.lookup(InstrumentKindObservableUpDownCounter, name, options)
9393
}
9494

9595
// Int64ObservableGauge returns a new instrument identified by name and
9696
// configured with options. The instrument is used to asynchronously record
9797
// instantaneous int64 measurements once per a measurement collection cycle.
9898
func (m *meter) Int64ObservableGauge(name string, options ...instrument.Option) (asyncint64.Gauge, error) {
99-
return m.instProviderInt64.lookup(InstrumentKindAsyncGauge, name, options)
99+
return m.instProviderInt64.lookup(InstrumentKindObservableGauge, name, options)
100100
}
101101

102102
// Float64Counter returns a new instrument identified by name and configured
103103
// with options. The instrument is used to synchronously record increasing
104104
// float64 measurements during a computational operation.
105105
func (m *meter) Float64Counter(name string, options ...instrument.Option) (syncfloat64.Counter, error) {
106-
return m.instProviderFloat64.lookup(InstrumentKindSyncCounter, name, options)
106+
return m.instProviderFloat64.lookup(InstrumentKindCounter, name, options)
107107
}
108108

109109
// Float64UpDownCounter returns a new instrument identified by name and
110110
// configured with options. The instrument is used to synchronously record
111111
// float64 measurements during a computational operation.
112112
func (m *meter) Float64UpDownCounter(name string, options ...instrument.Option) (syncfloat64.UpDownCounter, error) {
113-
return m.instProviderFloat64.lookup(InstrumentKindSyncUpDownCounter, name, options)
113+
return m.instProviderFloat64.lookup(InstrumentKindUpDownCounter, name, options)
114114
}
115115

116116
// Float64Histogram returns a new instrument identified by name and configured
117117
// with options. The instrument is used to synchronously record the
118118
// distribution of float64 measurements during a computational operation.
119119
func (m *meter) Float64Histogram(name string, options ...instrument.Option) (syncfloat64.Histogram, error) {
120-
return m.instProviderFloat64.lookup(InstrumentKindSyncHistogram, name, options)
120+
return m.instProviderFloat64.lookup(InstrumentKindHistogram, name, options)
121121
}
122122

123123
// Float64ObservableCounter returns a new instrument identified by name and
124124
// configured with options. The instrument is used to asynchronously record
125125
// increasing float64 measurements once per a measurement collection cycle.
126126
func (m *meter) Float64ObservableCounter(name string, options ...instrument.Option) (asyncfloat64.Counter, error) {
127-
return m.instProviderFloat64.lookup(InstrumentKindAsyncCounter, name, options)
127+
return m.instProviderFloat64.lookup(InstrumentKindObservableCounter, name, options)
128128
}
129129

130130
// Float64ObservableUpDownCounter returns a new instrument identified by name
131131
// and configured with options. The instrument is used to asynchronously record
132132
// float64 measurements once per a measurement collection cycle.
133133
func (m *meter) Float64ObservableUpDownCounter(name string, options ...instrument.Option) (asyncfloat64.UpDownCounter, error) {
134-
return m.instProviderFloat64.lookup(InstrumentKindAsyncUpDownCounter, name, options)
134+
return m.instProviderFloat64.lookup(InstrumentKindObservableUpDownCounter, name, options)
135135
}
136136

137137
// Float64ObservableGauge returns a new instrument identified by name and
138138
// configured with options. The instrument is used to asynchronously record
139139
// instantaneous float64 measurements once per a measurement collection cycle.
140140
func (m *meter) Float64ObservableGauge(name string, options ...instrument.Option) (asyncfloat64.Gauge, error) {
141-
return m.instProviderFloat64.lookup(InstrumentKindAsyncGauge, name, options)
141+
return m.instProviderFloat64.lookup(InstrumentKindObservableGauge, name, options)
142142
}
143143

144144
// RegisterCallback registers the function f to be called when any of the

sdk/metric/meter_test.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func TestMeterCreatesInstruments(t *testing.T) {
174174
want metricdata.Metrics
175175
}{
176176
{
177-
name: "AsyncInt64Count",
177+
name: "ObservableInt64Count",
178178
fn: func(t *testing.T, m metric.Meter) {
179179
ctr, err := m.Int64ObservableCounter("aint")
180180
assert.NoError(t, err)
@@ -198,7 +198,7 @@ func TestMeterCreatesInstruments(t *testing.T) {
198198
},
199199
},
200200
{
201-
name: "AsyncInt64UpDownCount",
201+
name: "ObservableInt64UpDownCount",
202202
fn: func(t *testing.T, m metric.Meter) {
203203
ctr, err := m.Int64ObservableUpDownCounter("aint")
204204
assert.NoError(t, err)
@@ -222,7 +222,7 @@ func TestMeterCreatesInstruments(t *testing.T) {
222222
},
223223
},
224224
{
225-
name: "AsyncInt64Gauge",
225+
name: "ObservableInt64Gauge",
226226
fn: func(t *testing.T, m metric.Meter) {
227227
gauge, err := m.Int64ObservableGauge("agauge")
228228
assert.NoError(t, err)
@@ -244,7 +244,7 @@ func TestMeterCreatesInstruments(t *testing.T) {
244244
},
245245
},
246246
{
247-
name: "AsyncFloat64Count",
247+
name: "ObservableFloat64Count",
248248
fn: func(t *testing.T, m metric.Meter) {
249249
ctr, err := m.Float64ObservableCounter("afloat")
250250
assert.NoError(t, err)
@@ -268,7 +268,7 @@ func TestMeterCreatesInstruments(t *testing.T) {
268268
},
269269
},
270270
{
271-
name: "AsyncFloat64UpDownCount",
271+
name: "ObservableFloat64UpDownCount",
272272
fn: func(t *testing.T, m metric.Meter) {
273273
ctr, err := m.Float64ObservableUpDownCounter("afloat")
274274
assert.NoError(t, err)
@@ -292,7 +292,7 @@ func TestMeterCreatesInstruments(t *testing.T) {
292292
},
293293
},
294294
{
295-
name: "AsyncFloat64Gauge",
295+
name: "ObservableFloat64Gauge",
296296
fn: func(t *testing.T, m metric.Meter) {
297297
gauge, err := m.Float64ObservableGauge("agauge")
298298
assert.NoError(t, err)
@@ -632,7 +632,7 @@ func TestAttributeFilter(t *testing.T) {
632632
wantMetric metricdata.Metrics
633633
}{
634634
{
635-
name: "AsyncFloat64Counter",
635+
name: "ObservableFloat64Counter",
636636
register: func(t *testing.T, mtr metric.Meter) error {
637637
ctr, err := mtr.Float64ObservableCounter("afcounter")
638638
if err != nil {
@@ -659,7 +659,7 @@ func TestAttributeFilter(t *testing.T) {
659659
},
660660
},
661661
{
662-
name: "AsyncFloat64UpDownCounter",
662+
name: "ObservableFloat64UpDownCounter",
663663
register: func(t *testing.T, mtr metric.Meter) error {
664664
ctr, err := mtr.Float64ObservableUpDownCounter("afupdowncounter")
665665
if err != nil {
@@ -686,7 +686,7 @@ func TestAttributeFilter(t *testing.T) {
686686
},
687687
},
688688
{
689-
name: "AsyncFloat64Gauge",
689+
name: "ObservableFloat64Gauge",
690690
register: func(t *testing.T, mtr metric.Meter) error {
691691
ctr, err := mtr.Float64ObservableGauge("afgauge")
692692
if err != nil {
@@ -711,7 +711,7 @@ func TestAttributeFilter(t *testing.T) {
711711
},
712712
},
713713
{
714-
name: "AsyncInt64Counter",
714+
name: "ObservableInt64Counter",
715715
register: func(t *testing.T, mtr metric.Meter) error {
716716
ctr, err := mtr.Int64ObservableCounter("aicounter")
717717
if err != nil {
@@ -738,7 +738,7 @@ func TestAttributeFilter(t *testing.T) {
738738
},
739739
},
740740
{
741-
name: "AsyncInt64UpDownCounter",
741+
name: "ObservableInt64UpDownCounter",
742742
register: func(t *testing.T, mtr metric.Meter) error {
743743
ctr, err := mtr.Int64ObservableUpDownCounter("aiupdowncounter")
744744
if err != nil {
@@ -765,7 +765,7 @@ func TestAttributeFilter(t *testing.T) {
765765
},
766766
},
767767
{
768-
name: "AsyncInt64Gauge",
768+
name: "ObservableInt64Gauge",
769769
register: func(t *testing.T, mtr metric.Meter) error {
770770
ctr, err := mtr.Int64ObservableGauge("aigauge")
771771
if err != nil {
@@ -1006,13 +1006,13 @@ func BenchmarkInstrumentCreation(b *testing.B) {
10061006
b.ResetTimer()
10071007

10081008
for n := 0; n < b.N; n++ {
1009-
aiCounter, _ = meter.Int64ObservableCounter("async.int64.counter")
1010-
aiUpDownCounter, _ = meter.Int64ObservableUpDownCounter("async.int64.up.down.counter")
1011-
aiGauge, _ = meter.Int64ObservableGauge("async.int64.gauge")
1009+
aiCounter, _ = meter.Int64ObservableCounter("observable.int64.counter")
1010+
aiUpDownCounter, _ = meter.Int64ObservableUpDownCounter("observable.int64.up.down.counter")
1011+
aiGauge, _ = meter.Int64ObservableGauge("observable.int64.gauge")
10121012

1013-
afCounter, _ = meter.Float64ObservableCounter("async.float64.counter")
1014-
afUpDownCounter, _ = meter.Float64ObservableUpDownCounter("async.float64.up.down.counter")
1015-
afGauge, _ = meter.Float64ObservableGauge("async.float64.gauge")
1013+
afCounter, _ = meter.Float64ObservableCounter("observable.float64.counter")
1014+
afUpDownCounter, _ = meter.Float64ObservableUpDownCounter("observable.float64.up.down.counter")
1015+
afGauge, _ = meter.Float64ObservableGauge("observable.float64.gauge")
10161016

10171017
siCounter, _ = meter.Int64Counter("sync.int64.counter")
10181018
siUpDownCounter, _ = meter.Int64UpDownCounter("sync.int64.up.down.counter")

sdk/metric/pipeline.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func (i *inserter[N]) instrumentID(kind InstrumentKind, stream Stream) instrumen
332332
}
333333

334334
switch kind {
335-
case InstrumentKindAsyncCounter, InstrumentKindSyncCounter, InstrumentKindSyncHistogram:
335+
case InstrumentKindObservableCounter, InstrumentKindCounter, InstrumentKindHistogram:
336336
id.Monotonic = true
337337
}
338338

@@ -350,7 +350,7 @@ func (i *inserter[N]) aggregator(agg aggregation.Aggregation, kind InstrumentKin
350350
return internal.NewLastValue[N](), nil
351351
case aggregation.Sum:
352352
switch kind {
353-
case InstrumentKindAsyncCounter, InstrumentKindAsyncUpDownCounter:
353+
case InstrumentKindObservableCounter, InstrumentKindObservableUpDownCounter:
354354
// Asynchronous counters and up-down-counters are defined to record
355355
// the absolute value of the count:
356356
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#asynchronous-counter-creation
@@ -388,34 +388,34 @@ func (i *inserter[N]) aggregator(agg aggregation.Aggregation, kind InstrumentKin
388388
// isAggregatorCompatible checks if the aggregation can be used by the instrument.
389389
// Current compatibility:
390390
//
391-
// | Instrument Kind | Drop | LastValue | Sum | Histogram | Exponential Histogram |
392-
// |----------------------|------|-----------|-----|-----------|-----------------------|
393-
// | Sync Counter | X | | X | X | X |
394-
// | Sync UpDown Counter | X | | X | | |
395-
// | Sync Histogram | X | | X | X | X |
396-
// | Async Counter | X | | X | | |
397-
// | Async UpDown Counter | X | | X | | |
398-
// | Async Gauge | X | X | | | |.
391+
// | Instrument Kind | Drop | LastValue | Sum | Histogram | Exponential Histogram |
392+
// |--------------------------|------|-----------|-----|-----------|-----------------------|
393+
// | Counter | X | | X | X | X |
394+
// | UpDownCounter | X | | X | | |
395+
// | Histogram | X | | X | X | X |
396+
// | Observable Counter | X | | X | | |
397+
// | Observable UpDownCounter | X | | X | | |
398+
// | Observable Gauge | X | X | | | |.
399399
func isAggregatorCompatible(kind InstrumentKind, agg aggregation.Aggregation) error {
400400
switch agg.(type) {
401401
case aggregation.ExplicitBucketHistogram:
402-
if kind == InstrumentKindSyncCounter || kind == InstrumentKindSyncHistogram {
402+
if kind == InstrumentKindCounter || kind == InstrumentKindHistogram {
403403
return nil
404404
}
405405
// TODO: review need for aggregation check after
406406
// https://github.com/open-telemetry/opentelemetry-specification/issues/2710
407407
return errIncompatibleAggregation
408408
case aggregation.Sum:
409409
switch kind {
410-
case InstrumentKindAsyncCounter, InstrumentKindAsyncUpDownCounter, InstrumentKindSyncCounter, InstrumentKindSyncHistogram, InstrumentKindSyncUpDownCounter:
410+
case InstrumentKindObservableCounter, InstrumentKindObservableUpDownCounter, InstrumentKindCounter, InstrumentKindHistogram, InstrumentKindUpDownCounter:
411411
return nil
412412
default:
413413
// TODO: review need for aggregation check after
414414
// https://github.com/open-telemetry/opentelemetry-specification/issues/2710
415415
return errIncompatibleAggregation
416416
}
417417
case aggregation.LastValue:
418-
if kind == InstrumentKindAsyncGauge {
418+
if kind == InstrumentKindObservableGauge {
419419
return nil
420420
}
421421
// TODO: review need for aggregation check after

0 commit comments

Comments
 (0)