feat(metrics): aggregate counter measurements at record time #152
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 270 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.335
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #152"
general
weight: 0.35
agagniere
Fixes #146 (Part 1: Counters and UpDownCounters).
Description
Previously,
Counter.add()andUpDownCounter.add()appended each measurement as an individualDataPointinto an unboundeddata_pointsarray, which was only cleared at collection time. For high-frequency recordings on a fixed set of attributes, memory consumption grew linearly with the number of measurements (up to ~250MB peak RSS for 1M iterations).This PR addresses Part 1 of #146 (as discussed with @agagniere and @daisuke8000) for synchronous sum instruments (
CounterandUpDownCounter):1. Record-Time In-Place Aggregation:
- Replaces
data_points: std.ArrayListUnmanagedinCounter(T)withpoints: std.ArrayHashMapUnmanaged(Attributes, T, Attributes.ArrayHashContext, true).- On
add()/addWithSlice(), looks up existing attribute entries and accumulatesdeltain place.- Preserves capacity across collections (
points.clearRetainingCapacity()) to eliminate repeated map reallocations.2. Zero-Heap Attribute Parsing:
- Implemented
Attributes.fromBuffer(buffer, keyValues)soadd(delta, attributes)resolves key-value pairs into a stack buffer without allocating heap memory for existing series updates.3. Cardinality Limit Enforcement:
- Propagates
cardinality_limit(defaulting to 2000 per the OpenTelemetry specification) to instruments.- When the limit is reached, incoming new attribute sets are logged with a warning and dropped, while updates to existing series continue to aggregate.
4. Tests & Benchmarks:
- Added unit test verifying in-place aggregation without memory growth across 10,000 iterations.
- Added unit test verifying enforcement of
cardinality_limit.- Updated existing instrument and meter tests to match record-time aggregated semantics.
- Ran all unit tests (418/418 passed) and verified zero memory leaks with
std.testing.allocator.- Ran SDK counter benchmarks (
UpDownCounter_Add_WithoutAttributes: ~398ns,Counter_Add_Without_Attributes: ~481ns).Part 2 (Histograms) will follow in a separate PR in coordination with @daisuke8000 and PR #130.