opentelemetry.sdk.metrics package

Submodules

opentelemetry.sdk.metrics.get_labels_as_key(labels)[source]

Gets a list of labels that can be used as a key in a dictionary.

Return type

Tuple[Tuple[str, str]]

class opentelemetry.sdk.metrics.BaseBoundInstrument(value_type, enabled, aggregator)[source]

Bases: object

Class containing common behavior for all bound metric instruments.

Bound metric instruments are responsible for operating on data for metric instruments for a specific set of labels.

Parameters
  • value_type (Type[~ValueT]) – The type of values for this bound instrument (int, float).

  • enabled (bool) – True if the originating instrument is enabled.

  • aggregator (Aggregator) – The aggregator for this bound metric instrument. Will handle aggregation upon updates and checkpointing of values for exporting.

update(value)[source]
release()[source]
decrease_ref_count()[source]
increase_ref_count()[source]
ref_count()[source]
class opentelemetry.sdk.metrics.BoundCounter(value_type, enabled, aggregator)[source]

Bases: opentelemetry.metrics.BoundCounter, opentelemetry.sdk.metrics.BaseBoundInstrument

add(value)[source]

See opentelemetry.metrics.BoundCounter.add.

Return type

None

class opentelemetry.sdk.metrics.BoundMeasure(value_type, enabled, aggregator)[source]

Bases: opentelemetry.metrics.BoundMeasure, opentelemetry.sdk.metrics.BaseBoundInstrument

record(value)[source]

See opentelemetry.metrics.BoundMeasure.record.

Return type

None

class opentelemetry.sdk.metrics.Metric(name, description, unit, value_type, meter, label_keys=(), enabled=True)[source]

Bases: opentelemetry.metrics.Metric

Base class for all metric types.

Also known as metric instrument. This is the class that is used to represent a metric that is to be continuously recorded and tracked. Each metric has a set of bound metrics that are created from the metric. See BaseBoundInstrument for information on bound metric instruments.

BOUND_INSTR_TYPE

alias of BaseBoundInstrument

bind(labels)[source]

See opentelemetry.metrics.Metric.bind.

Return type

BaseBoundInstrument

UPDATE_FUNCTION(y)
class opentelemetry.sdk.metrics.Counter(name, description, unit, value_type, meter, label_keys=(), enabled=True)[source]

Bases: opentelemetry.sdk.metrics.Metric, opentelemetry.metrics.Counter

See opentelemetry.metrics.Counter.

BOUND_INSTR_TYPE

alias of BoundCounter

add(value, labels)[source]

See opentelemetry.metrics.Counter.add.

Return type

None

UPDATE_FUNCTION(value, labels)

See opentelemetry.metrics.Counter.add.

Return type

None

class opentelemetry.sdk.metrics.Measure(name, description, unit, value_type, meter, label_keys=(), enabled=True)[source]

Bases: opentelemetry.sdk.metrics.Metric, opentelemetry.metrics.Measure

See opentelemetry.metrics.Measure.

BOUND_INSTR_TYPE

alias of BoundMeasure

record(value, labels)[source]

See opentelemetry.metrics.Measure.record.

Return type

None

UPDATE_FUNCTION(value, labels)

See opentelemetry.metrics.Measure.record.

Return type

None

class opentelemetry.sdk.metrics.Observer(callback, name, description, unit, value_type, meter, label_keys=(), enabled=True)[source]

Bases: opentelemetry.metrics.Observer

See opentelemetry.metrics.Observer.

observe(value, labels)[source]

Captures value to the observer.

Parameters
  • value (~ValueT) – The value to capture to this observer metric.

  • labels (Dict[str, str]) – Labels associated to value.

Return type

None

run()[source]
Return type

bool

class opentelemetry.sdk.metrics.Record(metric, labels, aggregator)[source]

Bases: object

Container class used for processing in the Batcher

class opentelemetry.sdk.metrics.Meter(instrumentation_info, stateful, resource=<opentelemetry.sdk.resources.Resource object>)[source]

Bases: opentelemetry.metrics.Meter

See opentelemetry.metrics.Meter.

Parameters
collect()[source]

Collects all the metrics created with this Meter for export.

Utilizes the batcher to create checkpoints of the current values in each aggregator belonging to the metrics that were created with this meter instance.

Return type

None

record_batch(labels, record_tuples)[source]

See opentelemetry.metrics.Meter.record_batch.

Return type

None

create_metric(name, description, unit, value_type, metric_type, label_keys=(), enabled=True)[source]

See opentelemetry.metrics.Meter.create_metric.

Return type

~MetricT

register_observer(callback, name, description, unit, value_type, label_keys=(), enabled=True)[source]

Registers an Observer metric 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 Observer metric instrument.

Return type

Observer

unregister_observer(observer)[source]

Unregisters an Observer metric instrument.

Parameters

observer (Observer) – The observer to unregister.

Return type

None

class opentelemetry.sdk.metrics.MeterProvider(resource=<opentelemetry.sdk.resources.Resource object>)[source]

Bases: opentelemetry.metrics.MeterProvider

get_meter(instrumenting_module_name, stateful=True, instrumenting_library_version='')[source]

Returns a Meter for use by the given instrumentation library.

This function may return different Meter types (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.ext.http_requests".

  • stateful – True/False to indicate whether the meter will be stateful. True indicates the meter computes checkpoints from over the process lifetime. False indicates the meter computes checkpoints which describe the updates of a single collection period (deltas).

  • instrumenting_library_version (str) – Optional. The version string of the instrumenting library. Usually this should be the same as pkg_resources.get_distribution(instrumenting_library_name).version.

Return type

Meter