module documentation

OpenTelemetry helpers for Temporal workers running inside AWS Lambda.

Use apply_defaults inside a run_worker configure callback for a batteries-included setup that creates an OTel collector exporter and tracing plugin, suitable for use with the AWS Distro for OpenTelemetry (ADOT) Lambda layer.

Use apply_tracing or build_metrics_telemetry_config individually if you only need one.

Class OtelOptions Options for apply_defaults.
Function apply_defaults Configure OTel metrics and tracing with AWS Lambda defaults.
Function apply_tracing Configure only OTel tracing (no metrics) on the Lambda worker config.
Function build_metrics_telemetry_config Build a temporalio.runtime.TelemetryConfig for OTel metrics.
Variable logger Undocumented
Function _resolve_endpoint Undocumented
Function _resolve_service_name Undocumented
def apply_defaults(config: LambdaWorkerConfig, options: OtelOptions | None = None): (source)

Configure OTel metrics and tracing with AWS Lambda defaults.

Sets up Core SDK metrics export via a temporalio.runtime.Runtime with an temporalio.runtime.OpenTelemetryConfig pointing at the OTLP collector, and adds the temporalio.contrib.opentelemetry.OpenTelemetryPlugin for distributed tracing with workflow sandbox passthrough.

Creates a replay-safe TracerProvider (with X-Ray ID generator and OTLP gRPC exporter if available) and sets it as the global OpenTelemetry tracer provider. The temporalio.contrib.opentelemetry.OpenTelemetryPlugin uses the global provider, so it must be set before the worker starts.

The collector endpoint defaults to http://localhost:4317, which is the endpoint expected by the ADOT collector Lambda layer.

Registers a per-invocation ForceFlush shutdown hook for the global TracerProvider so pending traces are exported before each Lambda invocation completes.

Metrics are exported on the metric_periodicity interval by the runtime's internal thread. There is no explicit flush API for these metrics; set metric_periodicity short enough to ensure at least one export per invocation.

Parameters
config:LambdaWorkerConfigThe LambdaWorkerConfig to configure.
options:OtelOptions | NoneOptional overrides for service name, endpoint, etc.
def apply_tracing(config: LambdaWorkerConfig): (source)

Configure only OTel tracing (no metrics) on the Lambda worker config.

Adds an temporalio.contrib.opentelemetry.OpenTelemetryPlugin to config.worker_config["plugins"]. The plugin uses the global TracerProvider set via opentelemetry.trace.set_tracer_provider. Ensure your provider is set globally before the worker starts.

Also registers a ForceFlush shutdown hook that flushes the global TracerProvider (if it supports force_flush).

Parameters
config:LambdaWorkerConfigThe LambdaWorkerConfig to configure.
def build_metrics_telemetry_config(*, endpoint: str = '', service_name: str = '', metric_periodicity: timedelta | None = None) -> TelemetryConfig: (source)

Build a temporalio.runtime.TelemetryConfig for OTel metrics.

Returns a TelemetryConfig with temporalio.runtime.OpenTelemetryConfig metrics pointed at the given OTLP collector endpoint. Use this when you need to compose metrics config with other telemetry settings (e.g. custom logging) into your own temporalio.runtime.Runtime.

Core SDK metrics are exported on the metric_periodicity interval by the runtime's internal thread. There is no explicit flush API; set metric_periodicity short enough to ensure at least one export per Lambda invocation.

Example:

telemetry = build_metrics_telemetry_config(
    endpoint="http://localhost:4317",
    service_name="my-service",
)
# Customize further:
telemetry_config = dataclasses.replace(
    telemetry, logging=my_logging_config
)
runtime = Runtime(telemetry=telemetry_config)
config.client_connect_config["runtime"] = runtime
Parameters
endpoint:strOTLP collector endpoint. Defaults to http://localhost:4317.
service_name:strOTel service name. Used as a global tag.
metric_periodicity:timedelta | NoneHow often metrics are exported.
Returns
TelemetryConfigA TelemetryConfig ready to pass to temporalio.runtime.Runtime.

Undocumented

def _resolve_endpoint(options: OtelOptions) -> str: (source)

Undocumented

def _resolve_service_name(options: OtelOptions) -> str: (source)

Undocumented