class MetricsExporter: (source)
Constructor: MetricsExporter(buffer, meter_provider, meter_name, meter_version, ...)
Exports metrics recorded via a temporalio.runtime.MetricBuffer
to an OpenTelemetry opentelemetry.metrics.MeterProvider.
Warning
This class is experimental and may change in future versions. Use with caution in production environments.
This must be started (via run or async with) after the
temporalio.runtime.Runtime referencing buffer has been
constructed, and it must be kept running for as long as metrics should be
exported. It drains the buffer on a fixed interval; per
temporalio.runtime.MetricBuffer, updates are dropped (with an
error logged by Core) if the buffer is not drained regularly.
Example:
from datetime import timedelta
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import (
ConsoleMetricExporter,
PeriodicExportingMetricReader,
)
from temporalio.client import Client
from temporalio.contrib.opentelemetry import MetricsExporter
from temporalio.runtime import MetricBuffer, Runtime, TelemetryConfig
buffer = MetricBuffer(10_000)
runtime = Runtime(telemetry=TelemetryConfig(metrics=buffer))
meter_provider = MeterProvider(
metric_readers=[
PeriodicExportingMetricReader(
ConsoleMetricExporter(), export_interval_millis=5000
)
]
)
async with MetricsExporter(buffer, meter_provider):
client = await Client.connect("localhost:7233", runtime=runtime)
...
| Async Method | __aenter__ |
Start run as a background task. |
| Async Method | __aexit__ |
Call shutdown and await the background task. |
| Method | __init__ |
Create an exporter that drains buffer into meter_provider. |
| Async Method | run |
Drain and export on poll_interval until shutdown is called. |
| Async Method | shutdown |
Stop run (including a final drain) and wait for it to finish. |
| Method | _apply |
Undocumented |
| Method | _drain |
Undocumented |
| Method | _get |
Undocumented |
| Method | _get |
Undocumented |
| Method | _handle |
Undocumented |
| Instance Variable | _attributes |
Undocumented |
| Instance Variable | _buffer |
Undocumented |
| Instance Variable | _instruments |
Undocumented |
| Instance Variable | _meter |
Undocumented |
| Instance Variable | _on |
Undocumented |
| Instance Variable | _poll |
Undocumented |
| Instance Variable | _run |
Undocumented |
| Instance Variable | _run |
Undocumented |
| Instance Variable | _shutdown |
Undocumented |
| Instance Variable | _started |
Undocumented |
temporalio.runtime.MetricBuffer, meter_provider: opentelemetry.metrics.MeterProvider | None = None, *, meter_name: str = 'temporalio', meter_version: str | None = None, poll_interval: timedelta = timedelta(Callable[ [ Exception], None] | None = None):
(source)
¶
Create an exporter that drains buffer into meter_provider.
| Parameters | |
buffer:temporalio.runtime.MetricBuffer | The buffer to drain. Must already be (or about to be) set
as the metrics of a
temporalio.runtime.TelemetryConfig on a
constructed temporalio.runtime.Runtime. |
meteropentelemetry.metrics.MeterProvider | None | The provider to create instruments on. Defaults to
opentelemetry.metrics.get_meter_provider (the
global provider) if not given. |
meterstr | Name passed to get_meter on the provider. |
meterstr | None | Version passed to get_meter on the provider. |
polltimedelta | How often to drain the buffer. Must be reasonably
frequent -- see the warning on
temporalio.runtime.MetricBuffer. |
onCallable[ | Optional callback invoked (in addition to logging) when draining the buffer or applying an individual update fails. If this callback itself raises, that is logged and ignored. |
Drain and export on poll_interval until shutdown is called.
| Raises | |
RuntimeError | If buffer was never attached to a constructed
temporalio.runtime.Runtime, or if this is called
while already running. |
temporalio.common.MetricAttributes) -> Mapping[ str, opentelemetry.util.types.AttributeValue]:
(source)
¶
Undocumented
temporalio.runtime.BufferedMetric) -> _Instrument:
(source)
¶
Undocumented