Class InMemoryMetricReader
java.lang.Object
io.opentelemetry.sdk.metrics.testing.InMemoryMetricReader
- All Implemented Interfaces:
MetricReader,MetricReaderFactory
@Deprecated
public class InMemoryMetricReader
extends Object
implements MetricReader, MetricReaderFactory
Deprecated.
A
MetricReader implementation that can be used to test OpenTelemetry integration.
Can be created using InMemoryMetricReader.create()
Example usage:
public class InMemoryMetricReaderExample {
private final InMemoryMetricReader reader = InMemoryMetricReader.create();
private final SdkMeterProvider sdkMeterProvider = SdkMeterProvider.builder().registerMetricReader(reader).build();
private final Meter meter = sdkMeterProvider.get("example");
private final LongCounter metricCallCount = meter.counterBuilder("num_collects");
public void printMetrics() {
metricCallCount.add(1);
System.out.println(reader.collectAllMetrics());
}
public static void main(String[] args) {
InMemoryMetricReaderExample example = new InMemoryMetricReaderExample();
example.printMetrics();
}
}
-
Method Summary
Modifier and TypeMethodDescriptionapply(MetricProducer producer) Deprecated.Construct a new MetricReader.Deprecated.Returns all metrics accumulated since the last call.static InMemoryMetricReadercreate()Deprecated.Returns a newInMemoryMetricReader.static InMemoryMetricReaderDeprecated.Creates a newInMemoryMetricReaderthat prefers DELTA aggregation.io.opentelemetry.sdk.common.CompletableResultCodeflush()Deprecated.Flushes metrics read by this reader.Deprecated.Return The preferred temporality for metrics.io.opentelemetry.sdk.common.CompletableResultCodeshutdown()Deprecated.Shuts down the metric reader.
-
Method Details
-
create
Deprecated.Returns a newInMemoryMetricReader. -
createDelta
Deprecated.Creates a newInMemoryMetricReaderthat prefers DELTA aggregation. -
collectAllMetrics
Deprecated.Returns all metrics accumulated since the last call. -
getPreferredTemporality
Deprecated.Description copied from interface:MetricReaderReturn The preferred temporality for metrics.- Specified by:
getPreferredTemporalityin interfaceMetricReader
-
flush
public io.opentelemetry.sdk.common.CompletableResultCode flush()Deprecated.Description copied from interface:MetricReaderFlushes metrics read by this reader.In all scenarios, the associated
MetricProducershould have itsMetricProducer.collectAllMetrics()method called.For push endpoints, this should collect and report metrics as normal.
- Specified by:
flushin interfaceMetricReader- Returns:
- the result of the shutdown.
-
shutdown
public io.opentelemetry.sdk.common.CompletableResultCode shutdown()Deprecated.Description copied from interface:MetricReaderShuts down the metric reader.For pull endpoints, like prometheus, this should shut down the metric hosting endpoint or server doing such a job.
For push endpoints, this should shut down any scheduler threads.
- Specified by:
shutdownin interfaceMetricReader- Returns:
- the result of the shutdown.
-
apply
Deprecated.Description copied from interface:MetricReaderFactoryConstruct a new MetricReader.- Specified by:
applyin interfaceMetricReaderFactory- Parameters:
producer- the mechanism of reading SDK metrics.- Returns:
- a controller for this metric reader.
-
io.opentelemetry:opentelemetry-sdk-metrics-testingmodule.