Class InMemoryMetricExporter

java.lang.Object
io.opentelemetry.sdk.metrics.testing.InMemoryMetricExporter
All Implemented Interfaces:
MetricExporter

@Deprecated public final class InMemoryMetricExporter extends Object implements MetricExporter
Deprecated.
Moved to io.opentelemetry:opentelemetry-sdk-metrics-testing module.
A MetricExporter implementation that can be used to test OpenTelemetry integration.

Can be created using InMemoryMetricExporter.create()

Example usage:


 public class InMemoryMetricExporterExample {

   // creating InMemoryMetricExporter
   private final InMemoryMetricExporter exporter = InMemoryMetricExporter.create();
   private final MeterSdkProvider meterSdkProvider = OpenTelemetrySdk.getMeterProvider();
   private final Meter meter = meterSdkProvider.get("InMemoryMetricExporterExample");
   private IntervalMetricReader intervalMetricReader;

   void setup() {
     intervalMetricReader =
         IntervalMetricReader.builder()
             .setMetricExporter(exporter)
             .setMetricProducers(Collections.singletonList(meterSdkProvider.getMetricProducer()))
             .setExportIntervalMillis(1000)
             .build();
   }

   LongCounter generateLongCounterMeter(String name) {
     return meter.longCounterBuilder(name).setDescription("Sample LongCounter").build();
   }

   public static void main(String[] args) throws InterruptedException {
     InMemoryMetricExporterExample example = new InMemoryMetricExporterExample();
     example.setup();
     example.generateLongCounterMeter("counter-1");
   }
 }
 
  • Method Details

    • create

      public static InMemoryMetricExporter create()
      Deprecated.
      Returns a new InMemoryMetricExporter with a preferred temporality of AggregationTemporality.CUMULATIVE.
    • create

      public static InMemoryMetricExporter create(AggregationTemporality preferredTemporality)
      Deprecated.
      Returns a new InMemoryMetricExporter with the given preferredTemporality.
    • getFinishedMetricItems

      public List<MetricData> getFinishedMetricItems()
      Deprecated.
      Returns a List of the finished Metrics, represented by MetricData.
      Returns:
      a List of the finished Metrics.
    • reset

      public void reset()
      Deprecated.
      Clears the internal List of finished Metrics.

      Does not reset the state of this exporter if already shutdown.

    • getPreferredTemporality

      public AggregationTemporality getPreferredTemporality()
      Deprecated.
      Description copied from interface: MetricExporter
      Returns the preferred temporality for metrics.
      Specified by:
      getPreferredTemporality in interface MetricExporter
    • export

      public io.opentelemetry.sdk.common.CompletableResultCode export(Collection<MetricData> metrics)
      Deprecated.
      Exports the collection of Metrics into the inmemory queue.

      If this is called after shutdown, this will return ResultCode.FAILURE.

      Specified by:
      export in interface MetricExporter
      Parameters:
      metrics - the collection of MetricData to be exported.
      Returns:
      the result of the export, which is often an asynchronous operation.
    • flush

      public io.opentelemetry.sdk.common.CompletableResultCode flush()
      Deprecated.
      The InMemory exporter does not batch metrics, so this method will immediately return with success.
      Specified by:
      flush in interface MetricExporter
      Returns:
      always Success
    • shutdown

      public io.opentelemetry.sdk.common.CompletableResultCode shutdown()
      Deprecated.
      Clears the internal List of finished Metrics.

      Any subsequent call to export() function on this MetricExporter, will return CompletableResultCode.ofFailure()

      Specified by:
      shutdown in interface MetricExporter
      Returns:
      a CompletableResultCode which is completed when shutdown completes.