opentelemetry.metrics package¶
Module contents¶
The OpenTelemetry metrics API describes the classes used to report raw measurements, as well as metrics with known aggregation and labels.
The Meter class is used to construct Metric s to record raw statistics
as well as metrics with predefined aggregation.
Meter s can be obtained via the MeterProvider, corresponding to the name
of the instrumenting library and (optionally) a version.
See the metrics api spec for terminology and context clarification.
-
class
opentelemetry.metrics.DefaultBoundCounter[source]¶ Bases:
opentelemetry.metrics.BoundCounterThe default bound counter instrument.
Used when no bound counter implementation is available.
-
class
opentelemetry.metrics.DefaultBoundUpDownCounter[source]¶ Bases:
opentelemetry.metrics.BoundUpDownCounterThe default bound updowncounter instrument.
Used when no bound updowncounter implementation is available.
-
class
opentelemetry.metrics.DefaultBoundValueRecorder[source]¶ Bases:
opentelemetry.metrics.BoundValueRecorderThe default bound valuerecorder instrument.
Used when no bound valuerecorder implementation is available.
-
class
opentelemetry.metrics.Metric[source]¶ Bases:
abc.ABCBase class for various types of metrics.
Metric class that inherit from this class are specialized with the type of bound metric instrument that the metric holds.
-
class
opentelemetry.metrics.Counter[source]¶ Bases:
opentelemetry.metrics.MetricA counter type metric that expresses the computation of a sum.
-
abstract
add(value, labels)[source]¶ Increases the value of the counter by
value.- Parameters
value (~ValueT) – The value to add to the counter metric. Should be positive or zero. For a Counter that can decrease, use
UpDownCounter.labels (
Dict[str,str]) – Labels to associate with the bound instrument.
- Return type
None
-
abstract
-
class
opentelemetry.metrics.DefaultCounter[source]¶ Bases:
opentelemetry.metrics.CounterThe default counter instrument.
Used when no
Counterimplementation is available.-
bind(labels)[source]¶ Gets a bound metric instrument.
Bound metric instruments are useful to reduce the cost of repeatedly recording a metric with a pre-defined set of label values.
-
add(value, labels)[source]¶ Increases the value of the counter by
value.- Parameters
value (~ValueT) – The value to add to the counter metric. Should be positive or zero. For a Counter that can decrease, use
UpDownCounter.labels (
Dict[str,str]) – Labels to associate with the bound instrument.
- Return type
None
-
-
class
opentelemetry.metrics.UpDownCounter[source]¶ Bases:
opentelemetry.metrics.MetricA counter type metric that expresses the computation of a sum, allowing negative increments.
-
class
opentelemetry.metrics.DefaultUpDownCounter[source]¶ Bases:
opentelemetry.metrics.UpDownCounterThe default updowncounter instrument.
Used when no
UpDownCounterimplementation is available.-
bind(labels)[source]¶ Gets a bound metric instrument.
Bound metric instruments are useful to reduce the cost of repeatedly recording a metric with a pre-defined set of label values.
-
-
class
opentelemetry.metrics.ValueRecorder[source]¶ Bases:
opentelemetry.metrics.MetricA valuerecorder type metric that represent raw stats.
-
class
opentelemetry.metrics.DefaultValueRecorder[source]¶ Bases:
opentelemetry.metrics.ValueRecorderThe default valuerecorder instrument.
Used when no
ValueRecorderimplementation is available.
-
class
opentelemetry.metrics.Observer[source]¶ Bases:
abc.ABCAn observer type metric instrument used to capture a current set of values.
Observer instruments are asynchronous, a callback is invoked with the observer instrument as argument allowing the user to capture multiple values per collection interval.
-
class
opentelemetry.metrics.SumObserver[source]¶ Bases:
opentelemetry.metrics.ObserverAsynchronous instrument used to capture a monotonic sum.
-
class
opentelemetry.metrics.DefaultSumObserver[source]¶ Bases:
opentelemetry.metrics.SumObserverNo-op implementation of
SumObserver.
-
class
opentelemetry.metrics.UpDownSumObserver[source]¶ Bases:
opentelemetry.metrics.ObserverAsynchronous instrument used to capture a non-monotonic count.
-
class
opentelemetry.metrics.DefaultUpDownSumObserver[source]¶ Bases:
opentelemetry.metrics.UpDownSumObserverNo-op implementation of
UpDownSumObserver.
-
class
opentelemetry.metrics.ValueObserver[source]¶ Bases:
opentelemetry.metrics.ObserverAsynchronous instrument used to capture grouping measurements.
-
class
opentelemetry.metrics.DefaultValueObserver[source]¶ Bases:
opentelemetry.metrics.ValueObserverNo-op implementation of
ValueObserver.
-
class
opentelemetry.metrics.MeterProvider[source]¶ Bases:
abc.ABC-
abstract
get_meter(instrumenting_module_name, instrumenting_library_version='')[source]¶ Returns a
Meterfor use by the given instrumentation library.This function may return different
Metertypes (e.g. a no-op meter vs. a functional meter).- Parameters
instrumenting_module_name (
str) –The name of the instrumenting module (usually just
__name__).This should not be the name of the module that is instrumented but the name of the module doing the instrumentation. E.g., instead of
"requests", use"opentelemetry.instrumentation.requests".instrumenting_library_version (
str) – Optional. The version string of the instrumenting library. Usually this should be the same aspkg_resources.get_distribution(instrumenting_library_name).version.
- Return type
-
abstract
-
class
opentelemetry.metrics.DefaultMeterProvider[source]¶ Bases:
opentelemetry.metrics.MeterProviderThe default MeterProvider, used when no implementation is available.
All operations are no-op.
-
get_meter(instrumenting_module_name, instrumenting_library_version='')[source]¶ Returns a
Meterfor use by the given instrumentation library.This function may return different
Metertypes (e.g. a no-op meter vs. a functional meter).- Parameters
instrumenting_module_name (
str) –The name of the instrumenting module (usually just
__name__).This should not be the name of the module that is instrumented but the name of the module doing the instrumentation. E.g., instead of
"requests", use"opentelemetry.instrumentation.requests".instrumenting_library_version (
str) – Optional. The version string of the instrumenting library. Usually this should be the same aspkg_resources.get_distribution(instrumenting_library_name).version.
- Return type
-
-
class
opentelemetry.metrics.Meter[source]¶ Bases:
abc.ABCAn interface to allow the recording of metrics.
Metrics or metric instruments, are devices used for capturing raw measurements. Each metric instrument supports a single method, each with fixed interpretation to capture measurements.-
abstract
record_batch(labels, record_tuples)[source]¶ Atomically records a batch of
Metricand value pairs.Allows the functionality of acting upon multiple metrics with a single API call. Implementations should find bound metric instruments that match the key-value pairs in the labels.
-
abstract
create_counter(name, description, unit, value_type, enabled=True)[source]¶ Creates a
Countermetric with typevalue_type.- Parameters
name (
str) – The name of the metric.description (
str) – Human-readable description of the metric.unit (
str) – Unit of the metric values following the UCUM convention (https://unitsofmeasure.org/ucum.html).value_type (
Type[~ValueT]) – The type of values being recorded by the metric.enabled (
bool) – Whether to report the metric by default.
- Return type
-
abstract
create_updowncounter(name, description, unit, value_type, enabled=True)[source]¶ Creates a
UpDownCountermetric with typevalue_type.- Parameters
name (
str) – The name of the metric.description (
str) – Human-readable description of the metric.unit (
str) – Unit of the metric values following the UCUM convention (https://unitsofmeasure.org/ucum.html).value_type (
Type[~ValueT]) – The type of values being recorded by the metric.enabled (
bool) – Whether to report the metric by default.
- Return type
-
abstract
create_valuerecorder(name, description, unit, value_type, enabled=True)[source]¶ Creates a
ValueRecordermetric with typevalue_type.- Parameters
name (
str) – The name of the metric.description (
str) – Human-readable description of the metric.unit (
str) – Unit of the metric values following the UCUM convention (https://unitsofmeasure.org/ucum.html).value_type (
Type[~ValueT]) – The type of values being recorded by the metric.enabled (
bool) – Whether to report the metric by default.
- Return type
-
abstract
register_sumobserver(callback, name, description, unit, value_type, label_keys=(), enabled=True)[source]¶ Registers an
SumObservermetric instrument.- Parameters
callback (
Callable[[Observer],None]) – Callback invoked each collection interval with the observer as argument.name (
str) – The name of the metric.description (
str) – Human-readable description of the metric.unit (
str) – Unit of the metric values following the UCUM convention (https://unitsofmeasure.org/ucum.html).value_type (
Type[~ValueT]) – The type of values being recorded by the metric.label_keys (
Sequence[str]) – The keys for the labels with dynamic values.enabled (
bool) – Whether to report the metric by default.
Returns: A new
SumObservermetric instrument.- Return type
-
abstract
register_updownsumobserver(callback, name, description, unit, value_type, label_keys=(), enabled=True)[source]¶ Registers an
UpDownSumObservermetric instrument.- Parameters
callback (
Callable[[Observer],None]) – Callback invoked each collection interval with the observer as argument.name (
str) – The name of the metric.description (
str) – Human-readable description of the metric.unit (
str) – Unit of the metric values following the UCUM convention (https://unitsofmeasure.org/ucum.html).value_type (
Type[~ValueT]) – The type of values being recorded by the metric.label_keys (
Sequence[str]) – The keys for the labels with dynamic values.enabled (
bool) – Whether to report the metric by default.
Returns: A new
UpDownSumObservermetric instrument.- Return type
-
abstract
register_valueobserver(callback, name, description, unit, value_type, label_keys=(), enabled=True)[source]¶ Registers an
ValueObservermetric instrument.- Parameters
callback (
Callable[[Observer],None]) – Callback invoked each collection interval with the observer as argument.name (
str) – The name of the metric.description (
str) – Human-readable description of the metric.unit (
str) – Unit of the metric values following the UCUM convention (https://unitsofmeasure.org/ucum.html).value_type (
Type[~ValueT]) – The type of values being recorded by the metric.label_keys (
Sequence[str]) – The keys for the labels with dynamic values.enabled (
bool) – Whether to report the metric by default.
Returns: A new
ValueObservermetric instrument.- Return type
-
abstract
-
class
opentelemetry.metrics.DefaultMeter[source]¶ Bases:
opentelemetry.metrics.MeterThe default Meter used when no Meter implementation is available.
-
record_batch(labels, record_tuples)[source]¶ Atomically records a batch of
Metricand value pairs.Allows the functionality of acting upon multiple metrics with a single API call. Implementations should find bound metric instruments that match the key-value pairs in the labels.
-
create_counter(name, description, unit, value_type, enabled=True)[source]¶ Creates a
Countermetric with typevalue_type.- Parameters
name (
str) – The name of the metric.description (
str) – Human-readable description of the metric.unit (
str) – Unit of the metric values following the UCUM convention (https://unitsofmeasure.org/ucum.html).value_type (
Type[~ValueT]) – The type of values being recorded by the metric.enabled (
bool) – Whether to report the metric by default.
- Return type
-
create_updowncounter(name, description, unit, value_type, enabled=True)[source]¶ Creates a
UpDownCountermetric with typevalue_type.- Parameters
name (
str) – The name of the metric.description (
str) – Human-readable description of the metric.unit (
str) – Unit of the metric values following the UCUM convention (https://unitsofmeasure.org/ucum.html).value_type (
Type[~ValueT]) – The type of values being recorded by the metric.enabled (
bool) – Whether to report the metric by default.
- Return type
-
create_valuerecorder(name, description, unit, value_type, enabled=True)[source]¶ Creates a
ValueRecordermetric with typevalue_type.- Parameters
name (
str) – The name of the metric.description (
str) – Human-readable description of the metric.unit (
str) – Unit of the metric values following the UCUM convention (https://unitsofmeasure.org/ucum.html).value_type (
Type[~ValueT]) – The type of values being recorded by the metric.enabled (
bool) – Whether to report the metric by default.
- Return type
-
register_sumobserver(callback, name, description, unit, value_type, label_keys=(), enabled=True)[source]¶ Registers an
SumObservermetric instrument.- Parameters
callback (
Callable[[Observer],None]) – Callback invoked each collection interval with the observer as argument.name (
str) – The name of the metric.description (
str) – Human-readable description of the metric.unit (
str) – Unit of the metric values following the UCUM convention (https://unitsofmeasure.org/ucum.html).value_type (
Type[~ValueT]) – The type of values being recorded by the metric.label_keys (
Sequence[str]) – The keys for the labels with dynamic values.enabled (
bool) – Whether to report the metric by default.
Returns: A new
SumObservermetric instrument.- Return type
-
register_updownsumobserver(callback, name, description, unit, value_type, label_keys=(), enabled=True)[source]¶ Registers an
UpDownSumObservermetric instrument.- Parameters
callback (
Callable[[Observer],None]) – Callback invoked each collection interval with the observer as argument.name (
str) – The name of the metric.description (
str) – Human-readable description of the metric.unit (
str) – Unit of the metric values following the UCUM convention (https://unitsofmeasure.org/ucum.html).value_type (
Type[~ValueT]) – The type of values being recorded by the metric.label_keys (
Sequence[str]) – The keys for the labels with dynamic values.enabled (
bool) – Whether to report the metric by default.
Returns: A new
UpDownSumObservermetric instrument.- Return type
-
register_valueobserver(callback, name, description, unit, value_type, label_keys=(), enabled=True)[source]¶ Registers an
ValueObservermetric instrument.- Parameters
callback (
Callable[[Observer],None]) – Callback invoked each collection interval with the observer as argument.name (
str) – The name of the metric.description (
str) – Human-readable description of the metric.unit (
str) – Unit of the metric values following the UCUM convention (https://unitsofmeasure.org/ucum.html).value_type (
Type[~ValueT]) – The type of values being recorded by the metric.label_keys (
Sequence[str]) – The keys for the labels with dynamic values.enabled (
bool) – Whether to report the metric by default.
Returns: A new
ValueObservermetric instrument.- Return type
-
-
opentelemetry.metrics.get_meter(instrumenting_module_name, instrumenting_library_version='', meter_provider=None)[source]¶ Returns a
Meterfor use by the given instrumentation library. This function is a convenience wrapper for opentelemetry.metrics.get_meter_provider().get_meterIf meter_provider is omitted the current configured one is used.
- Return type
-
opentelemetry.metrics.set_meter_provider(meter_provider)[source]¶ Sets the current global
MeterProviderobject.- Return type
None
-
opentelemetry.metrics.get_meter_provider()[source]¶ Gets the current global
MeterProviderobject.- Return type