The Simplest Way to Make Cloud Run and Lightstep Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Running Cloud Run and Lightstep together gives your team clear trace data for serverless apps. Cloud Run hosts your containers, and Lightstep tracks requests across every service. This setup lets developers find slow queries and broken calls in seconds. Fast scaling makes trace data vital when containers start and stop without warning. Good telemetry helps teams spot errors before users notice them. How data and keys flow between Cloud Run and Lightstep Your app runs inside a stateless conta

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Running Cloud Run and Lightstep together gives your team clear trace data for serverless apps. Cloud Run hosts your containers, and Lightstep tracks requests across every service.

This setup lets developers find slow queries and broken calls in seconds. Fast scaling makes trace data vital when containers start and stop without warning. Good telemetry helps teams spot errors before users notice them.

How data and keys flow between Cloud Run and Lightstep

Your app runs inside a stateless container on Google Cloud. When a user sends a request, the container starts up and processes the job. An OpenTelemetry tool inside the app records each step as a span.

The app then sends these spans over the network to Lightstep. To do this, the container needs a valid Lightstep key. Teams store this key in a Google Cloud secret store.

The Cloud Run service account reads the secret when the container boots. It passes the key into the app memory for the exporter to use. Lightstep checks the key, accepts the trace data, and builds a map of the request.

Because containers shut down right after requests finish, batching spans needs care. The exporter must flush all buffered traces before the instance stops running. A clean shutdown hook makes sure the app sends final spans before exit.

Common failure modes and how to scope roles

Many teams use one default service account for all their serverless apps. This shared role often has broad rights to read every secret in the project. If one app gets hacked, the attacker can read keys for all other systems.

Another common issue is sharing one Lightstep key across dev, staging, and prod. When a staging test floods the system, teams cannot block it without breaking prod. Broad keys also make it hard to rotate secrets on a set schedule.

Trace payloads can also leak private data if developers log full request bodies. Customer emails, phone numbers, card numbers, and national IDs can end up in span tags. Anyone who reads traces can then see this private data in plain text.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix these risks, give each Cloud Run service its own service account. Grant that account read rights to only the one secret it needs. Create separate Lightstep keys for each app tier so you can revoke them alone.

Set up data masking rules to scrub sensitive fields before traces leave the container. Masking rewrites matched fields in results so emails and card numbers stay hidden. Also, lock down egress rules so containers only send data to known endpoints.

Keeping trace delivery fast during cold starts

Serverless apps scale down to zero when traffic stops. When a new request hits, the container must boot and load its tools fast. Heavy trace tools can slow down this boot time and hurt user speed.

Keep your trace setup light by loading only the plugins your code uses. Skip auto-check tools for databases or queues that the service never calls. This keeps memory use low and helps new instances start right away.

You can also run a sidecar collector next to your main app container. The main app sends spans to the local collector with zero network delay. The sidecar then handles retries, batching, and secure transit to the trace backend.

This pattern keeps network drops from slowing down your main user requests. It also puts all your trace filtering rules in one neat place. Your team can update export rules in the sidecar without changing app code.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

How do we stop losing traces when Cloud Run scales down?

Listen for the shutdown signal that the platform sends before stopping a container. When that signal arrives, call the flush method on your trace exporter right away. Keep your batch timeout short so spans do not sit in memory for long.

Should we use a sidecar or direct export for trace data?

Direct export works well for small apps with low traffic and simple needs. A sidecar collector is better when you need local batching, retries, and tag scrubbing. The sidecar takes the heavy network work off your main app thread.

How often should we rotate our Lightstep ingestion keys?

Rotate your keys at least once every ninety days or after any staff change. Store the new key version in your secret manager and deploy a new revision. Once traffic shifts to the new revision, delete the old key right away.

The query runs. The emails stay hidden.