Skip to content

[Metrics] Exclude list for tags on Metrics#7373

Open
nabutabu wants to merge 16 commits into
open-telemetry:mainfrom
nabutabu:exclude-tags-1
Open

[Metrics] Exclude list for tags on Metrics#7373
nabutabu wants to merge 16 commits into
open-telemetry:mainfrom
nabutabu:exclude-tags-1

Conversation

@nabutabu

@nabutabu nabutabu commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Towards #4427
Design discussion issue open-telemetry/opentelemetry-specification#4188

Changes

Adds an exclude list to MetricStreamConfiguration and FindMetricAggregatorsExcludeTag method that returns the correct list for the current view

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

nabutabu added 4 commits June 7, 2026 22:53
…elated updates

- Introduced ExcludedTagKeys property in MetricStreamConfiguration to specify optional tag keys to exclude from metrics.
- Updated AggregatorStore to handle excluded tag keys during metric updates.
- Enhanced MetricStreamIdentity to include excluded tag keys.
- Implemented validation logic to ensure TagKeys and ExcludedTagKeys are mutually exclusive.
- Added tests to verify behavior of excluded tag keys in metric views.
@github-actions github-actions Bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Jun 8, 2026
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.04762% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.70%. Comparing base (be8483f) to head (56ce766).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/OpenTelemetry/Metrics/ThreadStaticStorage.cs 87.50% 3 Missing ⚠️
src/OpenTelemetry/Metrics/AggregatorStore.cs 91.66% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7373      +/-   ##
==========================================
- Coverage   89.76%   89.70%   -0.06%     
==========================================
  Files         276      276              
  Lines       14611    14686      +75     
==========================================
+ Hits        13115    13174      +59     
- Misses       1496     1512      +16     
Flag Coverage Δ
unittests-Project-Experimental 89.62% <94.04%> (-0.02%) ⬇️
unittests-Project-Stable 89.49% <94.04%> (-0.27%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/OpenTelemetry/Metrics/Exemplar/Exemplar.cs 85.96% <100.00%> (+0.25%) ⬆️
...try/Metrics/Exemplar/FixedSizeExemplarReservoir.cs 93.33% <100.00%> (+0.74%) ⬆️
src/OpenTelemetry/Metrics/MeterProviderSdk.cs 94.30% <100.00%> (+0.16%) ⬆️
src/OpenTelemetry/Metrics/MetricStreamIdentity.cs 86.74% <100.00%> (+0.29%) ⬆️
...elemetry/Metrics/View/MetricStreamConfiguration.cs 100.00% <100.00%> (ø)
src/OpenTelemetry/ReadOnlyFilteredTagCollection.cs 100.00% <100.00%> (ø)
src/OpenTelemetry/Metrics/AggregatorStore.cs 89.44% <91.66%> (+0.05%) ⬆️
src/OpenTelemetry/Metrics/ThreadStaticStorage.cs 85.71% <87.50%> (+0.93%) ⬆️

... and 5 files with indirect coverage changes

@github-actions

Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions Bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Jun 16, 2026
@nabutabu

Copy link
Copy Markdown
Contributor Author

Decisions that require review

TagKeys and ExcludedTagKeys combination behavior

State Behavior New in PR?
Both null All tags preserved No
TagKeys = [] All measurements collapse to zero-tag metric point No
ExcludedTagKeys = [] All tags preserved (identical to default, but goes through exclude code path) Yes
Both non-null (including both []) Validate() throws, view is dropped with a logged warning (event ID 41), instrument falls back to default behavior Yes

Order sensitivity in ExcludedTagKeys

ExcludedTagKeys uses element-wise comparison (same as TagKeys). ["a","b"] and ["b","a"] produce different MetricStreamIdentity values even though the filtering behavior is identical. This is a known limitation inherited from the pre-existing TagKeys behavior.

@nabutabu nabutabu marked this pull request as ready for review June 16, 2026 19:03
@nabutabu nabutabu requested a review from a team as a code owner June 16, 2026 19:03
@nabutabu nabutabu changed the title [WIP] Exclude list for tags on Metrics [Metrics] Exclude list for tags on Metrics Jun 16, 2026
@github-actions github-actions Bot removed the Stale Issues and pull requests which have been flagged for closing due to inactivity label Jun 17, 2026
Comment thread src/OpenTelemetry/Metrics/AggregatorStore.cs Outdated
{
#if NET
internal readonly FrozenSet<string>? TagKeysInteresting;
internal readonly FrozenSet<string>? ExcludedTagKeysInteresting;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we're excluding them, aren't they more "uninteresting"?

Not sure about the suffix and/or if we need both Excluded and Uninteresting.

I'd probably just name it ExcludedTagKeys.

Comment on lines +143 to +145
if (!excludedTagKeys.Contains(tags[n].Key))
{
tagKeysAndValues![actualLength] = tags[n];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tags[n] is accessed twice.

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

Labels

pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants