opentelemetry-js icon indicating copy to clipboard operation
opentelemetry-js copied to clipboard

feat(metrics): add advisory attributes parameter to metric instruments

Open pratstick opened this issue 5 months ago • 2 comments

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

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

How Has This Been Tested?

  • [x] Unit tests for ViewRegistry advisory attributes handling
  • [x] Integration tests covering various scenarios including edge cases
  • [x] Tests for attribute filtering behavior with and without views
  • [x] Verification of experimental feature marking
  • [x] 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:

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

pratstick avatar Jul 07 '25 18:07 pratstick

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: pratstick / name: Pratyush (b5eca96bd586d16c529b82f3afc63d939af04dd0, 82948e168b2c08896743fdba1b66dcdad1fc2f46, bad0c9f2515aa9bca0a95b1fd0a8c1fcaa89f341, d7c17af3cb452fb3bacc89178479a0567e18b919, 09c03bd117c41c1513b0ec028facc9a96809a92e, 957e0bfeca33e419c8c3a8d187d49535364baf87)

@pratstick did you have time to look into my comment? Looks like not a lot is missing other than that. 🙂

pichlermarc avatar Nov 12 '25 17:11 pichlermarc