module documentation

Provider-neutral OpenTelemetry helpers shared by serverless integrations.

This is a private module. It is intentionally not re-exported from temporalio.contrib.opentelemetry so that importing that package gains no new imports. The OTLP gRPC span exporter is imported lazily inside build_otlp_span_processor, so importing this module does not require the opentelemetry-exporter-otlp-proto-grpc dependency.

The AWS Lambda and GCP Cloud Run integrations layer their provider-specific policy (ID generators, default service names, environment fallbacks) on top of these helpers. Empty environment/argument values are skipped with a plain truthiness check and are not stripped of whitespace, matching the pre-existing AWS Lambda resolution behavior.

Function build_metrics_telemetry_config Build Core telemetry configuration for OTLP metrics export.
Function build_otlp_span_processor Build a batch span processor backed by the OTLP gRPC exporter.
Function resolve_endpoint Resolve the OTLP collector endpoint.
Function resolve_service_name Resolve the OpenTelemetry service name.
def build_metrics_telemetry_config(*, endpoint: str, service_name: str, metric_periodicity: timedelta | None) -> TelemetryConfig: (source)

Build Core telemetry configuration for OTLP metrics export.

Parameters
endpoint:strOTLP collector endpoint. Falls back to DEFAULT_OTLP_ENDPOINT when empty.
service_name:strService name added as the service_name global tag. When empty, no global tag is added.
metric_periodicity:timedelta | NoneMetric export interval, passed through unchanged.
Returns
TelemetryConfigA temporalio.runtime.TelemetryConfig with metrics pointed at the collector.
def build_otlp_span_processor(endpoint: str, *, insecure: bool = True) -> BatchSpanProcessor: (source)

Build a batch span processor backed by the OTLP gRPC exporter.

The exporter is imported lazily so that importing this module does not require opentelemetry-exporter-otlp-proto-grpc.

Parameters
endpoint:strOTLP collector endpoint.
insecure:boolWhether to use an insecure (non-TLS) gRPC channel.
Returns
BatchSpanProcessorA batch span processor that exports to the OTLP collector.
Raises
ImportErrorIf the OTLP gRPC exporter is not installed. The caller decides whether to warn and continue or re-raise.
def resolve_endpoint(explicit: str | None, *, env: Mapping[str, str] = os.environ, default: str = DEFAULT_OTLP_ENDPOINT) -> str: (source)

Resolve the OTLP collector endpoint.

Resolution order: explicit -> OTEL_EXPORTER_OTLP_ENDPOINT -> default. Empty values are skipped with a truthiness check, without stripping whitespace.

Parameters
explicit:str | NoneEndpoint supplied directly by the caller, if any.
env:Mapping[str, str]Environment mapping. Defaults to the live process environment.
default:strEndpoint used when nothing else is provided.
Returns
strThe resolved endpoint.
def resolve_service_name(explicit: str | None, fallback_env_vars: Sequence[str], default: str, *, env: Mapping[str, str] = os.environ) -> str: (source)

Resolve the OpenTelemetry service name.

Resolution order: explicit -> OTEL_SERVICE_NAME -> each name in fallback_env_vars in order -> default. Empty values are skipped with a truthiness check, without stripping whitespace.

Parameters
explicit:str | NoneService name supplied directly by the caller, if any.
fallback_env_vars:Sequence[str]Provider-specific environment variable names checked, in order, after OTEL_SERVICE_NAME.
default:strService name used when nothing else is provided.
env:Mapping[str, str]Environment mapping. Defaults to the live process environment.
Returns
strThe resolved service name.