Skip to content

Commit

Permalink
add testable example for exemplar filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Sep 30, 2024
1 parent 7d45e6f commit 06303f1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions sdk/metric/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/exemplar"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
)
Expand Down Expand Up @@ -240,3 +241,21 @@ func ExampleNewView_exponentialHistogram() {
metric.WithView(view),
)
}

func ExampleWithExemplarFilter_disabled() {
// Use exemplar.AlwaysOffFilter to disable exemplar collection.
_ = metric.NewMeterProvider(
metric.WithExemplarFilter(exemplar.AlwaysOffFilter),
)
}

func ExampleWithExemplarFilter_custom() {
// Create a custom filter function that only offers measurements if the
// context has an error.
customFilter := func(ctx context.Context) bool {
return ctx.Err() != nil
}
_ = metric.NewMeterProvider(
metric.WithExemplarFilter(customFilter),
)
}

0 comments on commit 06303f1

Please sign in to comment.