Skip to content

Conversation

pratstick
Copy link

Which problem is this PR solving?

This PR implements the "attributes" instrument advisory parameter for OpenTelemetry metrics as specified in the OpenTelemetry specification. The advisory parameter allows users to specify an allow-list of attribute keys that should be retained when recording metrics, helping to reduce cardinality and improve performance.

Fixes #4365

Short description of the changes

  • Added optional attributes parameter to MetricAdvice interface in the API
  • Implemented advisory attributes filtering in the SDK's ViewRegistry using AllowListProcessor
  • Added comprehensive unit and integration tests for the new functionality
  • Updated documentation with usage examples and experimental status notes
  • Created a working example demonstrating the feature

The implementation ensures that:

  • Advisory attributes only apply when no Views are configured for the instrument
  • The feature is properly marked as experimental
  • All existing functionality remains unchanged
  • The allow-list filtering works across all instrument types (Counter, Histogram, UpDownCounter, etc.)

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • Unit tests for ViewRegistry advisory attributes handling
  • Integration tests covering various scenarios including edge cases
  • Tests for attribute filtering behavior with and without views
  • Verification of experimental feature marking
  • Manual testing with the provided example script

The tests cover:

  • Advisory attributes filtering with different instrument types
  • Behavior when no advisory attributes are specified
  • Interaction with existing Views (Views take precedence)
  • Edge cases like empty attribute lists

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated
  • Feature is marked as experimental
  • Implementation follows OpenTelemetry specification
  • No breaking changes introduced
  • Example code provided for demonstration

pratstick added 4 commits July 8, 2025 00:13
Add optional attributes parameter to MetricAdvice interface to support
advisory attribute filtering for metric instruments. This parameter
allows users to specify which attribute keys should be kept when
recording metrics, acting as an allow-list filter.

The parameter is marked as experimental and follows the OpenTelemetry
specification for advisory parameters.
Implement advisory attributes filtering in ViewRegistry by creating
a default view with AllowListProcessor when no matching views are
found and the instrument has advisory attributes specified.

This ensures that only the specified attribute keys are retained
when recording metrics, reducing cardinality and improving performance.
Add comprehensive unit and integration tests for the advisory attributes
parameter functionality:

- Unit tests for ViewRegistry advisory attributes handling
- Integration tests covering various scenarios including edge cases
- Tests for attribute filtering behavior with and without views
- Verification of experimental feature marking
Add documentation and example for the new advisory attributes parameter:

- Update README with usage instructions and examples
- Create standalone example demonstrating the feature
- Include notes about experimental status and performance benefits
- Provide clear guidance on when and how to use advisory attributes
@pratstick pratstick requested a review from a team as a code owner July 7, 2025 18:53
Copy link

linux-foundation-easycla bot commented Jul 7, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

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

Thank you for working on this. 🙂

Looks like the tests are failing - I added some assumption as to why to my comments below.
Please also add an entry in ./CHANGELOG.md and ./api/CHANGELOG.md for this feature.

}

// Create a view that matches this specific instrument
return new View(viewOptions);
Copy link
Member

Choose a reason for hiding this comment

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

My guess is that creating a view always is what's eventually failing the tests. You might have to look into which part of the code calls findViews() to investigate what's wrong.

Copy link
Author

Choose a reason for hiding this comment

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

Sure , I will look into all the issues and get back to you

Copy link
Author

Choose a reason for hiding this comment

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

Hi @pichlermarc
I've addressed the aforementioned issues
Could you take a look

Thank you

Copy link
Member

Choose a reason for hiding this comment

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

looks like it's still failing due to the issue I mentioned above, did you force-push over the change that addressed this? 🤔

Added the suggested change

Co-authored-by: Marc Pichler <[email protected]>
@pratstick pratstick requested a review from pichlermarc July 10, 2025 06:19
- Add experimental `attributes` parameter to MetricAdvice interface
- Implement attribute filtering via ViewRegistry default views
- Only applies when no Views are configured for the instrument
- Views take precedence over advisory attributes when present
- Add comprehensive unit and integration tests
- Update documentation and changelogs

Closes open-telemetry#4365
@pratstick pratstick force-pushed the feature/advisory-attributes branch from 3e84236 to b5eca96 Compare July 11, 2025 16:50
@pichlermarc pichlermarc added the spec-feature This is a request to implement a new feature which is already specified by the OTel specification label Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:api pkg:sdk-metrics spec-feature This is a request to implement a new feature which is already specified by the OTel specification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[metrics] prototype attributes instrument advisory parameter
2 participants