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 | |
Options for apply_defaults. |
| Function | apply |
Configure OTel metrics and tracing with AWS Lambda defaults. |
| Function | apply |
Configure only OTel tracing (no metrics) on the Lambda worker config. |
| Function | build |
Build a temporalio.runtime.TelemetryConfig for OTel metrics. |
| Variable | logger |
Undocumented |
| Function | _resolve |
Undocumented |
| Function | _resolve |
Undocumented |
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:LambdaWorkerConfig | The LambdaWorkerConfig to configure. |
options:OtelOptions | None | Optional overrides for service name, endpoint, etc. |
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:LambdaWorkerConfig | The LambdaWorkerConfig to configure. |
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:str | OTLP collector endpoint. Defaults to http://localhost:4317. |
servicestr | OTel service name. Used as a global tag. |
metrictimedelta | None | How often metrics are exported. |
| Returns | |
TelemetryConfig | A TelemetryConfig ready to pass to
temporalio.runtime.Runtime. |