open-telemetry / open-telemetry/opentelemetry-ruby

Fix View `attribute_keys` to behave as an allowlist (with exclude list)

Open
#2,359 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug metrics spec-compliance spec:stable
Dominant language
Ruby
Stars
606
Forks
301
Avg merge
3d 19h
Merged PRs (30d)
42

Description

Spec requirement

Stream configuration's attribute_keys MUST behave as an allowlist — "keys that MUST be kept, all others MUST be ignored" — and SHOULD also support an exclude list (sdk.md:359-461, Stream configuration).

Current behavior

state/metric_stream.rb:91 (permalink) does attributes.merge!(view.attribute_keys). This adds/overwrites the given key-value pairs onto the measurement's attributes rather than filtering the measurement down to only the listed keys. Confirmed by test fixtures passing extra attributes (attribute_keys: { 'environment' => 'test' } in test/opentelemetry/sdk/metrics/state/metric_stream_test.rb:97). In addition, there is no exclude list support.

Suggested fix

Change attribute_keys handling to filter the measurement's attribute hash down to only the configured keys (attributes.slice(*view.attribute_keys) or equivalent), and add a separate exclude list option that removes named keys instead. This is potentially a breaking change fix. Anyone currently relying on attribute_keys to add literal values will need a different mechanism once this ships.

Related rows in SPEC_COMPLIANCE_METRICS.md

SDK-13

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at metrics_sdk/lib/opentelemetry/sdk/metrics/state/metric_stream.rb:91 and inspect the related fixtures in test/opentelemetry/sdk/metrics/state/metric_stream_test.rb:97. Verify the configured attribute_keys retain only matching measurement attributes, add the specified exclude-list behavior, and update tests so extra attributes and literal-value assumptions no longer pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
observability-sre
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.