Debian Codegraph @

sdk/metric/internal/aggregate/exemplar_test.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package aggregate
5
6 import (
7 "testing"
8 "time"
9
10 "github.com/stretchr/testify/assert"
11
12 "go.opentelemetry.io/otel/attribute"
13 "go.opentelemetry.io/otel/sdk/metric/exemplar"
14 "go.opentelemetry.io/otel/sdk/metric/metricdata"
15 )
16
17 func TestCollectExemplars(t *testing.T) {
18 t.Run("Int64", testCollectExemplars[int64]())
19 t.Run("Float64", testCollectExemplars[float64]())
20 }
21
22 func testCollectExemplars[N int64 | float64]() func(t *testing.T) {
23 return func(t *testing.T) {
24 now := time.Now()
25 alice := attribute.String("user", "Alice")
26 value := N(1)
27 spanID := [8]byte{0x1}
28 traceID := [16]byte{0x1}
29
30 out := new([]metricdata.Exemplar[N])
31 collectExemplars(out, func(in *[]exemplar.Exemplar) {
32 *in = reset(*in, 1, 1)
33 (*in)[0] = exemplar.Exemplar{
34 FilteredAttributes: []attribute.KeyValue{alice},
35 Time: now,
36 Value: exemplar.NewValue(value),
37 SpanID: spanID[:],
38 TraceID: traceID[:],
39 }
40 })
41
42 assert.Equal(t, []metricdata.Exemplar[N]{{
43 FilteredAttributes: []attribute.KeyValue{alice},
44 Time: now,
45 Value: value,
46 SpanID: spanID[:],
47 TraceID: traceID[:],
48 }}, *out)
49 }
50 }