Skip to content

Commit 19c0b2d

Browse files
committed
add test of Elixir cumulative explicit histogram
1 parent c1ccdff commit 19c0b2d

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

test/otel_metric_tests.exs

Lines changed: 33 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,9 @@ 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, from_lib: "opentelemetry_experimental/include/otel_metrics.hrl")
21+
Record.defrecordp(:histogram, @fields)
22+
1923
setup do
2024
Application.load(:opentelemetry_experimental)
2125
Application.load(:opentelemetry)
@@ -34,7 +38,7 @@ defmodule OtelMetricTests do
3438
observable_counter: :temporality_cumulative,
3539
updown_counter: :temporality_delta,
3640
observable_updowncounter: :temporality_cumulative,
37-
histogram: :temporality_delta,
41+
histogram: :temporality_cumulative,
3842
observable_gauge: :temporality_cumulative
3943
}
4044
}
@@ -97,4 +101,32 @@ defmodule OtelMetricTests do
97101
data: sum(datapoints: [datapoint(value: 9)])
98102
)}
99103
end
104+
105+
test "create Histogram with macros" do
106+
Histogram.create(:histogram_a, %{unit: "1", description: "some histogram_a"})
107+
Histogram.record(:histogram_a, 1)
108+
109+
:otel_meter_server.force_flush()
110+
111+
assert_receive {:metric,
112+
metric(
113+
name: :histogram_a,
114+
data: histogram(aggregation_temporality: :temporality_cumulative,
115+
datapoints: [{:histogram_datapoint, %{}, _, _, 1, 1, [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
116+
[0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0], [], 0, 1, 1}])
117+
)}
118+
119+
Histogram.record(:histogram_a, 10)
120+
121+
:otel_meter_server.force_flush()
122+
123+
assert_receive {:metric,
124+
metric(
125+
name: :histogram_a,
126+
data: histogram(aggregation_temporality: :temporality_cumulative,
127+
datapoints: [{:histogram_datapoint, %{}, _, _, 2, 11, [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
128+
[0.0, 5.0, 10.0, 25.0, 50.0, 75.0, 100.0, 250.0, 500.0, 750.0, 1000.0, 2500.0, 5000.0, 7500.0, 10000.0], [], 0, 1, 10}])
129+
)}
130+
end
131+
100132
end

0 commit comments

Comments
 (0)