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 |
Build Core telemetry configuration for OTLP metrics export. |
| Function | build |
Build a batch span processor backed by the OTLP gRPC exporter. |
| Function | resolve |
Resolve the OTLP collector endpoint. |
| Function | resolve |
Resolve the OpenTelemetry service name. |
str, service_name: str, metric_periodicity: timedelta | None) -> TelemetryConfig:
(source)
¶
Build Core telemetry configuration for OTLP metrics export.
| Parameters | |
endpoint:str | OTLP collector endpoint. Falls back to
DEFAULT_OTLP_ENDPOINT when empty. |
servicestr | Service name added as the service_name global tag. When empty, no global tag is added. |
metrictimedelta | None | Metric export interval, passed through unchanged. |
| Returns | |
TelemetryConfig | A temporalio.runtime.TelemetryConfig with metrics pointed at
the collector. |
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:str | OTLP collector endpoint. |
insecure:bool | Whether to use an insecure (non-TLS) gRPC channel. |
| Returns | |
BatchSpanProcessor | A batch span processor that exports to the OTLP collector. |
| Raises | |
ImportError | If the OTLP gRPC exporter is not installed. The caller decides whether to warn and continue or re-raise. |
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 | None | Endpoint supplied directly by the caller, if any. |
env:Mapping[ | Environment mapping. Defaults to the live process environment. |
default:str | Endpoint used when nothing else is provided. |
| Returns | |
str | The resolved endpoint. |
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 | None | Service name supplied directly by the caller, if any. |
fallbackSequence[ | Provider-specific environment variable names checked, in order, after OTEL_SERVICE_NAME. |
default:str | Service name used when nothing else is provided. |
env:Mapping[ | Environment mapping. Defaults to the live process environment. |
| Returns | |
str | The resolved service name. |