package exemplar
import "go.opentelemetry.io/otel/sdk/metric/exemplar"
Package exemplar provides an implementation of the OpenTelemetry exemplar reservoir to be used in metric collection pipelines.
Index ¶
- func AlwaysOffFilter(ctx context.Context) bool
- func AlwaysOnFilter(ctx context.Context) bool
- func TraceBasedFilter(ctx context.Context) bool
- type Exemplar
- type Filter
- type FixedSizeReservoir
- func NewFixedSizeReservoir(k int) *FixedSizeReservoir
- func (r *FixedSizeReservoir) Collect(dest *[]Exemplar)
- func (r *FixedSizeReservoir) Offer(ctx context.Context, t time.Time, n Value, a []attribute.KeyValue)
- type HistogramReservoir
- func NewHistogramReservoir(bounds []float64) *HistogramReservoir
- func (r HistogramReservoir) Collect(dest *[]Exemplar)
- func (r *HistogramReservoir) Offer(ctx context.Context, t time.Time, v Value, a []attribute.KeyValue)
- type Reservoir
- type ReservoirProvider
- func FixedSizeReservoirProvider(k int) ReservoirProvider
- func HistogramReservoirProvider(bounds []float64) ReservoirProvider
- type Value
- func NewValue[N int64 | float64](value N) Value
- func (v Value) Float64() float64
- func (v Value) Int64() int64
- func (v Value) Type() ValueType
- type ValueType
Functions ¶
func AlwaysOffFilter ¶
AlwaysOffFilter is a Filter that never offers measurements.
func AlwaysOnFilter ¶
AlwaysOnFilter is a Filter that always offers measurements.
func TraceBasedFilter ¶
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.
Types ¶
type Exemplar ¶
type Exemplar struct { // FilteredAttributes are the attributes recorded with the measurement but // filtered out of the timeseries' aggregated data. FilteredAttributes []attribute.KeyValue // Time is the time when the measurement was recorded. Time time.Time // Value is the measured value. Value Value // SpanID is the ID of the span that was active during the measurement. If // no span was active or the span was not sampled this will be empty. SpanID []byte `json:",omitempty"` // TraceID is the ID of the trace the active span belonged to during the // measurement. If no span was active or the span was not sampled this will // be empty. TraceID []byte `json:",omitempty"` }
Exemplar is a measurement sampled from a timeseries providing a typical example.
type Filter ¶
Filter determines if a measurement should be offered.
The passed ctx needs to contain any baggage or span that were active when the measurement was made. This information may be used by the Reservoir in making a sampling decision.
type FixedSizeReservoir ¶
type FixedSizeReservoir struct {
// contains filtered or unexported fields
}
FixedSizeReservoir is a Reservoir that samples at most k exemplars. If there are k or less measurements made, the Reservoir will sample each one. If there are more than k, the Reservoir will then randomly sample all additional measurement with a decreasing probability.
func NewFixedSizeReservoir ¶
func NewFixedSizeReservoir(k int) *FixedSizeReservoir
NewFixedSizeReservoir returns a FixedSizeReservoir that samples at most k exemplars. If there are k or less measurements made, the Reservoir will sample each one. If there are more than k, the Reservoir will then randomly sample all additional measurement with a decreasing probability.
func (*FixedSizeReservoir) Collect ¶
func (r *FixedSizeReservoir) Collect(dest *[]Exemplar)
Collect returns all the held exemplars.
The Reservoir state is preserved after this call.
func (*FixedSizeReservoir) Offer ¶
func (r *FixedSizeReservoir) Offer(ctx context.Context, t time.Time, n Value, a []attribute.KeyValue)
Offer accepts the parameters associated with a measurement. The parameters will be stored as an exemplar if the Reservoir decides to sample the measurement.
The passed ctx needs to contain any baggage or span that were active when the measurement was made. This information may be used by the Reservoir in making a sampling decision.
The time t is the time when the measurement was made. The v and a parameters are the value and dropped (filtered) attributes of the measurement respectively.
type HistogramReservoir ¶
type HistogramReservoir struct {
// contains filtered or unexported fields
}
HistogramReservoir is a Reservoir that samples the last measurement that falls within a histogram bucket. The histogram bucket upper-boundaries are define by bounds.
func NewHistogramReservoir ¶
func NewHistogramReservoir(bounds []float64) *HistogramReservoir
NewHistogramReservoir returns a HistogramReservoir that samples the last measurement that falls within a histogram bucket. The histogram bucket upper-boundaries are define by bounds.
The passed bounds must be sorted before calling this function.
func (HistogramReservoir) Collect ¶
func (r HistogramReservoir) Collect(dest *[]Exemplar)
Collect returns all the held exemplars.
The Reservoir state is preserved after this call.
func (*HistogramReservoir) Offer ¶
func (r *HistogramReservoir) Offer(ctx context.Context, t time.Time, v Value, a []attribute.KeyValue)
Offer accepts the parameters associated with a measurement. The parameters will be stored as an exemplar if the Reservoir decides to sample the measurement.
The passed ctx needs to contain any baggage or span that were active when the measurement was made. This information may be used by the Reservoir in making a sampling decision.
The time t is the time when the measurement was made. The v and a parameters are the value and dropped (filtered) attributes of the measurement respectively.
type Reservoir ¶
type Reservoir interface { // Offer accepts the parameters associated with a measurement. The // parameters will be stored as an exemplar if the Reservoir decides to // sample the measurement. // // The passed ctx needs to contain any baggage or span that were active // when the measurement was made. This information may be used by the // Reservoir in making a sampling decision. // // The time t is the time when the measurement was made. The val and attr // parameters are the value and dropped (filtered) attributes of the // measurement respectively. Offer(ctx context.Context, t time.Time, val Value, attr []attribute.KeyValue) // Collect returns all the held exemplars. // // The Reservoir state is preserved after this call. Collect(dest *[]Exemplar) }
Reservoir holds the sampled exemplar of measurements made.
type ReservoirProvider ¶
ReservoirProvider creates new [Reservoir]s.
The attributes provided are attributes which are kept by the aggregation, and are exclusive with attributes passed to Offer. The combination of these attributes and the attributes passed to Offer is the complete set of attributes a measurement was made with.
func FixedSizeReservoirProvider ¶
func FixedSizeReservoirProvider(k int) ReservoirProvider
FixedSizeReservoirProvider returns a provider of FixedSizeReservoir.
func HistogramReservoirProvider ¶
func HistogramReservoirProvider(bounds []float64) ReservoirProvider
HistogramReservoirProvider is a provider of HistogramReservoir.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is the value of data held by an exemplar.
func NewValue ¶
NewValue returns a new Value for the provided value.
func (Value) Float64 ¶
Float64 returns the value of v as an float64. If the ValueType of v is not an Float64ValueType, 0 is returned.
func (Value) Int64 ¶
Int64 returns the value of v as an int64. If the ValueType of v is not an Int64ValueType, 0 is returned.
func (Value) Type ¶
Type returns the ValueType of data held by v.
type ValueType ¶
type ValueType uint8
ValueType identifies the type of value used in exemplar data.
const ( // UnknownValueType should not be used. It represents a misconfigured // Value. UnknownValueType ValueType = 0 // Int64ValueType represents a Value with int64 data. Int64ValueType ValueType = 1 // Float64ValueType represents a Value with float64 data. Float64ValueType ValueType = 2 )
Source Files ¶
doc.go exemplar.go filter.go fixed_size_reservoir.go histogram_reservoir.go reservoir.go storage.go value.go
- Version
- v1.34.0 (latest)
- Published
- Jan 17, 2025
- Platform
- linux/amd64
- Imports
- 8 packages
- Last checked
- 3 hours ago –
Tools for package owners.