# Google Cloud: Cloud Run API Run an instrumented application on Cloud Run and export its traces directly to Corridora. Your frontend can use Firebase Hosting, Cloud Storage with a CDN, or another host. Route API requests to Cloud Run through your existing HTTPS routing or a separate API hostname. Cloud Run request logs and Cloud Trace are separate destinations. Seeing a request there does not show that Corridora received an application span. ## Prerequisites - A working Cloud Run service and image registry, with an application that listens on the platform's `PORT` and `0.0.0.0`. - Instrumentation included in the image; build the [trace-check API](examples/node-api/README.md) or follow a [language guide](../backend/languages/README.md) and [Docker setup](../backend/infrastructure/docker.md). - Permission to update Cloud Run and act as its runtime service account. The documented deployment roles include Cloud Run Admin and Service Account User, or equivalent scoped permissions. - A backend ingest key and a separate browser RUM key in the same Corridora organization. - HTTPS egress to Corridora. If all traffic uses a VPC egress path, that path must provide the required outbound connectivity. Keep the service's existing ingress restrictions and application authentication. This recipe does not make a private service public. ## Create a versioned secret In Secret Manager, create `corridora-otlp-headers` with this complete plaintext value: ```text X-CORRIDORA-KEY=YOUR_BACKEND_INGEST_KEY ``` Select a numbered version for the deployment. Grant the Cloud Run runtime service account `roles/secretmanager.secretAccessor` on this secret. The deployer's permission to configure a reference does not give the running service permission to read its value. Avoid storing the populated value in the container image, ordinary environment YAML, build logs, or source control. Use a new numbered secret version and deploy a revision when rotating the key. ## Set the runtime environment Copy [env.yaml](examples/google-cloud/env.yaml), replace the service identity and release, and merge in the application's existing ordinary environment variables. The YAML contains no credential; the header is supplied separately from Secret Manager. ```yaml OTEL_SERVICE_NAME: "shop-api-gcp" OTEL_EXPORTER_OTLP_PROTOCOL: "http/protobuf" OTEL_EXPORTER_OTLP_ENDPOINT: "https://ingest.corridora.ai" OTEL_TRACES_EXPORTER: "otlp" OTEL_PROPAGATORS: "tracecontext,baggage" OTEL_TRACES_SAMPLER: "parentbased_always_on" ``` This excerpt shows the key settings; use the complete example file, including its explicit log/metric exporter choices. The SDK must support the selected exporter and environment settings. A signal-specific traces endpoint must include `/v1/traces` if you use one instead of the base endpoint. ## Update the service Run with the Google Cloud CLI signed in to the intended project: ```bash export GCP_PROJECT=YOUR_PROJECT_ID export GCP_REGION=us-central1 export CLOUD_RUN_SERVICE=shop-api export IMAGE=YOUR_REGISTRY/shop-api:YOUR_RELEASE export SECRET_VERSION=1 gcloud run services update "$CLOUD_RUN_SERVICE" \ --project "$GCP_PROJECT" --region "$GCP_REGION" \ --image "$IMAGE" \ --env-vars-file env.yaml \ --update-secrets "OTEL_EXPORTER_OTLP_HEADERS=corridora-otlp-headers:$SECRET_VERSION" \ --no-cpu-throttling ``` `--env-vars-file` replaces ordinary environment variables; include the settings the application already needs. `--update-secrets` preserves unrelated secret mappings. Keeping CPU allocated between requests allows a background batch exporter to run; this changes the service's billing behavior. Retain graceful shutdown/flush in your SDK because revision termination and scale-down still occur. A deployment that previously pinned traffic to an older revision may need an explicit traffic change through your normal rollout process. ## Connect the browser Install [Corridora RUM](../../browser-rum.md) in the shared page template. For a separate HTTPS Cloud Run/API origin, add its exact origin to `data-trace-origins`. Configure API CORS to allow the frontend origin, its existing headers, and `traceparent`. Ensure the load balancer or gateway forwards the incoming header. An IAM-protected endpoint still needs the application's established access design; a RUM key is not a Cloud Run identity token. Permit preflight in the route design without weakening the authorization of the actual API operation. Keep the diagnostic API route uncached. A cache hit in frontend hosting or Cloud CDN produces no new origin request. Merely serving HTML from Cloud Run does not automatically connect its initial navigation request to a later browser session. ## Verify and operate 1. Confirm the intended revision receives traffic and has the numbered secret reference. 2. Check startup errors for secret access or exporter initialization failures. 3. Make a browser request after RUM starts, and compare browser and backend trace IDs using [verification](../verification.md). 4. Confirm the backend span is stored in Corridora, then repeat on a cold instance and after rollout. 5. Exercise an actual outbound HTTP/database operation to validate child spans and downstream propagation. If backend context matches but no stored spans appear, inspect outbound access, exporter protocol/path, key status, and lifecycle flushing. A successful application response can precede a failed asynchronous export. For GKE use [Kubernetes setup](../backend/infrastructure/kubernetes.md). For a shared Collector gateway, use the [Collector guide](../../collector.md) and point the application at the gateway's reachable OTLP listener.