Class SdkMeter

java.lang.Object
io.opentelemetry.sdk.metrics.SdkMeter
All Implemented Interfaces:
Meter

final class SdkMeter extends Object implements Meter
SdkMeter is SDK implementation of Meter.
  • Field Details

    • logger

      private static final Logger logger
    • VALID_INSTRUMENT_NAME_PATTERN

      private static final Pattern VALID_INSTRUMENT_NAME_PATTERN
      Instrument names MUST conform to the following syntax.
      • They are not null or empty strings.
      • They are case-insensitive, ASCII strings.
      • The first character must be an alphabetic character.
      • Subsequent characters must belong to the alphanumeric characters, '_', '.', '/', and '-'.
      • They can have a maximum length of 255 characters.
    • NOOP_METER

      private static final Meter NOOP_METER
    • NOOP_INSTRUMENT_NAME

      private static final String NOOP_INSTRUMENT_NAME
      See Also:
    • collectLock

      private final Object collectLock
    • callbackLock

      private final Object callbackLock
    • callbackRegistrations

      private final List<CallbackRegistration> callbackRegistrations
    • meterProviderSharedState

      private final MeterProviderSharedState meterProviderSharedState
    • instrumentationScopeInfo

      private final InstrumentationScopeInfo instrumentationScopeInfo
    • readerStorageRegistries

      private final Map<RegisteredReader,MetricStorageRegistry> readerStorageRegistries
    • meterEnabled

      private final boolean meterEnabled
  • Constructor Details

  • Method Details

    • getInstrumentationScopeInfo

      InstrumentationScopeInfo getInstrumentationScopeInfo()
    • collectAll

      Collection<MetricData> collectAll(RegisteredReader registeredReader, long epochNanos)
      Collect all metrics for the meter.
    • resetForTest

      void resetForTest()
      Reset the meter, clearing all registered callbacks and storages.
    • counterBuilder

      public LongCounterBuilder counterBuilder(String name)
      Description copied from interface: Meter
      Constructs a Counter instrument.

      This is used to build both synchronous instruments and asynchronous instruments (i.e. callbacks).

      Specified by:
      counterBuilder in interface Meter
      Parameters:
      name - the name of the Counter. Instrument names must consist of 255 or fewer characters including alphanumeric, _, ., -, /, and start with a letter.
      Returns:
      a builder for configuring a Counter instrument. Defaults to recording long values, but may be changed.
      See Also:
    • upDownCounterBuilder

      public LongUpDownCounterBuilder upDownCounterBuilder(String name)
      Description copied from interface: Meter
      Constructs an UpDownCounter instrument.

      This is used to build both synchronous instruments and asynchronous instruments (i.e. callbacks).

      Specified by:
      upDownCounterBuilder in interface Meter
      Parameters:
      name - the name of the UpDownCounter. Instrument names must consist of 255 or fewer characters including alphanumeric, _, ., -, /, and start with a letter.
      Returns:
      a builder for configuring an UpDownCounter instrument. Defaults to recording long values, but may be changed.
      See Also:
    • histogramBuilder

      public DoubleHistogramBuilder histogramBuilder(String name)
      Description copied from interface: Meter
      Constructs a Histogram instrument.
      Specified by:
      histogramBuilder in interface Meter
      Parameters:
      name - the name of the Histogram. Instrument names must consist of 255 or fewer characters including alphanumeric, _, ., -, /, and start with a letter.
      Returns:
      a builder for configuring a Histogram synchronous instrument. Defaults to recording double values, but may be changed.
      See Also:
    • gaugeBuilder

      public DoubleGaugeBuilder gaugeBuilder(String name)
      Description copied from interface: Meter
      Constructs an Asynchronous Gauge instrument.
      Specified by:
      gaugeBuilder in interface Meter
      Parameters:
      name - the name of the Gauge. Instrument names must consist of 255 or fewer characters including alphanumeric, _, ., -, /, and start with a letter.
      Returns:
      a builder used for configuring a Gauge instrument. Defaults to recording double values, but may be changed.
      See Also:
    • batchCallback

      public BatchCallback batchCallback(Runnable callback, ObservableMeasurement observableMeasurement, ObservableMeasurement... additionalMeasurements)
      Description copied from interface: Meter
      Constructs a batch callback.

      Batch callbacks allow a single callback to observe measurements for multiple asynchronous instruments.

      The callback will be called when the instruments are being observed.

      Callbacks are expected to abide by the following restrictions:

      • Run in a finite amount of time.
      • Safe to call repeatedly, across multiple threads.
      • Only observe values to registered instruments (i.e. observableMeasurement and additionalMeasurements
      Specified by:
      batchCallback in interface Meter
      Parameters:
      callback - a callback used to observe values on-demand.
      observableMeasurement - Instruments for which the callback may observe values.
      additionalMeasurements - Instruments for which the callback may observe values.
    • removeCallback

      void removeCallback(CallbackRegistration callbackRegistration)
      Unregister the callback.

      Callbacks are originally registered via registerCallback(CallbackRegistration).

    • registerCallback

      void registerCallback(CallbackRegistration callbackRegistration)
      Register the callback.

      The callback will be invoked once per collection until unregistered via removeCallback(CallbackRegistration).

    • isMeterEnabled

      boolean isMeterEnabled()
      Returns true if the MeterConfig.enabled() of the meter is true.
    • registerSynchronousMetricStorage

      WriteableMetricStorage registerSynchronousMetricStorage(InstrumentDescriptor instrument)
      Registers new synchronous storage associated with a given instrument.
    • registerObservableMeasurement

      SdkObservableMeasurement registerObservableMeasurement(InstrumentDescriptor instrumentDescriptor)
      Register new asynchronous storage associated with a given instrument.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • checkValidInstrumentName

      static boolean checkValidInstrumentName(String name)
      Check if the instrument name is valid. If invalid, log a warning.