Add GCP Cloud Run OpenTelemetry support - #1767
Open
seanbollin wants to merge 6 commits into
Open
Conversation
Adds a Cloud Run serverless-worker OpenTelemetry integration, mirroring the approved .NET SDK common-core refactor (temporalio/sdk-dotnet#844) and building on #1658. - New package temporalio.contrib.gcp.cloud_run: an OpenTelemetryPlugin that exports Core metrics and tracing spans over OTLP/gRPC to a local OpenTelemetry Collector sidecar. Cloud Run specifics only (service name from CLOUD_RUN_WORKER_POOL/K_SERVICE, 60s metric periodicity); gated behind a new cloud-run-worker-otel extra, no google-cloud client libraries. - New private temporalio/contrib/opentelemetry/_serverless.py: shared, provider-neutral helpers (endpoint/service-name resolution, Core-metrics telemetry config, lazy OTLP span-processor factory). It is not re-exported, so importing temporalio.contrib.opentelemetry gains no exporter import. - Refactor the AWS Lambda lambda_worker/otel.py onto _serverless with no public API or behavior change (existing tests unmodified). Co-authored-by: Edward Amsden <[email protected]> Co-Authored-By: Claude Opus 4.8 <[email protected]>
3 tasks
Records the new optional-dependency extra in the lockfile. The extra reuses packages already locked via lambda-worker-otel, so there are no new package or version changes. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The lazy OTLPSpanExporter import in _serverless.build_otlp_span_processor tripped basedpyright reportMissingTypeStubs under the test-latest-deps job (whose newer exporter build ships no type stubs). Matches the existing suppression pattern in contrib/aws/lambda_worker/otel.py. Co-Authored-By: Claude Opus 4.8 <[email protected]>
seanbollin
marked this pull request as ready for review
August 20, 2026 19:15
The extra required opentelemetry-exporter-otlp-proto-grpc>=1.11.1 without a companion constraint pinning a modern OpenTelemetry stack (unlike lambda-worker-otel, whose opentelemetry-sdk-extension-aws>=2.0.0 transitively caps protobuf<7). That let uv lock --upgrade downgrade the exporter to 1.11.1 and pull the just-released protobuf 7.35.1, whose runtime is incompatible with the old generated protobuf code (test-latest-deps failures). Raising the floor to >=1.26 (matching the api/sdk floors in this extra) removes the ancient version from the resolution; uv lock --upgrade now holds at protobuf 6.33.6. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Raising the exporter floor to >=1.26 (previous commit) fixed test-latest-deps but broke check-protos: that job forces protobuf<4 and runs uv sync --all-extras, and a >=1.26 exporter requires protobuf>=4, so uv could not resolve. Restore the low >=1.11.1 floor (matching lambda-worker-otel) so the exporter can downgrade to a protobuf-3-compatible build under protobuf<4, and add an explicit protobuf<7 cap so uv lock --upgrade (test-latest-deps) cannot downgrade the exporter to pull the incompatible protobuf 7.x. Satisfies both jobs. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds GCP Cloud Run serverless-worker OpenTelemetry support, mirroring the approved .NET SDK common-core refactor (temporalio/sdk-dotnet#844) and building on the earlier draft #1658.
temporalio.contrib.gcp.cloud_run— anOpenTelemetryPluginthat exports Core metrics and tracing spans over OTLP/gRPC to a local OpenTelemetry Collector sidecar. Cloud Run specifics only (service name fromCLOUD_RUN_WORKER_POOL/K_SERVICE, 60s metric periodicity). Gated behind a newcloud-run-worker-otelextra; nogoogle-cloud-*libraries — the collector does GCP resource detection, auth, and export.temporalio/contrib/opentelemetry/_serverless.py— shared, provider-neutral helpers (endpoint/service-name resolution, Core-metrics telemetry config, a lazy OTLP span-processor factory). It is not re-exported, so importingtemporalio.contrib.opentelemetrygains no exporter import.lambda_worker/otel.pyonto_serverless, with no public API or behavior change.Credit
Builds directly on @eamsden's draft #1658. Ported from that PR:
OpenTelemetryPluginsubclass —connect_service_clientruntime injection,force_flush/shutdown/flush_on_worker_stop,add_temporal_spans— its unit tests, and the README.New in this PR, on top of @eamsden's work: the shared private
_serverless.pyextraction, the refactor ofaws/lambda_worker/otel.pyonto it, thetemporalio.contrib.gcp.cloud_runsub-package placement, and thecloud-run-worker-otelextra naming + OTel version-floor alignment.Non-breaking
The base
opentelemetryextra is unchanged, and importingtemporalio.contrib.opentelemetrypulls in zero exporter modules (the exporter import is lazy, insidebuild_otlp_span_processor). The AWS Lambdaotel.pypublic signatures/behavior are unchanged — its existing tests pass unmodified (the non-breakage gate). Non-Lambda / non-Cloud-Run users are unaffected.Verification
pytest tests/contrib/opentelemetry/test_serverless.py tests/contrib/gcp tests/contrib/aws/lambda_worker/test_otel.py— 48 pass (incl. the AWS file unmodified). Isolation proof verified empirically; ruff / pyright / basedpyright / mypy clean.Related
Companion sample: temporalio/samples-python (Cloud Run worker). Cross-SDK effort with sdk-go, sdk-java, and .NET (temporalio/sdk-dotnet#844).
🤖 Generated with Claude Code