Skip to content

Metrics

metrics

Pluggable metrics hooks for the Durable Workflow client and worker.

Pass any :class:MetricsRecorder implementation as metrics= on :class:~durable_workflow.Client or :class:~durable_workflow.Worker. The SDK ships three recorders out of the box: :class:NoopMetrics (the default), :class:InMemoryMetrics for tests and small exporter loops, and :class:PrometheusMetrics which forwards to the optional prometheus-client package. Custom recorders implement two methods — :meth:MetricsRecorder.increment and :meth:MetricsRecorder.record — and receive stable metric names and tag dicts defined as module-level constants in this file.

MetricsRecorder

Bases: Protocol

Pluggable counter and histogram recorder used by the client and worker.

increment

increment(name, value=1.0, tags=None)

Increment a counter metric.

record

record(name, value, tags=None)

Record a histogram/sample metric.

NoopMetrics

Default metrics recorder that intentionally drops all observations.

increment

increment(name, value=1.0, tags=None)

Implements :meth:MetricsRecorder.increment as a no-op.

record

record(name, value, tags=None)

Implements :meth:MetricsRecorder.record as a no-op.

InMemoryMetrics dataclass

InMemoryMetrics(counters=dict(), histograms=dict())

Simple recorder useful for tests and custom exporter loops.

increment

increment(name, value=1.0, tags=None)

Accumulate into an in-memory counter keyed by name + sorted tags.

record

record(name, value, tags=None)

Append an observation to an in-memory histogram keyed by name + sorted tags.

counter_value

counter_value(name, tags=None)

Return the current value of a counter, or 0.0 if it has never been incremented.

observations

observations(name, tags=None)

Return a copy of the histogram observations recorded under name + tags.

PrometheusMetrics

PrometheusMetrics(*, registry=None)

Metrics recorder backed by the optional prometheus-client package.

increment

increment(name, value=1.0, tags=None)

Forward to a prometheus_client.Counter, creating one on first use.

record

record(name, value, tags=None)

Forward to a prometheus_client.Histogram, creating one on first use.