You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-06 09:09:44 +02:00
Part of https://github.com/open-telemetry/opentelemetry-go/issues/5249 This makes all existing types designed to implement the public Exemplar API public by moving most of `internal/exemplar` to `exemplar`. The only types that are not being made public are `exemplar.Drop`, and `exemplar.FilteredReservoir`. Those types are moved to `internal/aggregate`, and are renamed to `DropReservoir` and `FilteredExemplarReservoir`. The following types are made public: * `exemplar.Exemplar` * `exemplar.Filter` * `exemplar.SampledFilter` * `exemplar.AlwaysOnFilter` * `exemplar.HistogramReservoir` * `exemplar.FixedSizeReservoir` * `exemplar.Reservoir` * `exemplar.Value` * `exemplar.ValueType`
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package aggregate
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/sdk/metric/exemplar"
|
|
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
|
)
|
|
|
|
func TestCollectExemplars(t *testing.T) {
|
|
t.Run("Int64", testCollectExemplars[int64]())
|
|
t.Run("Float64", testCollectExemplars[float64]())
|
|
}
|
|
|
|
func testCollectExemplars[N int64 | float64]() func(t *testing.T) {
|
|
return func(t *testing.T) {
|
|
now := time.Now()
|
|
alice := attribute.String("user", "Alice")
|
|
value := N(1)
|
|
spanID := [8]byte{0x1}
|
|
traceID := [16]byte{0x1}
|
|
|
|
out := new([]metricdata.Exemplar[N])
|
|
collectExemplars(out, func(in *[]exemplar.Exemplar) {
|
|
*in = reset(*in, 1, 1)
|
|
(*in)[0] = exemplar.Exemplar{
|
|
FilteredAttributes: []attribute.KeyValue{alice},
|
|
Time: now,
|
|
Value: exemplar.NewValue(value),
|
|
SpanID: spanID[:],
|
|
TraceID: traceID[:],
|
|
}
|
|
})
|
|
|
|
assert.Equal(t, []metricdata.Exemplar[N]{{
|
|
FilteredAttributes: []attribute.KeyValue{alice},
|
|
Time: now,
|
|
Value: value,
|
|
SpanID: spanID[:],
|
|
TraceID: traceID[:],
|
|
}}, *out)
|
|
}
|
|
}
|