-
Notifications
You must be signed in to change notification settings - Fork 511
[METRICS] Add tag to AggregationConfig for aggregation type validation #3732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marcalff
merged 29 commits into
open-telemetry:main
from
ThomsonTan:add_tag_to_aggregationconfig
Nov 15, 2025
Merged
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
a2c48c6
Add tag to AggregationConfig for type checking
ThomsonTan d2330d1
Add test
ThomsonTan 177d85a
Fix format
ThomsonTan db221d8
Address feedback
ThomsonTan 7ec33ec
Merge branch 'main' into add_tag_to_aggregationconfig
ThomsonTan 4d9331c
Merge branch 'main' into add_tag_to_aggregationconfig
ThomsonTan 5dfc194
Support build without exception
ThomsonTan 2c4266b
Remove logging
ThomsonTan 6f04f06
Handle unittest in noexception build
ThomsonTan 363eb46
Fix EXPECT_NO_THROW for no-exception build
ThomsonTan b500f61
Fix iwyu
ThomsonTan af73f3a
Move check to AddView
ThomsonTan f28235c
Merge branch 'main' into add_tag_to_aggregationconfig
ThomsonTan 6179d6f
Handle kDefault in AddView
ThomsonTan d3b4c42
Fix meter provider test
ThomsonTan 8e2a1b0
Merge branch 'main' into add_tag_to_aggregationconfig
ThomsonTan 9dd5eae
Fix iwyu
ThomsonTan 36ef49a
Remove noexcept on AddView
ThomsonTan 5e96531
Add changelog
ThomsonTan f30cea6
Update changelog
ThomsonTan f150c4a
Merge branch 'main' into add_tag_to_aggregationconfig
ThomsonTan 4b27470
Merge branch 'main' into add_tag_to_aggregationconfig
ThomsonTan 4400651
Merge branch 'main' into add_tag_to_aggregationconfig
ThomsonTan a530053
Merge branch 'main' into add_tag_to_aggregationconfig
ThomsonTan 01889b2
Log View validation error and ignore it
ThomsonTan 3867d1d
Add back noexcept on AddView
ThomsonTan c1c5d0a
Add noexcept back to AddView implementation
ThomsonTan 83f6394
Merge branch 'main' into add_tag_to_aggregationconfig
ThomsonTan b61e528
Address feedback
ThomsonTan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,9 @@ | |
| #include <vector> | ||
|
|
||
| #include "opentelemetry/nostd/function_ref.h" | ||
| #include "opentelemetry/sdk/common/global_log_handler.h" | ||
| #include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" | ||
| #include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" | ||
| #include "opentelemetry/sdk/metrics/instruments.h" | ||
| #include "opentelemetry/sdk/metrics/view/instrument_selector.h" | ||
| #include "opentelemetry/sdk/metrics/view/meter_selector.h" | ||
|
|
@@ -47,6 +49,59 @@ class ViewRegistry | |
| { | ||
| // TBD - thread-safe ? | ||
|
|
||
| // Validate parameters | ||
| if (!instrument_selector || !meter_selector || !view) | ||
| { | ||
| OTEL_INTERNAL_LOG_ERROR( | ||
| "[ViewRegistry::AddView] Invalid parameters: instrument_selector, meter_selector, and " | ||
| "view cannot be null. Ignoring AddView call."); | ||
| return; | ||
| } | ||
|
|
||
| auto aggregation_config = view->GetAggregationConfig(); | ||
| if (aggregation_config) | ||
| { | ||
| bool valid = false; | ||
| auto aggregation_config_type = aggregation_config->GetType(); | ||
| auto aggregation_type = view->GetAggregationType(); | ||
|
|
||
| if (aggregation_type == AggregationType::kDefault) | ||
| { | ||
| bool is_monotonic; | ||
| aggregation_type = DefaultAggregation::GetDefaultAggregationType( | ||
| instrument_selector->GetInstrumentType(), is_monotonic); | ||
| } | ||
|
|
||
| switch (aggregation_type) | ||
| { | ||
| case AggregationType::kHistogram: | ||
| valid = (aggregation_config_type == AggregationType::kHistogram); | ||
| break; | ||
|
|
||
| case AggregationType::kBase2ExponentialHistogram: | ||
| valid = (aggregation_config_type == AggregationType::kBase2ExponentialHistogram); | ||
| break; | ||
|
|
||
| case AggregationType::kDrop: | ||
| case AggregationType::kLastValue: | ||
| case AggregationType::kSum: | ||
| valid = (aggregation_config_type == AggregationType::kDefault); | ||
| break; | ||
|
|
||
| default: | ||
| // Unreachable: all AggregationType enum values are handled above | ||
| std::abort(); | ||
|
||
| } | ||
|
|
||
| if (!valid) | ||
| { | ||
| OTEL_INTERNAL_LOG_ERROR( | ||
| "[ViewRegistry::AddView] AggregationType and AggregationConfig type mismatch. " | ||
| "Ignoring AddView call."); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| auto registered_view = std::unique_ptr<RegisteredView>(new RegisteredView{ | ||
| std::move(instrument_selector), std::move(meter_selector), std::move(view)}); | ||
| registered_views_.push_back(std::move(registered_view)); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.