Skip to content

fix(opentelemetry): honor MetricReader temporality in MetricProducer, closes #6253#6263

Open
mohamedramadan14 wants to merge 1 commit into
Effect-TS:mainfrom
mohamedramadan14:fix/opentelemetry-reader-temporality-6253
Open

fix(opentelemetry): honor MetricReader temporality in MetricProducer, closes #6253#6263
mohamedramadan14 wants to merge 1 commit into
Effect-TS:mainfrom
mohamedramadan14:fix/opentelemetry-reader-temporality-6253

Conversation

@mohamedramadan14

Copy link
Copy Markdown

Fixes #6253.

@effect/opentelemetry's MetricProducerImpl was hardcoding AggregationTemporality.CUMULATIVE on every produced data point (Counter, UpDownCounter, Frequency, Summary count/sum, Gauge, Histogram). It never consulted the registered MetricReader, so any temporalityPreference (e.g. DELTA) configured on OTLPMetricExporter (or any custom aggregationTemporalitySelector) was silently overridden.

Why this needs a small adaptation of the issue's suggested fix #1

The OTel MetricProducer.collect() interface only receives { timeoutMillis } — not a reader reference. The reader is given to the producer one-way via reader.setMetricProducer(producer). So the producer cannot query selectAggregationTemporality directly during collect() without first remembering the reader at registration time.

What the fix does

  • MetricProducerImpl now holds a list of registered MetricReaders, populated in registerProducer.
  • collect() calls reader.selectAggregationTemporality(descriptor.type) per produced data point and stamps that on the result. The 5 hardcoded sites (Counter, Gauge, Histogram, Frequency, Summary count/sum) all go through one helper.
  • No reader registered → unchanged (CUMULATIVE, matching the OTel default).
  • Multiple readers, all agree → use that preference.
  • Multiple readers, disagree → use the first reader's preference and emit a single diag.warn(...) (non-fatal, non-breaking).

Why option (1) over option (2)

Option (1) is spec-compliant and requires zero user-side configuration; option (2) would have made users re-state the reader's preference on the producer side.

Tests added (packages/opentelemetry/test/Metrics.test.ts)

  • counter honors reader's preferred temporality (DELTA) — the exact issue repro
  • gauge honors reader's preferred temporality (DELTA)
  • falls back to CUMULATIVE when no reader is registered

All 60 tests in @effect/opentelemetry pass. pnpm check, pnpm build, pnpm docgen all green.

Out of scope (noted as a follow-up)

packages/opentelemetry/src/OtlpMetrics.ts (the non-SDK direct-OTLP snapshot path) has the same hardcoded CUMULATIVE, but it does not use a MetricReader. A follow-up could add a temporality option to OtlpMetrics.make since there is no reader to query there.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jun 8, 2026
@changeset-bot

changeset-bot Bot commented Jun 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9571e91

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@effect/opentelemetry Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

@effect/opentelemetry: MetricProducer hardcodes CUMULATIVE temporality, ignoring OTLPMetricExporter temporalityPreference Proposals

1 participant