Class PrometheusCollector

java.lang.Object
io.prometheus.client.Collector
io.opentelemetry.exporter.prometheus.PrometheusCollector
All Implemented Interfaces:
io.opentelemetry.sdk.metrics.export.MetricReader

public final class PrometheusCollector extends io.prometheus.client.Collector implements io.opentelemetry.sdk.metrics.export.MetricReader
A reader of OpenTelemetry metrics that exports into Prometheus as a Collector.

Usage: sdkMeterProvider.registerMetricReader(PrometheusCollector.create());

  • Nested Class Summary

    Nested classes/interfaces inherited from class io.prometheus.client.Collector

    io.prometheus.client.Collector.Describable, io.prometheus.client.Collector.MetricFamilySamples, io.prometheus.client.Collector.Type
  • Field Summary

    Fields inherited from class io.prometheus.client.Collector

    MILLISECONDS_PER_SECOND, NANOSECONDS_PER_SECOND
  • Method Summary

    Modifier and Type
    Method
    Description
    List<io.prometheus.client.Collector.MetricFamilySamples>
     
    static io.opentelemetry.sdk.metrics.export.MetricReaderFactory
    Returns a new collector to be registered with a SdkMeterProviderBuilder.
    io.opentelemetry.sdk.common.CompletableResultCode
     
    io.opentelemetry.sdk.metrics.data.AggregationTemporality
     
    <T extends io.prometheus.client.Collector>
    T
    This method is called in MetricReaderFactory.apply(MetricProducer).
    io.opentelemetry.sdk.common.CompletableResultCode
     

    Methods inherited from class io.prometheus.client.Collector

    checkMetricLabelName, checkMetricName, collect, doubleToGoString, register, sanitizeMetricName

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • register

      public <T extends io.prometheus.client.Collector> T register()
      This method is called in MetricReaderFactory.apply(MetricProducer). Collector.register() triggers a call to collect(), which throws an error because MetricProducer.collectAllMetrics() is not yet read to accept calls. To get around this, we have collect() exit early until registration is complete.
      Overrides:
      register in class io.prometheus.client.Collector
    • collect

      public List<io.prometheus.client.Collector.MetricFamilySamples> collect()
      Specified by:
      collect in class io.prometheus.client.Collector
    • create

      public static io.opentelemetry.sdk.metrics.export.MetricReaderFactory create()
      Returns a new collector to be registered with a SdkMeterProviderBuilder.
    • getPreferredTemporality

      public io.opentelemetry.sdk.metrics.data.AggregationTemporality getPreferredTemporality()
      Specified by:
      getPreferredTemporality in interface io.opentelemetry.sdk.metrics.export.MetricReader
    • flush

      public io.opentelemetry.sdk.common.CompletableResultCode flush()
      Specified by:
      flush in interface io.opentelemetry.sdk.metrics.export.MetricReader
    • shutdown

      public io.opentelemetry.sdk.common.CompletableResultCode shutdown()
      Specified by:
      shutdown in interface io.opentelemetry.sdk.metrics.export.MetricReader