Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test of Elixir cumulative explicit histogram #712

Merged
merged 2 commits into from Mar 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 78 additions & 1 deletion test/otel_metric_tests.exs
Expand Up @@ -3,6 +3,7 @@ defmodule OtelMetricTests do

require OpenTelemetryAPIExperimental.Counter, as: Counter
require OpenTelemetryAPIExperimental.UpDownCounter, as: UpDownCounter
require OpenTelemetryAPIExperimental.Histogram, as: Histogram

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

@fields Record.extract(:histogram,
from_lib: "opentelemetry_experimental/include/otel_metrics.hrl"
)
Record.defrecordp(:histogram, @fields)

setup do
Application.load(:opentelemetry_experimental)
Application.load(:opentelemetry)
Expand All @@ -34,7 +40,7 @@ defmodule OtelMetricTests do
observable_counter: :temporality_cumulative,
updown_counter: :temporality_delta,
observable_updowncounter: :temporality_cumulative,
histogram: :temporality_delta,
histogram: :temporality_cumulative,
observable_gauge: :temporality_cumulative
}
}
Expand Down Expand Up @@ -97,4 +103,75 @@ defmodule OtelMetricTests do
data: sum(datapoints: [datapoint(value: 9)])
)}
end

test "create Histogram with macros" do
Histogram.create(:histogram_a, %{unit: "1", description: "some histogram_a"})
Histogram.record(:histogram_a, 1)

:otel_meter_server.force_flush()

assert_receive {:metric,
metric(
name: :histogram_a,
data:
histogram(
aggregation_temporality: :temporality_cumulative,
datapoints: [
{:histogram_datapoint, %{}, _, _, 1, 1,
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[
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}
]
)
)}

Histogram.record(:histogram_a, 10)

:otel_meter_server.force_flush()

assert_receive {:metric,
metric(
name: :histogram_a,
data:
histogram(
aggregation_temporality: :temporality_cumulative,
datapoints: [
{:histogram_datapoint, %{}, _, _, 2, 11,
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[
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}
]
)
)}
end
end