Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Sep 30, 2024
1 parent 06303f1 commit 9e2cbc5
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions sdk/metric/meter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/metric/exemplar"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest"
"go.opentelemetry.io/otel/sdk/resource"
Expand Down Expand Up @@ -2427,3 +2428,53 @@ func TestDuplicateInstrumentCreation(t *testing.T) {
})
}
}

func TestExemplarFilter(t *testing.T) {
rdr := NewManualReader()
mp := NewMeterProvider(
WithReader(rdr),
// Passing AlwaysOnFilter causes collection of the exemplar for the
// counter increment below.
WithExemplarFilter(exemplar.AlwaysOnFilter),
)

m1 := mp.Meter("scope")
ctr1, err := m1.Float64Counter("ctr")
assert.NoError(t, err)
ctr1.Add(context.Background(), 1.0)

want := metricdata.ResourceMetrics{
Resource: resource.Default(),
ScopeMetrics: []metricdata.ScopeMetrics{
{
Scope: instrumentation.Scope{
Name: "scope",
},
Metrics: []metricdata.Metrics{
{
Name: "ctr",
Data: metricdata.Sum[float64]{
Temporality: metricdata.CumulativeTemporality,
IsMonotonic: true,
DataPoints: []metricdata.DataPoint[float64]{
{
Value: 1.0,
Exemplars: []metricdata.Exemplar[float64]{
{
Value: 1.0,
},
},
},
},
},
},
},
},
},
}

got := metricdata.ResourceMetrics{}
err = rdr.Collect(context.Background(), &got)
assert.NoError(t, err)
metricdatatest.AssertEqual(t, want, got, metricdatatest.IgnoreTimestamp())
}

0 comments on commit 9e2cbc5

Please sign in to comment.