Package io.opentelemetry.sdk.metrics
Class SdkMeter
- java.lang.Object
-
- io.opentelemetry.sdk.metrics.SdkMeter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SdkMeter.MultiWritableMetricStorage
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object
callbackLock
private java.util.List<CallbackRegistration>
callbackRegistrations
private java.lang.Object
collectLock
private InstrumentationScopeInfo
instrumentationScopeInfo
private static java.util.logging.Logger
logger
private boolean
meterEnabled
private MeterProviderSharedState
meterProviderSharedState
private static java.lang.String
NOOP_INSTRUMENT_NAME
private static Meter
NOOP_METER
private java.util.Map<RegisteredReader,MetricStorageRegistry>
readerStorageRegistries
private static java.util.regex.Pattern
VALID_INSTRUMENT_NAME_PATTERN
Instrument names MUST conform to the following syntax.
-
Constructor Summary
Constructors Constructor Description SdkMeter(MeterProviderSharedState meterProviderSharedState, InstrumentationScopeInfo instrumentationScopeInfo, java.util.List<RegisteredReader> registeredReaders, MeterConfig meterConfig)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BatchCallback
batchCallback(java.lang.Runnable callback, ObservableMeasurement observableMeasurement, ObservableMeasurement... additionalMeasurements)
Constructs a batch callback.(package private) static boolean
checkValidInstrumentName(java.lang.String name)
Check if the instrument name is valid.(package private) java.util.Collection<MetricData>
collectAll(RegisteredReader registeredReader, long epochNanos)
Collect all metrics for the meter.LongCounterBuilder
counterBuilder(java.lang.String name)
Constructs a Counter instrument.DoubleGaugeBuilder
gaugeBuilder(java.lang.String name)
Constructs an Asynchronous Gauge instrument.(package private) InstrumentationScopeInfo
getInstrumentationScopeInfo()
DoubleHistogramBuilder
histogramBuilder(java.lang.String name)
Constructs a Histogram instrument.(package private) boolean
isMeterEnabled()
(package private) void
registerCallback(CallbackRegistration callbackRegistration)
Register the callback.(package private) SdkObservableMeasurement
registerObservableMeasurement(InstrumentDescriptor instrumentDescriptor)
Register new asynchronous storage associated with a given instrument.(package private) WriteableMetricStorage
registerSynchronousMetricStorage(InstrumentDescriptor instrument)
Registers new synchronous storage associated with a given instrument.(package private) void
removeCallback(CallbackRegistration callbackRegistration)
Unregister the callback.(package private) void
resetForTest()
Reset the meter, clearing all registered callbacks and storages.java.lang.String
toString()
LongUpDownCounterBuilder
upDownCounterBuilder(java.lang.String name)
Constructs an UpDownCounter instrument.
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
VALID_INSTRUMENT_NAME_PATTERN
private static final java.util.regex.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 java.lang.String NOOP_INSTRUMENT_NAME
- See Also:
- Constant Field Values
-
collectLock
private final java.lang.Object collectLock
-
callbackLock
private final java.lang.Object callbackLock
-
callbackRegistrations
private final java.util.List<CallbackRegistration> callbackRegistrations
-
meterProviderSharedState
private final MeterProviderSharedState meterProviderSharedState
-
instrumentationScopeInfo
private final InstrumentationScopeInfo instrumentationScopeInfo
-
readerStorageRegistries
private final java.util.Map<RegisteredReader,MetricStorageRegistry> readerStorageRegistries
-
meterEnabled
private final boolean meterEnabled
-
-
Constructor Detail
-
SdkMeter
SdkMeter(MeterProviderSharedState meterProviderSharedState, InstrumentationScopeInfo instrumentationScopeInfo, java.util.List<RegisteredReader> registeredReaders, MeterConfig meterConfig)
-
-
Method Detail
-
getInstrumentationScopeInfo
InstrumentationScopeInfo getInstrumentationScopeInfo()
-
collectAll
java.util.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(java.lang.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 interfaceMeter
- 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:
- Instrument Naming Rule
-
upDownCounterBuilder
public LongUpDownCounterBuilder upDownCounterBuilder(java.lang.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 interfaceMeter
- 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:
- Instrument Naming Rule
-
histogramBuilder
public DoubleHistogramBuilder histogramBuilder(java.lang.String name)
Description copied from interface:Meter
Constructs a Histogram instrument.- Specified by:
histogramBuilder
in interfaceMeter
- 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:
- Instrument Naming Rule
-
gaugeBuilder
public DoubleGaugeBuilder gaugeBuilder(java.lang.String name)
Description copied from interface:Meter
Constructs an Asynchronous Gauge instrument.- Specified by:
gaugeBuilder
in interfaceMeter
- 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:
- Instrument Naming Rule
-
batchCallback
public BatchCallback batchCallback(java.lang.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
andadditionalMeasurements
- Specified by:
batchCallback
in interfaceMeter
- 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()
-
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 java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
checkValidInstrumentName
static boolean checkValidInstrumentName(java.lang.String name)
Check if the instrument name is valid. If invalid, log a warning.
-
-