Skip to content

Ignore reader preferred aggregations incompatible with async instruments - #5554

Open
Eason09053360 wants to merge 2 commits into
open-telemetry:mainfrom
Eason09053360:fix-reader-preferred-aggregation-async-incompatibility
Open

Ignore reader preferred aggregations incompatible with async instruments#5554
Eason09053360 wants to merge 2 commits into
open-telemetry:mainfrom
Eason09053360:fix-reader-preferred-aggregation-async-incompatibility

Conversation

@Eason09053360

@Eason09053360 Eason09053360 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

No existing issue — found by reading the code.

MetricReaderStorage warns and skips a View that configures a histogram
aggregation for an asynchronous instrument. The same aggregation set through
MetricReader(preferred_aggregation=...) skips that check and silently produces
no data at all: histogram aggregations only implement the DELTA instrument
temporality path, so asynchronous instruments (always CUMULATIVE) return None
from every collect().

from opentelemetry.metrics import Observation
from opentelemetry.sdk.metrics import MeterProvider, ObservableCounter
from opentelemetry.sdk.metrics.export import InMemoryMetricReader
from opentelemetry.sdk.metrics.view import ExplicitBucketHistogramAggregation

reader = InMemoryMetricReader(
    preferred_aggregation={ObservableCounter: ExplicitBucketHistogramAggregation()}
)
meter = MeterProvider(metric_readers=[reader]).get_meter("repro")
meter.create_observable_counter("my_counter", callbacks=[lambda options: [Observation(7)]])

print(reader.get_metrics_data())  # None, and nothing logged

Both histogram aggregations and all three asynchronous instrument classes are
affected. Synchronous instruments are not, so the OTLP exporter's
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION handling (which maps
Histogram) is unchanged.

This warns and keeps the instrument's default aggregation, matching what the
View path already does.

Related: #5461 fixes the matching gap on the View path. Different file and
function, so the two can be reviewed independently.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • New test_configure_aggregation_asynchronous_histogram_incompatibility
    (3 async instrument classes × both histogram aggregations) and
    test_configure_aggregation_synchronous_histogram_allowed.
  • opentelemetry-sdk/tests/metrics/ — 309 passed, 1 skipped.

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

MetricReaderStorage warns and skips a View that configures a histogram
aggregation for an asynchronous instrument, but the same aggregation
selected through MetricReader(preferred_aggregation=...) bypassed that
check entirely.

Histogram aggregations only implement the DELTA instrument temporality
path, so asynchronous instruments -- which always report as CUMULATIVE --
silently produced no data points on every collection. This affected both
ExplicitBucketHistogramAggregation and ExponentialBucketHistogramAggregation
across all three asynchronous instrument classes.

Warn and keep the instrument's default aggregation instead, so selecting
an aggregation through a reader behaves the same as selecting it through
a view.
@Eason09053360
Eason09053360 marked this pull request as ready for review August 17, 2026 17:31
@Eason09053360
Eason09053360 requested a review from a team as a code owner August 17, 2026 17:31
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Aug 17, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-08-21 01:46 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@Eason09053360
Eason09053360 marked this pull request as draft August 18, 2026 02:32
@Eason09053360
Eason09053360 marked this pull request as ready for review August 18, 2026 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant