# opentelemetry.sdk.metrics.export

class opentelemetry.sdk.metrics.export.AggregationTemporality(*values)

  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)

  Bases: `object`

  offset: `int`
  bucket_counts: `Sequence`[`int`]

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

  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)

    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

  force_flush(timeout_millis=10000)

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

    Return type:

      `bool`

  shutdown(timeout_millis=30000, **kwargs)

    Shuts down the exporter.

    Called when the SDK is shut down.

    Return type:

      `None`

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

  Bases: `MetricReader`

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

  This is useful for e.g. unit tests.

  get_metrics_data()

    Reads and returns current metrics from the SDK

    Return type:

      `MetricsData` | `None`

  shutdown(timeout_millis=30000, **kwargs)

    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 a `MeterProvider`, `shutdown()` will invoke this automatically.

    Return type:

      `None`

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

  Bases: `ABC`

  Interface for exporting metrics.

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

  Parameters:

    - preferred_temporality (`dict`[`type`, `AggregationTemporality`] | `None`) – Used by `opentelemetry.sdk.metrics.export.PeriodicExportingMetricReader` to configure exporter level preferred temporality. See `opentelemetry.sdk.metrics.export.MetricReader` for more details on what preferred temporality is.

    - preferred_aggregation (`dict`[`type`, `Aggregation`] | `None`) – Used by `opentelemetry.sdk.metrics.export.PeriodicExportingMetricReader` to configure exporter level preferred aggregation. See `opentelemetry.sdk.metrics.export.MetricReader` for more details on what preferred aggregation is.

  abstractmethod export(metrics_data, timeout_millis=10000, **kwargs)

    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

  abstractmethod force_flush(timeout_millis=10000)

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

    Return type:

      `bool`

  abstractmethod shutdown(timeout_millis=30000, **kwargs)

    Shuts down the exporter.

    Called when the SDK is shut down.

    Return type:

      `None`

class opentelemetry.sdk.metrics.export.MetricExportResult(*values)

  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)

  Bases: `ABC`

  Base class for all metric readers

  Parameters:

    - preferred_temporality (`dict`[`type`, `AggregationTemporality`] | `None`) – A mapping between instrument classes and aggregation temporality. By default uses CUMULATIVE for all instrument classes. This mapping will be used to define the default aggregation temporality of every instrument class. If the user wants to make a change in the default aggregation temporality of an instrument class, it is enough to pass here a dictionary whose keys are the instrument classes and the values are the corresponding desired aggregation temporalities of the classes that the user wants to change, not all of them. The classes not included in the passed dictionary will retain their association to their default aggregation temporalities.

    - preferred_aggregation (`dict`[`type`, `Aggregation`] | `None`) – A mapping between instrument classes and aggregation instances. By default maps all instrument classes to an instance of `DefaultAggregation`. This mapping will be used to define the default aggregation of every instrument class. If the user wants to make a change in the default aggregation of an instrument class, it is enough to pass here a dictionary whose keys are the instrument classes and the values are the corresponding desired aggregation for the instrument classes that the user wants to change, not necessarily all of them. The classes not included in the passed dictionary will retain their association to their default aggregations. The aggregation defined here will be overridden by an aggregation defined by a view that is not `DefaultAggregation`.

  abstractmethod _receive_metrics(metrics_data, timeout_millis=10000, **kwargs)

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

    Return type:

      `None`

  collect(timeout_millis=10000)

    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)
    Return type:

      `bool`

  abstractmethod shutdown(timeout_millis=30000, **kwargs)

    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 a `MeterProvider`, `shutdown()` will invoke this automatically.

    Return type:

      `None`

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

  Bases: `MetricReader`

  `PeriodicExportingMetricReader` is an implementation of `MetricReader` that 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.

  force_flush(timeout_millis=10000)
    Return type:

      `bool`

  shutdown(timeout_millis=30000, **kwargs)

    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 a `MeterProvider`, `shutdown()` will invoke this automatically.

    Return type:

      `None`

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

  Bases: `object`

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

  to_json(indent=4)
    Return type:

      `str`

  data_points: `Sequence`[`ExponentialHistogramDataPoint`]
  aggregation_temporality: `AggregationTemporality`

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=<factory>)

  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.

  to_json(indent=4)
    Return type:

      `str`

  attributes: `Mapping`[`str`, `str` | `bool` | `int` | `float` | `Sequence`[`str`] | `Sequence`[`bool`] | `Sequence`[`int`] | `Sequence`[`float`]] | `None`
  start_time_unix_nano: `int`
  time_unix_nano: `int`
  count: `int`
  sum: `int` | `float`
  scale: `int`
  zero_count: `int`
  positive: `Buckets`
  negative: `Buckets`
  flags: `int`
  min: `float`
  max: `float`
  exemplars: `Sequence`[`Exemplar`]

class opentelemetry.sdk.metrics.export.Gauge(data_points)

  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.

  to_json(indent=4)
    Return type:

      `str`

  data_points: `Sequence`[`NumberDataPoint`]

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

  Bases: `object`

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

  to_json(indent=4)
    Return type:

      `str`

  data_points: `Sequence`[`HistogramDataPoint`]
  aggregation_temporality: `AggregationTemporality`

class opentelemetry.sdk.metrics.export.HistogramDataPoint(attributes, start_time_unix_nano, time_unix_nano, count, sum, bucket_counts, explicit_bounds, min, max, exemplars=<factory>)

  Bases: `object`

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

  to_json(indent=4)
    Return type:

      `str`

  attributes: `Mapping`[`str`, `str` | `bool` | `int` | `float` | `Sequence`[`str`] | `Sequence`[`bool`] | `Sequence`[`int`] | `Sequence`[`float`]] | `None`
  start_time_unix_nano: `int`
  time_unix_nano: `int`
  count: `int`
  sum: `int` | `float`
  bucket_counts: `Sequence`[`int`]
  explicit_bounds: `Sequence`[`float`]
  min: `float`
  max: `float`
  exemplars: `Sequence`[`Exemplar`]

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

  Bases: `object`

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

  to_json(indent=4)
    Return type:

      `str`

  name: `str`
  description: `str` | `None`
  unit: `str` | `None`
  data: `Sum` | `Gauge` | `Histogram` | `ExponentialHistogram`

class opentelemetry.sdk.metrics.export.MetricsData(resource_metrics)

  Bases: `object`

  An array of ResourceMetrics

  to_json(indent=4)
    Return type:

      `str`

  resource_metrics: `Sequence`[`ResourceMetrics`]

class opentelemetry.sdk.metrics.export.NumberDataPoint(attributes, start_time_unix_nano, time_unix_nano, value, exemplars=<factory>)

  Bases: `object`

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

  to_json(indent=4)
    Return type:

      `str`

  attributes: `Mapping`[`str`, `str` | `bool` | `int` | `float` | `Sequence`[`str`] | `Sequence`[`bool`] | `Sequence`[`int`] | `Sequence`[`float`]] | `None`
  start_time_unix_nano: `int`
  time_unix_nano: `int`
  value: `int` | `float`
  exemplars: `Sequence`[`Exemplar`]

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

  Bases: `object`

  A collection of ScopeMetrics from a Resource

  to_json(indent=4)
    Return type:

      `str`

  resource: `Resource`
  scope_metrics: `Sequence`[`ScopeMetrics`]
  schema_url: `str`

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

  Bases: `object`

  A collection of Metrics produced by a scope

  to_json(indent=4)
    Return type:

      `str`

  scope: `InstrumentationScope`
  metrics: `Sequence`[`Metric`]
  schema_url: `str`

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

  Bases: `object`

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

  to_json(indent=4)
    Return type:

      `str`

  data_points: `Sequence`[`NumberDataPoint`]
  aggregation_temporality: `AggregationTemporality`
  is_monotonic: `bool`