Skip to content

Commit 4880dbe

Browse files
committed
fix(openfeature): use delta temporality for OTLP metrics export
1 parent c2e8fe0 commit 4880dbe

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

products/feature-flagging/feature-flagging-api/src/main/java/datadog/trace/api/openfeature/FlagEvalMetrics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class FlagEvalMetrics implements Closeable {
6262
OtlpHttpMetricExporter exporter =
6363
OtlpHttpMetricExporter.builder()
6464
.setEndpoint(endpoint)
65-
.setAggregationTemporalitySelector(AggregationTemporalitySelector.alwaysCumulative())
65+
.setAggregationTemporalitySelector(AggregationTemporalitySelector.deltaPreferred())
6666
.build();
6767

6868
PeriodicMetricReader reader =

products/feature-flagging/feature-flagging-api/src/test/java/datadog/trace/api/openfeature/FlagEvalMetricsTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
1414
import io.opentelemetry.sdk.metrics.data.LongPointData;
1515
import io.opentelemetry.sdk.metrics.data.MetricData;
16+
import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector;
1617
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
1718
import java.util.Collection;
1819
import org.junit.jupiter.api.Test;
@@ -145,11 +146,14 @@ void shutdownClearsCounter() {
145146
}
146147

147148
@Test
148-
void multipleRecordCallsAccumulateCumulativelyInExportedMetrics() {
149-
// InMemoryMetricReader defaults to cumulative temporality. This validates that N record()
150-
// calls produce a cumulative sum of N, matching the alwaysCumulative() selector configured
151-
// on the production OTLP exporter in FlagEvalMetrics.
152-
InMemoryMetricReader reader = InMemoryMetricReader.create();
149+
void multipleRecordCallsAccumulateWithDeltaTemporality() {
150+
// Use delta temporality to match the deltaPreferred() selector configured on the production
151+
// OTLP exporter in FlagEvalMetrics. Delta temporality exports only increments since last
152+
// collection, which is what OTLP receivers expect.
153+
InMemoryMetricReader reader =
154+
InMemoryMetricReader.builder()
155+
.setAggregationTemporalitySelector(AggregationTemporalitySelector.deltaPreferred())
156+
.build();
153157
SdkMeterProvider provider = SdkMeterProvider.builder().registerMetricReader(reader).build();
154158

155159
try (FlagEvalMetrics metrics = new FlagEvalMetrics(provider)) {
@@ -165,12 +169,12 @@ void multipleRecordCallsAccumulateCumulativelyInExportedMetrics() {
165169
.orElseThrow(() -> new AssertionError("feature_flag.evaluations metric not found"));
166170

167171
assertEquals(
168-
AggregationTemporality.CUMULATIVE,
172+
AggregationTemporality.DELTA,
169173
metric.getLongSumData().getAggregationTemporality(),
170-
"Exported metric must use CUMULATIVE temporality");
174+
"Exported metric must use DELTA temporality");
171175

172176
LongPointData point = metric.getLongSumData().getPoints().iterator().next();
173-
assertEquals(5L, point.getValue(), "5 record() calls must produce a cumulative sum of 5");
177+
assertEquals(5L, point.getValue(), "5 record() calls must produce a delta sum of 5");
174178
}
175179
}
176180

0 commit comments

Comments
 (0)