class ReplaySafeMeterProvider(MeterProvider): (source)
Constructor: ReplaySafeMeterProvider(meter_provider)
A meter provider that is safe for use during workflow replay.
Warning
This class is experimental and may change in future versions. Use with caution in production environments.
This meter provider wraps an OpenTelemetry MeterProvider and drops synchronous instrument recordings (counter add(), up-down counter add(), histogram record(), and gauge set()) made from workflow code while the workflow is replaying history events. Without this, libraries that record metrics from workflow code (e.g. google-adk) re-record every measurement on each replay, inflating counts.
Recordings are therefore first-execution-only, matching
temporalio.workflow.metric_meter: a workflow task retry
re-executes live and can record again. Queries and update validators are
live, at-most-once-per-request operations even when they execute while the
workflow is replaying, so their recordings are kept. Observable
(asynchronous) instruments pass through untouched since their callbacks
run on the metric reader's collect thread, never inside workflow code.
Recordings outside workflows are unaffected.
Install this as the process-global meter provider before any library (e.g. google-adk) creates instruments:
opentelemetry.metrics.set_meter_provider(
ReplaySafeMeterProvider(my_meter_provider)
)
OpenTelemetry proxy meters late-bind, so calling set_meter_provider after such libraries are imported still routes their instruments through this wrapper. However, set_meter_provider only takes effect once per process, so this wrapper must be the one and only global meter provider ever set.
| Method | __getattr__ |
Delegate all other attributes (e.g. shutdown, force_flush) to the underlying meter provider. |
| Method | __init__ |
Initialize the replay-safe meter provider. |
| Method | get |
Get a replay-safe meter from the underlying provider. |
| Instance Variable | _meter |
Undocumented |
Initialize the replay-safe meter provider.
| Parameters | |
meterMeterProvider | The underlying OpenTelemetry MeterProvider to wrap. |
str, version: str | None = None, schema_url: str | None = None, attributes: Attributes | None = None) -> Meter:
(source)
¶
Get a replay-safe meter from the underlying provider.
| Parameters | |
name:str | The name of the instrumenting module. |
version:str | None | The version string of the instrumenting library. |
schemastr | None | The schema URL for the meter. |
attributes:Attributes | None | Additional attributes for the meter. |
| Returns | |
Meter | A replay-safe meter instance. |