Skip to content

Commit 0d3dddc

Browse files
authored
Fix exported instrument kind const value change (open-telemetry#5385)
open-telemetry#5304 introduced the following incompatible changes: - `InstrumentKindObservableCounter`: value changed from 4 to 5 - `InstrumentKindObservableGauge`: value changed from 6 to 7 - `InstrumentKindObservableUpDownCounter`: value changed from 5 to 6 This reverts that change, making `InstrumentKindGauge` explicitly `7`. Additionally, this removes the use of `iota` to prevent this kind of breaking change from being accidentally introduced in the future.
1 parent 7aae7a8 commit 0d3dddc

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

sdk/metric/instrument.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,32 @@ type InstrumentKind uint8
3030
const (
3131
// instrumentKindUndefined is an undefined instrument kind, it should not
3232
// be used by any initialized type.
33-
instrumentKindUndefined InstrumentKind = iota // nolint:deadcode,varcheck,unused
33+
instrumentKindUndefined InstrumentKind = 0 // nolint:deadcode,varcheck,unused
3434
// InstrumentKindCounter identifies a group of instruments that record
3535
// increasing values synchronously with the code path they are measuring.
36-
InstrumentKindCounter
36+
InstrumentKindCounter InstrumentKind = 1
3737
// InstrumentKindUpDownCounter identifies a group of instruments that
3838
// record increasing and decreasing values synchronously with the code path
3939
// they are measuring.
40-
InstrumentKindUpDownCounter
40+
InstrumentKindUpDownCounter InstrumentKind = 2
4141
// InstrumentKindHistogram identifies a group of instruments that record a
4242
// distribution of values synchronously with the code path they are
4343
// measuring.
44-
InstrumentKindHistogram
45-
// InstrumentKindGauge identifies a group of instruments that record
46-
// instantaneous values synchronously with the code path they are
47-
// measuring.
48-
InstrumentKindGauge
44+
InstrumentKindHistogram InstrumentKind = 3
4945
// InstrumentKindObservableCounter identifies a group of instruments that
5046
// record increasing values in an asynchronous callback.
51-
InstrumentKindObservableCounter
47+
InstrumentKindObservableCounter InstrumentKind = 4
5248
// InstrumentKindObservableUpDownCounter identifies a group of instruments
5349
// that record increasing and decreasing values in an asynchronous
5450
// callback.
55-
InstrumentKindObservableUpDownCounter
51+
InstrumentKindObservableUpDownCounter InstrumentKind = 5
5652
// InstrumentKindObservableGauge identifies a group of instruments that
5753
// record current values in an asynchronous callback.
58-
InstrumentKindObservableGauge
54+
InstrumentKindObservableGauge InstrumentKind = 6
55+
// InstrumentKindGauge identifies a group of instruments that record
56+
// instantaneous values synchronously with the code path they are
57+
// measuring.
58+
InstrumentKindGauge InstrumentKind = 7
5959
)
6060

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

sdk/metric/instrumentkind_string.go

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/metric/pipeline_registry_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,14 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
145145
)
146146

147147
instruments := []Instrument{
148-
{Name: "foo", Kind: InstrumentKind(0)}, // Unknown kind
149-
{Name: "foo", Kind: InstrumentKindCounter},
150-
{Name: "foo", Kind: InstrumentKindUpDownCounter},
151-
{Name: "foo", Kind: InstrumentKindHistogram},
152-
{Name: "foo", Kind: InstrumentKindGauge},
153-
{Name: "foo", Kind: InstrumentKindObservableCounter},
154-
{Name: "foo", Kind: InstrumentKindObservableUpDownCounter},
155-
{Name: "foo", Kind: InstrumentKindObservableGauge},
148+
InstrumentKind(0): {Name: "foo", Kind: InstrumentKind(0)}, // Unknown kind
149+
InstrumentKindCounter: {Name: "foo", Kind: InstrumentKindCounter},
150+
InstrumentKindUpDownCounter: {Name: "foo", Kind: InstrumentKindUpDownCounter},
151+
InstrumentKindHistogram: {Name: "foo", Kind: InstrumentKindHistogram},
152+
InstrumentKindGauge: {Name: "foo", Kind: InstrumentKindGauge},
153+
InstrumentKindObservableCounter: {Name: "foo", Kind: InstrumentKindObservableCounter},
154+
InstrumentKindObservableUpDownCounter: {Name: "foo", Kind: InstrumentKindObservableUpDownCounter},
155+
InstrumentKindObservableGauge: {Name: "foo", Kind: InstrumentKindObservableGauge},
156156
}
157157

158158
testcases := []struct {

0 commit comments

Comments
 (0)