Skip to content

Commit 233d283

Browse files
authored
Merge branch 'main' into version-bumps
2 parents f8abaf3 + c2eedcf commit 233d283

File tree

1 file changed

+78
-1
lines changed

1 file changed

+78
-1
lines changed

test/otel_metric_tests.exs

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ defmodule OtelMetricTests do
33

44
require OpenTelemetryAPIExperimental.Counter, as: Counter
55
require OpenTelemetryAPIExperimental.UpDownCounter, as: UpDownCounter
6+
require OpenTelemetryAPIExperimental.Histogram, as: Histogram
67

78
require Record
89
@fields Record.extract(:metric, from_lib: "opentelemetry_experimental/include/otel_metrics.hrl")
@@ -16,6 +17,11 @@ defmodule OtelMetricTests do
1617
@fields Record.extract(:sum, from_lib: "opentelemetry_experimental/include/otel_metrics.hrl")
1718
Record.defrecordp(:sum, @fields)
1819

20+
@fields Record.extract(:histogram,
21+
from_lib: "opentelemetry_experimental/include/otel_metrics.hrl"
22+
)
23+
Record.defrecordp(:histogram, @fields)
24+
1925
setup do
2026
Application.load(:opentelemetry_experimental)
2127
Application.load(:opentelemetry)
@@ -34,7 +40,7 @@ defmodule OtelMetricTests do
3440
observable_counter: :temporality_cumulative,
3541
updown_counter: :temporality_delta,
3642
observable_updowncounter: :temporality_cumulative,
37-
histogram: :temporality_delta,
43+
histogram: :temporality_cumulative,
3844
observable_gauge: :temporality_cumulative
3945
}
4046
}
@@ -97,4 +103,75 @@ defmodule OtelMetricTests do
97103
data: sum(datapoints: [datapoint(value: 9)])
98104
)}
99105
end
106+
107+
test "create Histogram with macros" do
108+
Histogram.create(:histogram_a, %{unit: "1", description: "some histogram_a"})
109+
Histogram.record(:histogram_a, 1)
110+
111+
:otel_meter_server.force_flush()
112+
113+
assert_receive {:metric,
114+
metric(
115+
name: :histogram_a,
116+
data:
117+
histogram(
118+
aggregation_temporality: :temporality_cumulative,
119+
datapoints: [
120+
{:histogram_datapoint, %{}, _, _, 1, 1,
121+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
122+
[
123+
0.0,
124+
5.0,
125+
10.0,
126+
25.0,
127+
50.0,
128+
75.0,
129+
100.0,
130+
250.0,
131+
500.0,
132+
750.0,
133+
1000.0,
134+
2500.0,
135+
5000.0,
136+
7500.0,
137+
10000.0
138+
], [], 0, 1, 1}
139+
]
140+
)
141+
)}
142+
143+
Histogram.record(:histogram_a, 10)
144+
145+
:otel_meter_server.force_flush()
146+
147+
assert_receive {:metric,
148+
metric(
149+
name: :histogram_a,
150+
data:
151+
histogram(
152+
aggregation_temporality: :temporality_cumulative,
153+
datapoints: [
154+
{:histogram_datapoint, %{}, _, _, 2, 11,
155+
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
156+
[
157+
0.0,
158+
5.0,
159+
10.0,
160+
25.0,
161+
50.0,
162+
75.0,
163+
100.0,
164+
250.0,
165+
500.0,
166+
750.0,
167+
1000.0,
168+
2500.0,
169+
5000.0,
170+
7500.0,
171+
10000.0
172+
], [], 0, 1, 10}
173+
]
174+
)
175+
)}
176+
end
100177
end

0 commit comments

Comments
 (0)