Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make AggregationTemporality configurable for OtlpInMemoryMetricExporter #7904

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.javaagent.testing.exporter;

import static java.util.logging.Level.CONFIG;

import io.opentelemetry.exporter.internal.otlp.metrics.MetricsRequestMarshaler;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.metrics.InstrumentType;
Expand All @@ -17,13 +19,34 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Logger;

class OtlpInMemoryMetricExporter implements MetricExporter {

private static final Logger logger = Logger.getLogger(OtlpInMemoryMetricExporter.class.getName());

private final Queue<byte[]> collectedRequests = new ConcurrentLinkedQueue<>();

private static final AggregationTemporality aggregationTemporality = initAggregationTemporality();

private static AggregationTemporality initAggregationTemporality() {
// this configuration setting is for external users
// see https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/7902
String temporalityProperty = System.getProperty("otel.javaagent.testing.exporter.temporality");
ptrdom marked this conversation as resolved.
Show resolved Hide resolved
AggregationTemporality aggregationTemporality;
if (temporalityProperty == null) {
aggregationTemporality = AggregationTemporality.DELTA;
} else {
aggregationTemporality =
AggregationTemporality.valueOf(temporalityProperty.toUpperCase(Locale.ROOT));
}
logger.log(CONFIG, "Setting aggregation temporality to {0}", aggregationTemporality.toString());
return aggregationTemporality;
}

List<byte[]> getCollectedExportRequests() {
return new ArrayList<>(collectedRequests);
}
Expand All @@ -34,7 +57,7 @@ void reset() {

@Override
public AggregationTemporality getAggregationTemporality(InstrumentType instrumentType) {
return AggregationTemporality.DELTA;
return aggregationTemporality;
}

@Override
Expand Down