You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-06 09:09:44 +02:00
Add the experimental exemplar feature (#4871)
* Add the experimental exemplar feature * Add exemplars to EXPERIMENTAL.md * Add changelog entry * Fix hist buckets > 1 detection * Collect instead of Flush res about to be deleted * Add e2e test * Do not pre-alloc ResourceMetrics This only has a single use. * Fix grammatical error in comment * Add test cases Default and invalid OTEL_METRICS_EXEMPLAR_FILTER. Test sampled and non-sampled context for trace_based. * Comment nCPU * Doc OTEL_METRICS_EXEMPLAR_FILTER
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/sdk/metric/internal/exemplar"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
||||
"go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest"
|
||||
)
|
||||
@@ -59,6 +60,10 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func dropExemplars[N int64 | float64]() exemplar.Reservoir[N] {
|
||||
return exemplar.Drop[N]()
|
||||
}
|
||||
|
||||
func TestBuilderFilter(t *testing.T) {
|
||||
t.Run("Int64", testBuilderFilter[int64]())
|
||||
t.Run("Float64", testBuilderFilter[float64]())
|
||||
@@ -69,20 +74,21 @@ func testBuilderFilter[N int64 | float64]() func(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
value, attr := N(1), alice
|
||||
run := func(b Builder[N], wantA attribute.Set) func(*testing.T) {
|
||||
run := func(b Builder[N], wantF attribute.Set, wantD []attribute.KeyValue) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
t.Helper()
|
||||
|
||||
meas := b.filter(func(_ context.Context, v N, a attribute.Set) {
|
||||
meas := b.filter(func(_ context.Context, v N, f attribute.Set, d []attribute.KeyValue) {
|
||||
assert.Equal(t, value, v, "measured incorrect value")
|
||||
assert.Equal(t, wantA, a, "measured incorrect attributes")
|
||||
assert.Equal(t, wantF, f, "measured incorrect filtered attributes")
|
||||
assert.ElementsMatch(t, wantD, d, "measured incorrect dropped attributes")
|
||||
})
|
||||
meas(context.Background(), value, attr)
|
||||
}
|
||||
}
|
||||
|
||||
t.Run("NoFilter", run(Builder[N]{}, attr))
|
||||
t.Run("Filter", run(Builder[N]{Filter: attrFltr}, fltrAlice))
|
||||
t.Run("NoFilter", run(Builder[N]{}, attr, nil))
|
||||
t.Run("Filter", run(Builder[N]{Filter: attrFltr}, fltrAlice, []attribute.KeyValue{adminTrue}))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user