Skip to content
Merged
Show file tree
Hide file tree
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 @@ -12,10 +12,10 @@
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import java.io.IOException;
import java.util.Collection;
import java.util.function.Function;

/**
* This class implements a {@link MetricExporter} that delegates to an instance of {@code
Expand All @@ -24,22 +24,17 @@
public class MetricToDiskExporter implements MetricExporter {

private final ToDiskExporter<MetricData> delegate;
private final Function<InstrumentType, AggregationTemporality> typeToTemporality;
private final AggregationTemporalitySelector aggregationTemporalitySelector;

/**
* Creates a new MetricToDiskExporter that will buffer Metric telemetry on disk storage.
*
* @param delegate - The MetricExporter to delegate to if disk writing fails.
* @param config - The StorageConfiguration that specifies how storage is managed.
* @param typeToTemporality - The function that maps an InstrumentType into an
* AggregationTemporality.
* @return A new MetricToDiskExporter instance.
* @throws IOException if the delegate ToDiskExporter could not be created.
*/
public static MetricToDiskExporter create(
MetricExporter delegate,
StorageConfiguration config,
Function<InstrumentType, AggregationTemporality> typeToTemporality)
public static MetricToDiskExporter create(MetricExporter delegate, StorageConfiguration config)
throws IOException {
ToDiskExporter<MetricData> toDisk =
ToDiskExporter.<MetricData>builder()
Expand All @@ -48,15 +43,14 @@ public static MetricToDiskExporter create(
.setSerializer(SignalSerializer.ofMetrics())
.setExportFunction(delegate::export)
.build();
return new MetricToDiskExporter(toDisk, typeToTemporality);
return new MetricToDiskExporter(toDisk, delegate);
}

// VisibleForTesting
MetricToDiskExporter(
ToDiskExporter<MetricData> delegate,
Function<InstrumentType, AggregationTemporality> typeToTemporality) {
ToDiskExporter<MetricData> delegate, AggregationTemporalitySelector selector) {
this.delegate = delegate;
this.typeToTemporality = typeToTemporality;
this.aggregationTemporalitySelector = selector;
}

@Override
Expand All @@ -81,6 +75,6 @@ public CompletableResultCode shutdown() {

@Override
public AggregationTemporality getAggregationTemporality(InstrumentType instrumentType) {
return typeToTemporality.apply(instrumentType);
return aggregationTemporalitySelector.getAggregationTemporality(instrumentType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ void setUp() throws IOException {
memoryMetricExporter = InMemoryMetricExporter.create();
ToDiskExporter<MetricData> toDiskMetricExporter =
buildToDiskExporter(SignalSerializer.ofMetrics(), memoryMetricExporter::export);
metricToDiskExporter =
new MetricToDiskExporter(
toDiskMetricExporter, memoryMetricExporter::getAggregationTemporality);
metricToDiskExporter = new MetricToDiskExporter(toDiskMetricExporter, memoryMetricExporter);
meterProvider = createMeterProvider(metricToDiskExporter);
meter = meterProvider.get("MetricInstrumentationScope");

Expand Down
Loading