Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring the exemplar filter on the metrics SDK #5850

Merged
merged 15 commits into from
Oct 11, 2024
Merged
Prev Previous commit
Next Next commit
add unit test
dashpole committed Oct 4, 2024
commit 1ca96715aa33be0e44de3406ed937a5e8fb36932
51 changes: 51 additions & 0 deletions sdk/metric/meter_test.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -2462,3 +2463,53 @@ func TestMeterProviderDelegation(t *testing.T) {
otel.SetMeterProvider(provider)
})
}

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())
}