Skip to content

Commit 88ba99c

Browse files
committed
Fix histogram aggregation
1 parent d43403d commit 88ba99c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

apps/opentelemetry_experimental/src/otel_metric_exporter_prometheus.erl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,12 @@ datapoint(#histogram_datapoint{} = DP, MetricName, AddCreated, ScopeLabels, [Poi
214214
false -> []
215215
end,
216216

217-
Buckets = lists:map(
218-
fun({C, Le}) ->
217+
{Buckets, _} = lists:mapfoldl(
218+
fun({C, Le}, Sum) ->
219219
HistoLabels = surround_labels(join_labels(Labels, render_label_pair({"le", Le}))),
220-
[MetricName, "_bucket", HistoLabels, " ", number_to_binary(C), "\n"]
220+
{[MetricName, "_bucket", HistoLabels, " ", number_to_binary(Sum + C), "\n"], Sum + C}
221221
end,
222+
0,
222223
lists:zip(DP#histogram_datapoint.bucket_counts, DP#histogram_datapoint.explicit_bounds ++ [<<"+Inf">>])
223224
),
224225

@@ -524,8 +525,8 @@ monotonic_histogram_test() ->
524525
"# UNIT test_sec sec",
525526
"# HELP test_sec lorem ipsum",
526527
"test_sec_bucket{otel_scope_name=\"scope-1\",otel_scope_version=\"version-1\",le=\"2\"} 2",
527-
"test_sec_bucket{otel_scope_name=\"scope-1\",otel_scope_version=\"version-1\",le=\"3\"} 0",
528-
"test_sec_bucket{otel_scope_name=\"scope-1\",otel_scope_version=\"version-1\",le=\"+Inf\"} 1",
528+
"test_sec_bucket{otel_scope_name=\"scope-1\",otel_scope_version=\"version-1\",le=\"3\"} 2",
529+
"test_sec_bucket{otel_scope_name=\"scope-1\",otel_scope_version=\"version-1\",le=\"+Inf\"} 3",
529530
"test_sec_count{otel_scope_name=\"scope-1\",otel_scope_version=\"version-1\"} 3",
530531
"test_sec_sum{otel_scope_name=\"scope-1\",otel_scope_version=\"version-1\"} 7",
531532
"test_sec_created{otel_scope_name=\"scope-1\",otel_scope_version=\"version-1\"} 0",

0 commit comments

Comments
 (0)