Isolate delta baselines for each metric reader - #6904
Conversation
🦋 Changeset detectedLatest commit: 87ea0bd The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
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 |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Reproduction test for delta multi-reader baseline sharing — adds
OtelMetricsMultiReaderDeltaRepro.test.tsthat creates a delta-mode producer, registers two readers, increments a counter, collects from both, and asserts both report[1, 1]. The test correctly reproduces the bug:MetricProducerImpl.collectupdates instance-levelpreviousCounterStateon each call, so the second reader computes its delta from already-advanced state and reports0.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Added
MetricProducerImpl.fork()— creates a fresh instance with independent delta-tracking state maps while sharing the same resource, context, and temporality. - Forked producer per reader in
registerProducer— each registeredMetricReadernow receives its ownMetricProducerImplcopy viafork(), isolating delta baselines so later readers compute deltas from their own collection interval. - Consolidated reproduction test into
OtelMetrics.test.ts— the standalone repro file is deleted and replaced with a permanent regression test that creates a delta producer, registers two readers, increments a counter, and asserts both report[1, 1].
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|

Summary
When multiple registered readers collect sequentially, later readers lose measurements already consumed by earlier readers.
Important
This PR starts with focused failing reproduction tests. Add the implementation fix to this same branch; CI is expected to fail until that fix is included.
Metric readers share one delta baseline
Module:
opentelemetry/OtelMetricsAudit ID:
adapters-otel-2-shared-reader-delta-baselineSeverity / confidence: high / high
What happens
When multiple registered readers collect sequentially, later readers lose measurements already consumed by earlier readers.
Why it happens
All readers share one MetricProducerImpl whose previous values and previous export time mutate after every collect.
Expected behavior
Each reader accepted by registerProducer must receive measurements for its own delta collection interval.
Relevant implementation
These links and excerpts are pinned to audit base
c9b56ab507f224426ee8388dc450da447ec4715f.packages/opentelemetry/src/OtelMetrics.ts:71-95packages/opentelemetry/src/internal/metrics.ts:46-65packages/opentelemetry/src/internal/metrics.ts:109-129packages/opentelemetry/src/internal/metrics.ts:395-398View problematic code at
packages/opentelemetry/src/OtelMetrics.ts:71-95View exact lines on GitHub
View problematic code at
packages/opentelemetry/src/internal/metrics.ts:46-65View exact lines on GitHub
View problematic code at
packages/opentelemetry/src/internal/metrics.ts:109-129View exact lines on GitHub
View problematic code at
packages/opentelemetry/src/internal/metrics.ts:395-398View exact lines on GitHub
Reproduction
pnpm test --run packages/opentelemetry/test/OtelMetricsMultiReaderDeltaRepro.test.tsObserved failure: Readers received [1, 0] instead of [1, 1] (1/1 failed).
Implementation handoff
The initial reproduction tests on this branch are the regression specification for the implementation fix that should follow in this PR.
pnpm test --run packages/opentelemetry/test/OtelMetricsMultiReaderDeltaRepro.test.tsAudit provenance
c9b56ab507f224426ee8388dc450da447ec4715fc9b56ab507f224426ee8388dc450da447ec4715fadapters-otel-2-shared-reader-delta-baselineCloses EFF-345