Package io.opentelemetry.sdk.metrics
Class SdkMeter
java.lang.Object
io.opentelemetry.sdk.metrics.SdkMeter
- All Implemented Interfaces:
Meter
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Object
private final List
<CallbackRegistration> private final Object
private final InstrumentationScopeInfo
private static final Logger
private final boolean
private final MeterProviderSharedState
private static final String
private static final Meter
private final Map
<RegisteredReader, MetricStorageRegistry> private static final Pattern
Instrument names MUST conform to the following syntax. -
Constructor Summary
ConstructorsConstructorDescriptionSdkMeter
(MeterProviderSharedState meterProviderSharedState, InstrumentationScopeInfo instrumentationScopeInfo, List<RegisteredReader> registeredReaders, MeterConfig meterConfig) -
Method Summary
Modifier and TypeMethodDescriptionbatchCallback
(Runnable callback, ObservableMeasurement observableMeasurement, ObservableMeasurement... additionalMeasurements) Constructs a batch callback.(package private) static boolean
Check if the instrument name is valid.(package private) Collection
<MetricData> collectAll
(RegisteredReader registeredReader, long epochNanos) Collect all metrics for the meter.counterBuilder
(String name) Constructs a Counter instrument.gaugeBuilder
(String name) Constructs an Asynchronous Gauge instrument.(package private) InstrumentationScopeInfo
histogramBuilder
(String name) Constructs a Histogram instrument.(package private) boolean
(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
Reset the meter, clearing all registered callbacks and storages.toString()
upDownCounterBuilder
(String name) Constructs an UpDownCounter instrument.
-
Field Details
-
logger
-
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
-
NOOP_INSTRUMENT_NAME
- See Also:
-
collectLock
-
callbackLock
-
callbackRegistrations
-
instrumentationScopeInfo
-
readerStorageRegistries
-
meterEnabled
private final boolean meterEnabled
-
-
Constructor Details
-
Method Details
-
getInstrumentationScopeInfo
InstrumentationScopeInfo getInstrumentationScopeInfo() -
collectAll
Collect all metrics for the meter. -
resetForTest
void resetForTest()Reset the meter, clearing all registered callbacks and storages. -
counterBuilder
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:
-
upDownCounterBuilder
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:
-
histogramBuilder
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:
-
gaugeBuilder
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:
-
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
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
Unregister the callback.Callbacks are originally registered via
registerCallback(CallbackRegistration)
. -
registerCallback
Register the callback.The callback will be invoked once per collection until unregistered via
removeCallback(CallbackRegistration)
. -
isMeterEnabled
boolean isMeterEnabled() -
registerSynchronousMetricStorage
Registers new synchronous storage associated with a given instrument. -
registerObservableMeasurement
Register new asynchronous storage associated with a given instrument. -
toString
-
checkValidInstrumentName
Check if the instrument name is valid. If invalid, log a warning.
-