class documentation

class ReplaySafeMeterProvider(MeterProvider): (source)

Constructor: ReplaySafeMeterProvider(meter_provider)

View In Hierarchy

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_meter Get a replay-safe meter from the underlying provider.
Instance Variable _meter_provider Undocumented
def __getattr__(self, name: str) -> Any: (source)

Delegate all other attributes (e.g. shutdown, force_flush) to the underlying meter provider.

def __init__(self, meter_provider: MeterProvider): (source)

Initialize the replay-safe meter provider.

Parameters
meter_provider:MeterProviderThe underlying OpenTelemetry MeterProvider to wrap.
def get_meter(self, name: 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:strThe name of the instrumenting module.
version:str | NoneThe version string of the instrumenting library.
schema_url:str | NoneThe schema URL for the meter.
attributes:Attributes | NoneAdditional attributes for the meter.
Returns
MeterA replay-safe meter instance.
_meter_provider = (source)

Undocumented