opentelemetry-cpp icon indicating copy to clipboard operation
opentelemetry-cpp copied to clipboard

[METRICS] Observable instruments double count past the cardinality limit

Open mateenali66 opened this issue 1 month ago • 3 comments

Describe your environment

main at e89c12ad, macOS arm64, AppleClang 21, CMake RelWithDebInfo.

Steps to reproduce

One cumulative reader, and a view with a cardinality limit of 2 on an ObservableCounter. The callback reports these rounds:

{a=1, b=1}, then {x=7}, then {x=9}, then {x=9}

What is the expected behavior?

x reads 7, 9, 9. The spec says "Measurements MUST NOT be double-counted or dropped during an overflow."

What is the actual behavior?

x = 7, 16, 25

ObservableUpDownCounter gives the same values.

Additional context

last_observed_hash_map_ is full, so Get(x) finds nothing and the whole absolute value counts as a delta every round (async_metric_storage.h:166-176, :205-215).

#4484 keeps this behaviour and pins it in CardinalityLimitCapsCounterBaselines.

mateenali66 avatar Nov 05 '26 07:11 mateenali66

Reproduced on current main (c60031c), affects both ObservableCounter and ObservableUpDownCounter.

last_observed_hash_map_ is capped by the cardinality limit, so series past it never find their baseline. Baselines should be unbounded per source series; the delta map already enforces the limit on output.

I'd like to take this and open a PR.

Syedowais312 avatar Nov 07 '26 09:11 Syedowais312

Baselines should be unbounded per source series

Thanks for the reproduction.

Unbounded baselines bring back the growth #4484 just capped.

200k churned sets, one reader
uncapped    +43 MiB
capped      +0.8 MiB

#4484 moves this code and pins the current behaviour in CardinalityLimitCapsCounterBaselines, so a fix has to start from it.

Please wait for #4484 to merge, and keep the state bounded.

mateenali66 avatar Nov 07 '26 17:11 mateenali66

Thanks, fair point. I'll wait for #4484 to merge and look for a fix that keeps state bounded.

Syedowais312 avatar Nov 07 '26 17:11 Syedowais312