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

Rename SampledFilter to TraceBasedFilter #5862

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Added

- Add `go.opentelemetry.io/otel/sdk/metric/exemplar` package which includes `Exemplar`, `Filter`, `SampledFilter`, `AlwaysOnFilter`, `HistogramReservoir`, `FixedSizeReservoir`, `Reservoir`, `Value` and `ValueType` types. These will be used for configuring the exemplar reservoir for the metrics sdk. (#5747)
- Add `go.opentelemetry.io/otel/sdk/metric/exemplar` package which includes `Exemplar`, `Filter`, `TraceBasedFilter`, `AlwaysOnFilter`, `HistogramReservoir`, `FixedSizeReservoir`, `Reservoir`, `Value` and `ValueType` types. These will be used for configuring the exemplar reservoir for the metrics sdk. (#5747, #5862)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/exemplar.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func reservoirFunc[N int64 | float64](agg Aggregation) func() aggregate.Filtered
case "trace_based":
fallthrough
default:
filter = exemplar.SampledFilter
filter = exemplar.TraceBasedFilter
}

// https://github.com/open-telemetry/opentelemetry-specification/blob/d4b241f451674e8f611bb589477680341006ad2b/specification/metrics/sdk.md#exemplar-defaults
Expand Down
4 changes: 2 additions & 2 deletions sdk/metric/exemplar/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
// Reservoir in making a sampling decision.
type Filter func(context.Context) bool

// SampledFilter is a [Filter] that will only offer measurements
// TraceBasedFilter is a [Filter] that will only offer measurements
// if the passed context associated with the measurement contains a sampled
// [go.opentelemetry.io/otel/trace.SpanContext].
func SampledFilter(ctx context.Context) bool {
func TraceBasedFilter(ctx context.Context) bool {
return trace.SpanContextFromContext(ctx).IsSampled()
}

Expand Down
12 changes: 6 additions & 6 deletions sdk/metric/exemplar/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import (
"go.opentelemetry.io/otel/trace"
)

func TestSampledFilter(t *testing.T) {
t.Run("Int64", testSampledFiltered[int64])
t.Run("Float64", testSampledFiltered[float64])
func TestTraceBasedFilter(t *testing.T) {
t.Run("Int64", testTraceBasedFilter[int64])
t.Run("Float64", testTraceBasedFilter[float64])
}

func testSampledFiltered[N int64 | float64](t *testing.T) {
func testTraceBasedFilter[N int64 | float64](t *testing.T) {
ctx := context.Background()

assert.False(t, SampledFilter(ctx), "non-sampled context should not be offered")
assert.True(t, SampledFilter(sample(ctx)), "sampled context should be offered")
assert.False(t, TraceBasedFilter(ctx), "non-sampled context should not be offered")
assert.True(t, TraceBasedFilter(sample(ctx)), "sampled context should be offered")
}

func sample(parent context.Context) context.Context {
Expand Down
Loading