opentelemetry.sdk.metrics.export — OpenTelemetry Python documentation (original) (raw)

class opentelemetry.sdk.metrics.export.AggregationTemporality(value)[source]

Bases: IntEnum

The temporality to use when aggregating data.

Can be one of the following values:

UNSPECIFIED = 0

DELTA = 1

CUMULATIVE = 2

class opentelemetry.sdk.metrics.export.Buckets(offset, bucket_counts)[source]

Bases: object

offset_: int_

bucket_counts_: Sequence[int]_

class opentelemetry.sdk.metrics.export.ConsoleMetricExporter(out=<_io.TextIOWrapper name='' mode='w' encoding='utf-8'>, formatter=<function ConsoleMetricExporter.>, preferred_temporality=None, preferred_aggregation=None)[source]

Bases: MetricExporter

Implementation of MetricExporter that prints metrics to the console.

This class can be used for diagnostic purposes. It prints the exported metrics to the console STDOUT.

export(metrics_data, timeout_millis=10000, **kwargs)[source]

Exports a batch of telemetry data.

Parameters:

metrics – The list of opentelemetry.sdk.metrics.export.Metric objects to be exported

Return type:

MetricExportResult

Returns:

The result of the export

shutdown(timeout_millis=30000, **kwargs)[source]

Shuts down the exporter.

Called when the SDK is shut down.

Return type:

None

force_flush(timeout_millis=10000)[source]

Ensure that export of any metrics currently received by the exporter are completed as soon as possible.

Return type:

bool

class opentelemetry.sdk.metrics.export.InMemoryMetricReader(preferred_temporality=None, preferred_aggregation=None)[source]

Bases: MetricReader

Implementation of MetricReader that returns its metrics from get_metrics_data().

This is useful for e.g. unit tests.

get_metrics_data()[source]

Reads and returns current metrics from the SDK

Return type:

Optional[opentelemetry.sdk.metrics.export.MetricsData]

shutdown(timeout_millis=30000, **kwargs)[source]

Shuts down the MetricReader. This method provides a way for the MetricReader to do any cleanup required. A metric reader can only be shutdown once, any subsequent calls are ignored and return failure status.

When a MetricReader is registered on aMeterProvider,shutdown() will invoke this automatically.

Return type:

None

class opentelemetry.sdk.metrics.export.MetricExporter(preferred_temporality=None, preferred_aggregation=None)[source]

Bases: ABC

Interface for exporting metrics.

Interface to be implemented by services that want to export metrics received in their own format.

Parameters:

abstract export(metrics_data, timeout_millis=10000, **kwargs)[source]

Exports a batch of telemetry data.

Parameters:

metrics – The list of opentelemetry.sdk.metrics.export.Metric objects to be exported

Return type:

MetricExportResult

Returns:

The result of the export

abstract force_flush(timeout_millis=10000)[source]

Ensure that export of any metrics currently received by the exporter are completed as soon as possible.

Return type:

bool

abstract shutdown(timeout_millis=30000, **kwargs)[source]

Shuts down the exporter.

Called when the SDK is shut down.

Return type:

None

class opentelemetry.sdk.metrics.export.MetricExportResult(value)[source]

Bases: Enum

Result of exporting a metric

Can be any of the following values:

SUCCESS = 0

FAILURE = 1

class opentelemetry.sdk.metrics.export.MetricReader(preferred_temporality=None, preferred_aggregation=None)[source]

Bases: ABC

Base class for all metric readers

Parameters:

abstract _receive_metrics(metrics_data, timeout_millis=10000, **kwargs)[source]

Called by MetricReader.collect when it receives a batch of metrics

Return type:

None

collect(timeout_millis=10000)[source]

Collects the metrics from the internal SDK state and invokes the _receive_metrics with the collection.

Parameters:

timeout_millis (float) – Amount of time in milliseconds before this function raises a timeout error.

Return type:

None

If any of the underlying collect methods called by this method fails by any reason (including timeout) an exception will be raised detailing the individual errors that caused this function to fail.

force_flush(timeout_millis=10000)[source]

Return type:

bool

abstract shutdown(timeout_millis=30000, **kwargs)[source]

Shuts down the MetricReader. This method provides a way for the MetricReader to do any cleanup required. A metric reader can only be shutdown once, any subsequent calls are ignored and return failure status.

When a MetricReader is registered on aMeterProvider,shutdown() will invoke this automatically.

Return type:

None

class opentelemetry.sdk.metrics.export.PeriodicExportingMetricReader(exporter, export_interval_millis=None, export_timeout_millis=None)[source]

Bases: MetricReader

PeriodicExportingMetricReader is an implementation of MetricReaderthat collects metrics based on a user-configurable time interval, and passes the metrics to the configured exporter. If the time interval is set to math.inf, the reader will not invoke periodic collection.

The configured exporter’s export() method will not be called concurrently.

shutdown(timeout_millis=30000, **kwargs)[source]

Shuts down the MetricReader. This method provides a way for the MetricReader to do any cleanup required. A metric reader can only be shutdown once, any subsequent calls are ignored and return failure status.

