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.
Moved to io.opentelemetry:opentelemetry-sdk-metrics-testing module.
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 Details

    • create

      public static InMemoryMetricReader create()
      Deprecated.
      Returns a new InMemoryMetricReader.
    • createDelta

      public static InMemoryMetricReader createDelta()
      Deprecated.
      Creates a new InMemoryMetricReader that prefers DELTA aggregation.
    • collectAllMetrics

      public Collection<MetricData> collectAllMetrics()
      Deprecated.
      Returns all metrics accumulated since the last call.
    • getPreferredTemporality

      public AggregationTemporality getPreferredTemporality()
      Deprecated.
      Description copied from interface: MetricReader
      Return The preferred temporality for metrics.
      Specified by:
      getPreferredTemporality in interface MetricReader
    • flush

      public io.opentelemetry.sdk.common.CompletableResultCode flush()
      Deprecated.
      Description copied from interface: MetricReader
      Flushes metrics read by this reader.

      In all scenarios, the associated MetricProducer should have its MetricProducer.collectAllMetrics() method called.

      For push endpoints, this should collect and report metrics as normal.

      Specified by:
      flush in interface MetricReader
      Returns:
      the result of the shutdown.
    • shutdown

      public io.opentelemetry.sdk.common.CompletableResultCode shutdown()
      Deprecated.
      Description copied from interface: MetricReader
      Shuts 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:
      shutdown in interface MetricReader
      Returns:
      the result of the shutdown.
    • apply

      public MetricReader apply(MetricProducer producer)
      Deprecated.
      Description copied from interface: MetricReaderFactory
      Construct a new MetricReader.
      Specified by:
      apply in interface MetricReaderFactory
      Parameters:
      producer - the mechanism of reading SDK metrics.
      Returns:
      a controller for this metric reader.