class documentation

OpenTelemetry plugin for Temporal workers running on Google Cloud Run.

The default configuration sends Temporal Core metrics and Python traces over OTLP gRPC to a collector on localhost:4317. The collector is responsible for Google Cloud resource detection, authentication, and export.

The plugin creates and installs a replay-safe global tracer provider unless tracer_provider is supplied. It also creates a Temporal runtime for Core metrics unless runtime is supplied. Call shutdown after every worker using the plugin has stopped.

Warning

This class is experimental and may change in future versions. Use with caution in production environments.

Method __init__ Initialize the Google Cloud OpenTelemetry plugin.
Async Method connect_service_client Install the metrics runtime before connecting the service client.
Method force_flush Export buffered Python traces without shutting down the provider.
Async Method run_worker Run a worker and optionally force-flush traces after it stops.
Method shutdown Flush traces and shut down a provider created by the plugin.
Property endpoint Resolved OTLP collector endpoint.
Property runtime Temporal runtime used for Core metrics.
Property service_name Resolved OpenTelemetry service name.
Property tracer_provider Replay-safe tracer provider used by the plugin.
Instance Variable _endpoint Undocumented
Instance Variable _flush_on_worker_stop Undocumented
Instance Variable _flush_timeout Undocumented
Instance Variable _owns_tracer_provider Undocumented
Instance Variable _runtime Undocumented
Instance Variable _service_name Undocumented
Instance Variable _shutdown Undocumented
Instance Variable _shutdown_lock Undocumented
Instance Variable _shutdown_succeeded Undocumented
Instance Variable _tracer_provider Undocumented

Inherited from SimplePlugin (via OpenTelemetryPlugin):

Method configure_client See base class.
Method configure_replayer See base class.
Method configure_worker See base class.
Method name See base class.
Async Method run_replayer See base class.
Instance Variable activities Undocumented
Instance Variable data_converter Undocumented
Instance Variable interceptors Undocumented
Instance Variable nexus_service_handlers Undocumented
Instance Variable run_context Undocumented
Instance Variable workflow_failure_exception_types Undocumented
Instance Variable workflow_runner Undocumented
Instance Variable workflows Undocumented
Instance Variable _name Undocumented
def __init__(self, *, endpoint: str | None = None, service_name: str | None = None, metric_periodicity: timedelta | None = None, flush_timeout: timedelta = DEFAULT_FLUSH_TIMEOUT, flush_on_worker_stop: bool = False, tracer_provider: TracerProvider | None = None, runtime: Runtime | None = None, add_temporal_spans: bool = False): (source)

Initialize the Google Cloud OpenTelemetry plugin.

Parameters
endpoint:str | NoneOTLP gRPC endpoint. Falls back to OTEL_EXPORTER_OTLP_ENDPOINT, then http://localhost:4317.
service_name:str | NoneOpenTelemetry service name. Falls back to OTEL_SERVICE_NAME, CLOUD_RUN_WORKER_POOL, K_SERVICE, then temporal-worker.
metric_periodicity:timedelta | NoneHow often Temporal Core metrics are exported. Defaults to 60 seconds. Cannot be used with runtime.
flush_timeout:timedeltaDefault tracing force-flush timeout.
flush_on_worker_stop:boolWhether to force-flush traces after each worker stops. Disabled by default because one plugin can be used by multiple workers.
tracer_provider:TracerProvider | NoneApplication-owned replay-safe tracer provider. It must have been created with temporalio.contrib.opentelemetry.create_tracer_provider. When supplied, the plugin does not create an exporter or shut down the provider.
runtime:Runtime | NoneApplication-owned Temporal runtime. When supplied, the plugin does not create or modify Core metrics configuration. Use build_metrics_telemetry_config to build a composable telemetry configuration for a custom runtime.
add_temporal_spans:boolWhether the underlying Temporal OpenTelemetry plugin should add Temporal-specific operation spans.
async def connect_service_client(self, config: ConnectConfig, next: Callable[[ConnectConfig], Awaitable[ServiceClient]]) -> ServiceClient: (source)

Install the metrics runtime before connecting the service client.

def force_flush(self, timeout: timedelta | None = None) -> bool: (source)

Export buffered Python traces without shutting down the provider.

Temporal Core metrics are exported periodically and the Python runtime currently has no explicit metrics-flush API.

Parameters
timeout:timedelta | NoneMaximum time to wait. Defaults to flush_timeout from the constructor.
Returns
boolTrue when the tracer provider reports a successful flush.
async def run_worker(self, worker: Worker, next: Callable[[Worker], Awaitable[None]]): (source)

Run a worker and optionally force-flush traces after it stops.

def shutdown(self, timeout: timedelta | None = None) -> bool: (source)

Flush traces and shut down a provider created by the plugin.

Application-owned tracer providers are force-flushed but are not shut down. This method is idempotent. Stop every worker using the plugin before calling it.

Parameters
timeout:timedelta | NoneMaximum time allowed for the tracing force-flush. Provider shutdown happens after that flush.
Returns
boolTrue when the tracing force-flush succeeded.

Resolved OTLP collector endpoint.

runtime: Runtime = (source)

Temporal runtime used for Core metrics.

service_name: str = (source)

Resolved OpenTelemetry service name.

tracer_provider: ReplaySafeTracerProvider = (source)

Replay-safe tracer provider used by the plugin.

_endpoint = (source)

Undocumented

_flush_on_worker_stop = (source)

Undocumented

_flush_timeout = (source)

Undocumented

_owns_tracer_provider = (source)

Undocumented

_runtime = (source)

Undocumented

_service_name = (source)

Undocumented

_shutdown: bool = (source)

Undocumented

_shutdown_lock = (source)

Undocumented

_shutdown_succeeded = (source)

Undocumented

_tracer_provider = (source)

Undocumented