fix(opentelemetry): honor MetricReader temporality in MetricProducer, closes #6253#6263
Open
mohamedramadan14 wants to merge 1 commit into
Open
Conversation
🦋 Changeset detectedLatest commit: 9571e91 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6253.
@effect/opentelemetry'sMetricProducerImplwas hardcodingAggregationTemporality.CUMULATIVEon every produced data point (Counter, UpDownCounter, Frequency, Summary count/sum, Gauge, Histogram). It never consulted the registeredMetricReader, so anytemporalityPreference(e.g.DELTA) configured onOTLPMetricExporter(or any customaggregationTemporalitySelector) 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 viareader.setMetricProducer(producer). So the producer cannot queryselectAggregationTemporalitydirectly duringcollect()without first remembering the reader at registration time.What the fix does
MetricProducerImplnow holds a list of registeredMetricReaders, populated inregisterProducer.collect()callsreader.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.CUMULATIVE, matching the OTel default).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)All 60 tests in
@effect/opentelemetrypass.pnpm check,pnpm build,pnpm docgenall green.Out of scope (noted as a follow-up)
packages/opentelemetry/src/OtlpMetrics.ts(the non-SDK direct-OTLP snapshot path) has the same hardcodedCUMULATIVE, but it does not use aMetricReader. A follow-up could add atemporalityoption toOtlpMetrics.makesince there is no reader to query there.