Skip to content

Commit 2a20f5e

Browse files
authored
Make AggregationTemporality configurable for OtlpInMemoryMetricExporter (#7904)
References #7902. Not sure if system property name is the most appropriate or if any tests are required for these changes.
1 parent 7bb978d commit 2a20f5e

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

testing/agent-exporter/src/main/java/io/opentelemetry/javaagent/testing/exporter/OtlpInMemoryMetricExporter.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.opentelemetry.javaagent.testing.exporter;
77

8+
import static java.util.logging.Level.CONFIG;
9+
810
import io.opentelemetry.exporter.internal.otlp.metrics.MetricsRequestMarshaler;
911
import io.opentelemetry.sdk.common.CompletableResultCode;
1012
import io.opentelemetry.sdk.metrics.InstrumentType;
@@ -17,13 +19,34 @@
1719
import java.util.ArrayList;
1820
import java.util.Collection;
1921
import java.util.List;
22+
import java.util.Locale;
2023
import java.util.Queue;
2124
import java.util.concurrent.ConcurrentLinkedQueue;
25+
import java.util.logging.Logger;
2226

2327
class OtlpInMemoryMetricExporter implements MetricExporter {
2428

29+
private static final Logger logger = Logger.getLogger(OtlpInMemoryMetricExporter.class.getName());
30+
2531
private final Queue<byte[]> collectedRequests = new ConcurrentLinkedQueue<>();
2632

33+
private static final AggregationTemporality aggregationTemporality = initAggregationTemporality();
34+
35+
private static AggregationTemporality initAggregationTemporality() {
36+
// this configuration setting is for external users
37+
// see https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/7902
38+
String temporalityProperty = System.getProperty("otel.javaagent.testing.exporter.temporality");
39+
AggregationTemporality aggregationTemporality;
40+
if (temporalityProperty == null) {
41+
aggregationTemporality = AggregationTemporality.DELTA;
42+
} else {
43+
aggregationTemporality =
44+
AggregationTemporality.valueOf(temporalityProperty.toUpperCase(Locale.ROOT));
45+
}
46+
logger.log(CONFIG, "Setting aggregation temporality to {0}", aggregationTemporality.toString());
47+
return aggregationTemporality;
48+
}
49+
2750
List<byte[]> getCollectedExportRequests() {
2851
return new ArrayList<>(collectedRequests);
2952
}
@@ -34,7 +57,7 @@ void reset() {
3457

3558
@Override
3659
public AggregationTemporality getAggregationTemporality(InstrumentType instrumentType) {
37-
return AggregationTemporality.DELTA;
60+
return aggregationTemporality;
3861
}
3962

4063
@Override

0 commit comments

Comments
 (0)