When a MetricReader is registered on aMeterProvider,shutdown() will invoke this automatically.

Return type:

None

force_flush(timeout_millis=10000)[source]

Return type:

bool

class opentelemetry.sdk.metrics.export.ExponentialHistogram(data_points, aggregation_temporality)[source]

Bases: object

Represents the type of a metric that is calculated by aggregating as an ExponentialHistogram of all reported measurements over a time interval.

data_points_: Sequence[ExponentialHistogramDataPoint]_

aggregation_temporality_: AggregationTemporality_

to_json(indent=4)[source]

Return type:

str

class opentelemetry.sdk.metrics.export.ExponentialHistogramDataPoint(attributes, start_time_unix_nano, time_unix_nano, count, sum, scale, zero_count, positive, negative, flags, min, max, exemplars=)[source]

Bases: object

Single data point in a timeseries whose boundaries are defined by an exponential function. This timeseries describes the time-varying scalar value of a metric.

attributes_: Optional[Mapping[str, Union[str, bool, int, float, Sequence[str], Sequence[bool], Sequence[int], Sequence[float]]]]_

start_time_unix_nano_: int_

time_unix_nano_: int_

count_: int_

sum_: Union[int, float]_

scale_: int_

zero_count_: int_

positive_: Buckets_

negative_: Buckets_

flags_: int_

min_: float_

max_: float_

exemplars_: Sequence[Exemplar]_

to_json(indent=4)[source]

Return type:

str

class opentelemetry.sdk.metrics.export.Gauge(data_points)[source]

Bases: object

Represents the type of a scalar metric that always exports the current value for every data point. It should be used for an unknown aggregation.

data_points_: Sequence[NumberDataPoint]_

to_json(indent=4)[source]

Return type:

str

class opentelemetry.sdk.metrics.export.Histogram(data_points, aggregation_temporality)[source]

Bases: object

Represents the type of a metric that is calculated by aggregating as a histogram of all reported measurements over a time interval.

data_points_: Sequence[HistogramDataPoint]_

aggregation_temporality_: AggregationTemporality_

to_json(indent=4)[source]

Return type:

str

class opentelemetry.sdk.metrics.export.HistogramDataPoint(attributes, start_time_unix_nano, time_unix_nano, count, sum, bucket_counts, explicit_bounds, min, max, exemplars=)[source]

Bases: object

Single data point in a timeseries that describes the time-varying scalar value of a metric.

attributes_: Optional[Mapping[str, Union[str, bool, int, float, Sequence[str], Sequence[bool], Sequence[int], Sequence[float]]]]_

start_time_unix_nano_: int_

time_unix_nano_: int_

count_: int_

sum_: Union[int, float]_

bucket_counts_: Sequence[int]_

explicit_bounds_: Sequence[float]_

min_: float_

max_: float_

exemplars_: Sequence[Exemplar]_

to_json(indent=4)[source]

Return type:

str

class opentelemetry.sdk.metrics.export.Metric(name, description, unit, data)[source]

Bases: object

Represents a metric point in the OpenTelemetry data model to be exported.

name_: str_

description_: Optional[str]_

unit_: Optional[str]_

data_: Union[Sum, Gauge, Histogram, ExponentialHistogram]_

to_json(indent=4)[source]

Return type:

str

class opentelemetry.sdk.metrics.export.MetricsData(resource_metrics)[source]

Bases: object

An array of ResourceMetrics

resource_metrics_: Sequence[ResourceMetrics]_

to_json(indent=4)[source]

Return type:

str

class opentelemetry.sdk.metrics.export.NumberDataPoint(attributes, start_time_unix_nano, time_unix_nano, value, exemplars=)[source]

Bases: object

Single data point in a timeseries that describes the time-varying scalar value of a metric.

attributes_: Optional[Mapping[str, Union[str, bool, int, float, Sequence[str], Sequence[bool], Sequence[int], Sequence[float]]]]_

start_time_unix_nano_: int_

time_unix_nano_: int_

value_: Union[int, float]_

exemplars_: Sequence[Exemplar]_

to_json(indent=4)[source]

Return type:

str

class opentelemetry.sdk.metrics.export.ResourceMetrics(resource, scope_metrics, schema_url)[source]

Bases: object

A collection of ScopeMetrics from a Resource

resource_: Resource_

scope_metrics_: Sequence[ScopeMetrics]_

schema_url_: str_

to_json(indent=4)[source]

Return type:

str

class opentelemetry.sdk.metrics.export.ScopeMetrics(scope, metrics, schema_url)[source]

Bases: object

A collection of Metrics produced by a scope

scope_: InstrumentationScope_

metrics_: Sequence[Metric]_

schema_url_: str_

to_json(indent=4)[source]

Return type:

str

class opentelemetry.sdk.metrics.export.Sum(data_points, aggregation_temporality, is_monotonic)[source]

Bases: object

Represents the type of a scalar metric that is calculated as a sum of all reported measurements over a time interval.

data_points_: Sequence[NumberDataPoint]_

aggregation_temporality_: AggregationTemporality_

is_monotonic_: bool_

to_json(indent=4)[source]

Return type:

str