| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package exemplar // import "go.opentelemetry.io/otel/sdk/metric/exemplar" |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
|
| 9 |
"go.opentelemetry.io/otel/trace" |
| 10 |
) |
| 11 |
|
| 12 |
// Filter determines if a measurement should be offered. |
| 13 |
// |
| 14 |
// The passed ctx needs to contain any baggage or span that were active |
| 15 |
// when the measurement was made. This information may be used by the |
| 16 |
// Reservoir in making a sampling decision. |
| 17 |
type Filter func(context.Context) bool |
| 18 |
|
| 19 |
// TraceBasedFilter is a [Filter] that will only offer measurements |
| 20 |
// if the passed context associated with the measurement contains a sampled |
| 21 |
// [go.opentelemetry.io/otel/trace.SpanContext]. |
| 22 |
func TraceBasedFilter(ctx context.Context) bool { |
| 23 |
return trace.SpanContextFromContext(ctx).IsSampled() |
| 24 |
} |
| 25 |
|
| 26 |
// AlwaysOnFilter is a [Filter] that always offers measurements. |
| 27 |
func AlwaysOnFilter(context.Context) bool { |
| 28 |
return true |
| 29 |
} |
| 30 |
|
| 31 |
// AlwaysOffFilter is a [Filter] that never offers measurements. |
| 32 |
func AlwaysOffFilter(context.Context) bool { |
| 33 |
return false |
| 34 |
} |