1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-12-01 23:12:29 +02:00

Add the synchronous gauge to the metric API and SDK (#5304)

Resolve #5225 

The specification has [added a synchronous gauge
instrument](https://github.com/open-telemetry/opentelemetry-specification/pull/3540).
That instrument has now been
[stabilized](https://github.com/open-telemetry/opentelemetry-specification/pull/4019),
and that stabilization is included in the [next
release](https://github.com/open-telemetry/opentelemetry-specification/pull/4034).

This adds the new synchronous gauge instrument to the metric API and all
implementation we publish.

This change will be a breaking change for any SDK developer. The
`embedded` package is updated to ensure our compatibility guarantees are
meet.

---------

Co-authored-by: David Ashpole <dashpole@google.com>
This commit is contained in:
Tyler Yahn
2024-05-16 09:56:40 -07:00
committed by GitHub
parent 166b3473dd
commit dafe137bbe
24 changed files with 416 additions and 12 deletions

View File

@@ -149,6 +149,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
{Name: "foo", Kind: InstrumentKindCounter},
{Name: "foo", Kind: InstrumentKindUpDownCounter},
{Name: "foo", Kind: InstrumentKindHistogram},
{Name: "foo", Kind: InstrumentKindGauge},
{Name: "foo", Kind: InstrumentKindObservableCounter},
{Name: "foo", Kind: InstrumentKindObservableUpDownCounter},
{Name: "foo", Kind: InstrumentKindObservableGauge},
@@ -184,6 +185,12 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
inst: instruments[InstrumentKindHistogram],
validate: assertHist[N](metricdata.DeltaTemporality),
},
{
name: "Default/Delta/Gauge",
reader: NewManualReader(WithTemporalitySelector(deltaTemporalitySelector)),
inst: instruments[InstrumentKindGauge],
validate: assertLastValue[N],
},
{
name: "Default/Delta/PrecomputedSum/Monotonic",
reader: NewManualReader(WithTemporalitySelector(deltaTemporalitySelector)),
@@ -220,6 +227,12 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
inst: instruments[InstrumentKindHistogram],
validate: assertHist[N](metricdata.CumulativeTemporality),
},
{
name: "Default/Cumulative/Gauge",
reader: NewManualReader(),
inst: instruments[InstrumentKindGauge],
validate: assertLastValue[N],
},
{
name: "Default/Cumulative/PrecomputedSum/Monotonic",
reader: NewManualReader(),
@@ -307,6 +320,12 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
inst: instruments[InstrumentKindHistogram],
validate: assertHist[N](metricdata.CumulativeTemporality),
},
{
name: "Reader/Default/Cumulative/Gauge",
reader: NewManualReader(WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} })),
inst: instruments[InstrumentKindGauge],
validate: assertLastValue[N],
},
{
name: "Reader/Default/Cumulative/PrecomputedSum/Monotonic",
reader: NewManualReader(WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} })),
@@ -699,6 +718,32 @@ func TestIsAggregatorCompatible(t *testing.T) {
kind: InstrumentKindHistogram,
agg: AggregationBase2ExponentialHistogram{},
},
{
name: "SyncGauge and Drop",
kind: InstrumentKindGauge,
agg: AggregationDrop{},
},
{
name: "SyncGauge and LastValue",
kind: InstrumentKindGauge,
agg: AggregationLastValue{},
},
{
name: "SyncGauge and Sum",
kind: InstrumentKindGauge,
agg: AggregationSum{},
want: errIncompatibleAggregation,
},
{
name: "SyncGauge and ExplicitBucketHistogram",
kind: InstrumentKindGauge,
agg: AggregationExplicitBucketHistogram{},
},
{
name: "SyncGauge and ExponentialHistogram",
kind: InstrumentKindGauge,
agg: AggregationBase2ExponentialHistogram{},
},
{
name: "ObservableCounter and Drop",
kind: InstrumentKindObservableCounter,