Skip to content

sdk/metric: Retain advisory attributes when View has no AttributeFilter - #8859

Open
dashpole wants to merge 3 commits into
open-telemetry:mainfrom
dashpole:fix-view-default-attributes
Open

sdk/metric: Retain advisory attributes when View has no AttributeFilter#8859
dashpole wants to merge 3 commits into
open-telemetry:mainfrom
dashpole:fix-view-default-attributes

Conversation

@dashpole

Copy link
Copy Markdown
Contributor

Fixes #8857.

According to the OpenTelemetry Metrics SDK specification, if attribute_keys is not provided on a View, the SDK should use the 'Attributes' advisory parameter configured on the instrument. Previously, when a View matched an instrument without setting an AttributeFilter, the stream's AttributeFilter remained nil, causing the pipeline to drop the instrument's advisory default attributes.

Centralize AttributeFilter defaulting inside cachedAggregator alongside aggregation and exemplar reservoir provider defaulting.

@dashpole
dashpole force-pushed the fix-view-default-attributes branch from e8ff568 to 8e67a60 Compare August 24, 2026 20:18
@dashpole
dashpole requested a lite review from Copilot August 24, 2026 20:20
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.4%. Comparing base (1ad6638) to head (4e4c8e5).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #8859     +/-   ##
=======================================
- Coverage   88.4%   88.4%   -0.1%     
=======================================
  Files        331     331             
  Lines      21001   21001             
=======================================
- Hits       18572   18571      -1     
- Misses      2429    2430      +1     
Files with missing lines Coverage Δ
sdk/metric/pipeline.go 92.7% <100.0%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a Metrics SDK spec compliance gap in go.opentelemetry.io/otel/sdk/metric: when a View matches an instrument but does not specify attribute_keys (i.e., Stream.AttributeFilter is nil), the SDK now correctly falls back to the instrument’s advisory default attributes (configured via metric/x.WithDefaultAttributes) instead of treating it as “allow all attributes”.

Changes:

  • Centralizes Stream.AttributeFilter defaulting in inserter.cachedAggregator, applying advisory default attributes when a View omits an attribute filter.
  • Updates pipeline unit tests and adds a meter-level regression test to cover “View matches without AttributeFilter” behavior (and preserves explicit View filter override behavior).
  • Adds a changelog entry describing the fix in go.opentelemetry.io/otel/sdk/metric.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
sdk/metric/pipeline.go Passes instrument advisory keys into cachedAggregator and applies AttributeFilter defaulting there when Views omit it.
sdk/metric/pipeline_test.go Updates cachedAggregator call sites to match the new signature.
sdk/metric/meter_test.go Adds regression coverage for matched Views without an attribute filter and validates explicit filter override behavior.
CHANGELOG.md Documents the user-visible behavior fix in the Unreleased “Fixed” section.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread sdk/metric/meter_test.go
Fixes open-telemetry#8857.

According to the OpenTelemetry Metrics SDK specification, if attribute_keys
is not provided on a View, the SDK should use the 'Attributes' advisory parameter
configured on the instrument. Previously, when a View matched an instrument
without setting an AttributeFilter, the stream's AttributeFilter remained nil,
causing the pipeline to drop the instrument's advisory default attributes.

Centralize AttributeFilter defaulting inside cachedAggregator alongside
aggregation and exemplar reservoir provider defaulting.
@dashpole
dashpole force-pushed the fix-view-default-attributes branch from e5c50c0 to 45741ba Compare August 26, 2026 13:40
@dashpole
dashpole marked this pull request as ready for review August 26, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WithDefaultAttributes is overridden by nil attribute filter in views

2 participants