diff --git a/sdk/metric/internal/aggregate/aggregate_test.go b/sdk/metric/internal/aggregate/aggregate_test.go index c426f1caa74..59d72d37e08 100644 --- a/sdk/metric/internal/aggregate/aggregate_test.go +++ b/sdk/metric/internal/aggregate/aggregate_test.go @@ -100,8 +100,8 @@ func testBuilderFilter[N int64 | float64]() func(t *testing.T) { } } - t.Run("NoFilter", run(Builder[N]{}, attr, nil)) - t.Run("Filter", run(Builder[N]{Filter: attrFltr}, fltrAlice, []attribute.KeyValue{adminTrue})) + t.Run("NoFilter", run(Builder[N]{ExemplarFilter: exemplar.AlwaysOffFilter}, attr, nil)) + t.Run("Filter", run(Builder[N]{ExemplarFilter: exemplar.AlwaysOffFilter, Filter: attrFltr}, fltrAlice, []attribute.KeyValue{adminTrue})) } } diff --git a/sdk/metric/internal/aggregate/exponential_histogram_test.go b/sdk/metric/internal/aggregate/exponential_histogram_test.go index 9ede71ac88c..deb66ccacf1 100644 --- a/sdk/metric/internal/aggregate/exponential_histogram_test.go +++ b/sdk/metric/internal/aggregate/exponential_histogram_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/internal/global" + "go.opentelemetry.io/otel/sdk/metric/exemplar" "go.opentelemetry.io/otel/sdk/metric/metricdata" ) @@ -682,22 +683,26 @@ func BenchmarkExponentialHistogram(b *testing.B) { b.Run("Int64/Cumulative", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) { return Builder[int64]{ - Temporality: metricdata.CumulativeTemporality, + Temporality: metricdata.CumulativeTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.ExponentialBucketHistogram(maxSize, maxScale, noMinMax, noSum) })) b.Run("Int64/Delta", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) { return Builder[int64]{ - Temporality: metricdata.DeltaTemporality, + Temporality: metricdata.DeltaTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.ExponentialBucketHistogram(maxSize, maxScale, noMinMax, noSum) })) b.Run("Float64/Cumulative", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) { return Builder[float64]{ - Temporality: metricdata.CumulativeTemporality, + Temporality: metricdata.CumulativeTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.ExponentialBucketHistogram(maxSize, maxScale, noMinMax, noSum) })) b.Run("Float64/Delta", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) { return Builder[float64]{ - Temporality: metricdata.DeltaTemporality, + Temporality: metricdata.DeltaTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.ExponentialBucketHistogram(maxSize, maxScale, noMinMax, noSum) })) } @@ -747,6 +752,7 @@ func testDeltaExpoHist[N int64 | float64]() func(t *testing.T) { Temporality: metricdata.DeltaTemporality, Filter: attrFltr, AggregationLimit: 2, + ExemplarFilter: exemplar.AlwaysOffFilter, }.ExponentialBucketHistogram(4, 20, false, false) ctx := context.Background() return test[N](in, out, []teststep[N]{ @@ -874,6 +880,7 @@ func testCumulativeExpoHist[N int64 | float64]() func(t *testing.T) { Temporality: metricdata.CumulativeTemporality, Filter: attrFltr, AggregationLimit: 2, + ExemplarFilter: exemplar.AlwaysOffFilter, }.ExponentialBucketHistogram(4, 20, false, false) ctx := context.Background() return test[N](in, out, []teststep[N]{ diff --git a/sdk/metric/internal/aggregate/filtered_reservoir.go b/sdk/metric/internal/aggregate/filtered_reservoir.go index 91035c9d100..a600eb1e413 100644 --- a/sdk/metric/internal/aggregate/filtered_reservoir.go +++ b/sdk/metric/internal/aggregate/filtered_reservoir.go @@ -28,7 +28,7 @@ func newFilteredExemplarReservoir[N int64 | float64](f exemplar.Filter, r exempl } func (f *filteredExemplarReservoir[N]) Offer(ctx context.Context, val N, attr []attribute.KeyValue) { - if f.filter != nil && f.filter(ctx) { + if f.filter(ctx) { // only record the current time if we are sampling this measurement. f.reservoir.Offer(ctx, time.Now(), exemplar.NewValue(val), attr) } diff --git a/sdk/metric/internal/aggregate/histogram_test.go b/sdk/metric/internal/aggregate/histogram_test.go index 4484a33fa45..769fc07fa11 100644 --- a/sdk/metric/internal/aggregate/histogram_test.go +++ b/sdk/metric/internal/aggregate/histogram_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/sdk/metric/exemplar" "go.opentelemetry.io/otel/sdk/metric/metricdata" "go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest" ) @@ -54,6 +55,7 @@ func testDeltaHist[N int64 | float64](c conf[N]) func(t *testing.T) { Temporality: metricdata.DeltaTemporality, Filter: attrFltr, AggregationLimit: 3, + ExemplarFilter: exemplar.AlwaysOffFilter, }.ExplicitBucketHistogram(bounds, noMinMax, c.noSum) ctx := context.Background() return test[N](in, out, []teststep[N]{ @@ -141,6 +143,7 @@ func testCumulativeHist[N int64 | float64](c conf[N]) func(t *testing.T) { Temporality: metricdata.CumulativeTemporality, Filter: attrFltr, AggregationLimit: 3, + ExemplarFilter: exemplar.AlwaysOffFilter, }.ExplicitBucketHistogram(bounds, noMinMax, c.noSum) ctx := context.Background() return test[N](in, out, []teststep[N]{ @@ -375,22 +378,26 @@ func TestDeltaHistogramReset(t *testing.T) { func BenchmarkHistogram(b *testing.B) { b.Run("Int64/Cumulative", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) { return Builder[int64]{ - Temporality: metricdata.CumulativeTemporality, + Temporality: metricdata.CumulativeTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.ExplicitBucketHistogram(bounds, noMinMax, false) })) b.Run("Int64/Delta", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) { return Builder[int64]{ - Temporality: metricdata.DeltaTemporality, + Temporality: metricdata.DeltaTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.ExplicitBucketHistogram(bounds, noMinMax, false) })) b.Run("Float64/Cumulative", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) { return Builder[float64]{ - Temporality: metricdata.CumulativeTemporality, + Temporality: metricdata.CumulativeTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.ExplicitBucketHistogram(bounds, noMinMax, false) })) b.Run("Float64/Delta", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) { return Builder[float64]{ - Temporality: metricdata.DeltaTemporality, + Temporality: metricdata.DeltaTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.ExplicitBucketHistogram(bounds, noMinMax, false) })) } diff --git a/sdk/metric/internal/aggregate/lastvalue_test.go b/sdk/metric/internal/aggregate/lastvalue_test.go index 77e0d283ba0..349ed337c50 100644 --- a/sdk/metric/internal/aggregate/lastvalue_test.go +++ b/sdk/metric/internal/aggregate/lastvalue_test.go @@ -7,6 +7,7 @@ import ( "context" "testing" + "go.opentelemetry.io/otel/sdk/metric/exemplar" "go.opentelemetry.io/otel/sdk/metric/metricdata" ) @@ -39,6 +40,7 @@ func testDeltaLastValue[N int64 | float64]() func(*testing.T) { Temporality: metricdata.DeltaTemporality, Filter: attrFltr, AggregationLimit: 3, + ExemplarFilter: exemplar.AlwaysOffFilter, }.LastValue() ctx := context.Background() return test[N](in, out, []teststep[N]{ @@ -143,6 +145,7 @@ func testCumulativeLastValue[N int64 | float64]() func(*testing.T) { Temporality: metricdata.CumulativeTemporality, Filter: attrFltr, AggregationLimit: 3, + ExemplarFilter: exemplar.AlwaysOffFilter, }.LastValue() ctx := context.Background() return test[N](in, out, []teststep[N]{ @@ -265,6 +268,7 @@ func testDeltaPrecomputedLastValue[N int64 | float64]() func(*testing.T) { Temporality: metricdata.DeltaTemporality, Filter: attrFltr, AggregationLimit: 3, + ExemplarFilter: exemplar.AlwaysOffFilter, }.PrecomputedLastValue() ctx := context.Background() return test[N](in, out, []teststep[N]{ @@ -369,6 +373,7 @@ func testCumulativePrecomputedLastValue[N int64 | float64]() func(*testing.T) { Temporality: metricdata.CumulativeTemporality, Filter: attrFltr, AggregationLimit: 3, + ExemplarFilter: exemplar.AlwaysOffFilter, }.PrecomputedLastValue() ctx := context.Background() return test[N](in, out, []teststep[N]{ @@ -469,6 +474,8 @@ func testCumulativePrecomputedLastValue[N int64 | float64]() func(*testing.T) { } func BenchmarkLastValue(b *testing.B) { - b.Run("Int64", benchmarkAggregate(Builder[int64]{}.PrecomputedLastValue)) - b.Run("Float64", benchmarkAggregate(Builder[float64]{}.PrecomputedLastValue)) + b.Run("Int64", benchmarkAggregate(Builder[int64]{ + ExemplarFilter: exemplar.AlwaysOffFilter}.PrecomputedLastValue)) + b.Run("Float64", benchmarkAggregate(Builder[float64]{ + ExemplarFilter: exemplar.AlwaysOffFilter}.PrecomputedLastValue)) } diff --git a/sdk/metric/internal/aggregate/sum_test.go b/sdk/metric/internal/aggregate/sum_test.go index bb825e18375..524af5d0407 100644 --- a/sdk/metric/internal/aggregate/sum_test.go +++ b/sdk/metric/internal/aggregate/sum_test.go @@ -7,6 +7,7 @@ import ( "context" "testing" + "go.opentelemetry.io/otel/sdk/metric/exemplar" "go.opentelemetry.io/otel/sdk/metric/metricdata" ) @@ -44,6 +45,7 @@ func testDeltaSum[N int64 | float64]() func(t *testing.T) { Temporality: metricdata.DeltaTemporality, Filter: attrFltr, AggregationLimit: 3, + ExemplarFilter: exemplar.AlwaysOffFilter, }.Sum(mono) ctx := context.Background() return test[N](in, out, []teststep[N]{ @@ -172,6 +174,7 @@ func testCumulativeSum[N int64 | float64]() func(t *testing.T) { Temporality: metricdata.CumulativeTemporality, Filter: attrFltr, AggregationLimit: 3, + ExemplarFilter: exemplar.AlwaysOffFilter, }.Sum(mono) ctx := context.Background() return test[N](in, out, []teststep[N]{ @@ -286,6 +289,7 @@ func testDeltaPrecomputedSum[N int64 | float64]() func(t *testing.T) { Temporality: metricdata.DeltaTemporality, Filter: attrFltr, AggregationLimit: 3, + ExemplarFilter: exemplar.AlwaysOffFilter, }.PrecomputedSum(mono) ctx := context.Background() return test[N](in, out, []teststep[N]{ @@ -415,6 +419,7 @@ func testCumulativePrecomputedSum[N int64 | float64]() func(t *testing.T) { Temporality: metricdata.CumulativeTemporality, Filter: attrFltr, AggregationLimit: 3, + ExemplarFilter: exemplar.AlwaysOffFilter, }.PrecomputedSum(mono) ctx := context.Background() return test[N](in, out, []teststep[N]{ @@ -544,43 +549,51 @@ func BenchmarkSum(b *testing.B) { // performance, therefore, only monotonic=false is benchmarked here. b.Run("Int64/Cumulative", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) { return Builder[int64]{ - Temporality: metricdata.CumulativeTemporality, + Temporality: metricdata.CumulativeTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.Sum(false) })) b.Run("Int64/Delta", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) { return Builder[int64]{ - Temporality: metricdata.DeltaTemporality, + Temporality: metricdata.DeltaTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.Sum(false) })) b.Run("Float64/Cumulative", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) { return Builder[float64]{ - Temporality: metricdata.CumulativeTemporality, + Temporality: metricdata.CumulativeTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.Sum(false) })) b.Run("Float64/Delta", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) { return Builder[float64]{ - Temporality: metricdata.DeltaTemporality, + Temporality: metricdata.DeltaTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.Sum(false) })) b.Run("Precomputed/Int64/Cumulative", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) { return Builder[int64]{ - Temporality: metricdata.CumulativeTemporality, + Temporality: metricdata.CumulativeTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.PrecomputedSum(false) })) b.Run("Precomputed/Int64/Delta", benchmarkAggregate(func() (Measure[int64], ComputeAggregation) { return Builder[int64]{ - Temporality: metricdata.DeltaTemporality, + Temporality: metricdata.DeltaTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.PrecomputedSum(false) })) b.Run("Precomputed/Float64/Cumulative", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) { return Builder[float64]{ - Temporality: metricdata.CumulativeTemporality, + Temporality: metricdata.CumulativeTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.PrecomputedSum(false) })) b.Run("Precomputed/Float64/Delta", benchmarkAggregate(func() (Measure[float64], ComputeAggregation) { return Builder[float64]{ - Temporality: metricdata.DeltaTemporality, + Temporality: metricdata.DeltaTemporality, + ExemplarFilter: exemplar.AlwaysOffFilter, }.PrecomputedSum(false) })) }