Skip to content

Commit

Permalink
add test of Elixir cumulative explicit histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter committed Mar 16, 2024
1 parent c3db261 commit a2ca9f7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions mix.exs
Expand Up @@ -14,6 +14,7 @@ defmodule OtelElixirTests.MixProject do
[
{:opentelemetry, path: "apps/opentelemetry", only: :test, override: true},
{:opentelemetry_api, path: "apps/opentelemetry_api", only: :test, override: true},
{:opentelemetry_exporter, path: "apps/opentelemetry_exporter", only: :test, override: true},
{:opentelemetry_semantic_conventions,
path: "apps/opentelemetry_semantic_conventions", only: :test, override: true},
{:opentelemetry_experimental,
Expand Down
34 changes: 33 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,9 @@ 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 +38,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 +101,32 @@ 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

0 comments on commit a2ca9f7

Please sign in to comment.