Skip to content

Conversation

nikhilbhatia08
Copy link
Contributor

Fixes #1724

Performing Reaggregation when spatial dimensions are dropped in async counters. There are also unit tests provided to the change.

Changes

Please provide a brief description of the changes here.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@nikhilbhatia08 nikhilbhatia08 requested a review from a team as a code owner October 12, 2025 20:14
Copy link

codecov bot commented Oct 12, 2025

Codecov Report

❌ Patch coverage is 79.41176% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.75%. Comparing base (767ef30) to head (880567f).

Files with missing lines Patch % Lines
...try/sdk/metrics/state/measurement_attributes_map.h 65.86% 14 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3691      +/-   ##
==========================================
- Coverage   89.95%   89.75%   -0.20%     
==========================================
  Files         225      226       +1     
  Lines        7273     7326      +53     
==========================================
+ Hits         6542     6575      +33     
- Misses        731      751      +20     
Files with missing lines Coverage Δ
...nclude/opentelemetry/sdk/metrics/observer_result.h 100.00% <100.00%> (ø)
...telemetry/sdk/metrics/state/async_metric_storage.h 95.66% <100.00%> (+1.06%) ⬆️
...e/opentelemetry/sdk/metrics/state/metric_storage.h 100.00% <ø> (ø)
...telemetry/sdk/metrics/state/multi_metric_storage.h 100.00% <100.00%> (ø)
sdk/src/metrics/meter.cc 85.89% <100.00%> (ø)
...try/sdk/metrics/state/measurement_attributes_map.h 65.86% <65.86%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lalitb lalitb requested a review from Copilot October 13, 2025 04:08
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses the issue of performing async re-aggregation when spatial attributes are dropped in OpenTelemetry metrics. The main purpose is to ensure that when attributes are filtered out by attribute processors in async counters, the measurements are properly reaggregated to combine values that now have identical attribute sets.

Key changes include:

  • Introduced a new MeasurementAttributes type for better handling of attribute-value mappings
  • Modified async metric storage to perform reaggregation during attribute processing
  • Updated observer result handling to use the new measurement structure

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sdk/include/opentelemetry/sdk/metrics/state/measurement_attributes_map.h New header defining custom hash/equality functions and MeasurementAttributes type for attribute maps
sdk/include/opentelemetry/sdk/metrics/observer_result.h Updated ObserverResultT to use new MeasurementAttributes type and removed dependency on AttributesProcessor
sdk/include/opentelemetry/sdk/metrics/state/async_metric_storage.h Added ConvertMeasurementsToMetricAttributes method to handle reaggregation and attributes processor integration
sdk/include/opentelemetry/sdk/metrics/state/metric_storage.h Updated AsyncWritableMetricStorage interface to use MeasurementAttributes type
sdk/include/opentelemetry/sdk/metrics/state/multi_metric_storage.h Updated AsyncMultiMetricStorage to use new MeasurementAttributes type
sdk/src/metrics/meter.cc Modified async metric storage registration to pass attributes processor
sdk/src/metrics/state/observable_registry.cc Updated to create ObserverResultT without attributes processor parameter
sdk/test/metrics/async_metric_storage_test.cc Updated tests to use new types and added attributes processor setup
sdk/test/metrics/observer_result_test.cc Simplified test to use new ObserverResultT constructor
sdk/test/metrics/sum_aggregation_test.cc Added comprehensive tests for observable counter reaggregation scenarios

return std::hash<nostd::string_view>{}(nostd::get<nostd::string_view>(value));
}

return 0; // fallback for other types
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback hash value of 0 for unsupported types can cause hash collisions. Consider using a more distinctive hash value or throwing an exception for unsupported types to make the limitation explicit.

Suggested change
return 0; // fallback for other types
// Fallback for other types: use the index of the variant as a distinctive hash value
return std::hash<size_t>{}(value.index());

Copilot uses AI. Check for mistakes.

return nostd::get<nostd::string_view>(a) == nostd::get<nostd::string_view>(b);
}

return false;
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback return value of false for unsupported types in equality comparison can lead to incorrect behavior. Consider throwing an exception for unsupported types to make the limitation explicit, similar to the hash function concern.

Copilot uses AI. Check for mistakes.

@lalitb lalitb self-requested a review October 16, 2025 17:45
@lalitb lalitb self-assigned this Oct 16, 2025
@lalitb lalitb removed their request for review October 16, 2025 17:45
@lalitb
Copy link
Member

lalitb commented Oct 16, 2025

Assigned it to self. Will review during this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Metrics SDK] Async aggregation doesn't do re-aggregation properly when the spatial dimensions are dropped

2 participants