Ship logs and traces from your Cloud Run service to Better Stack using the Google-built OpenTelemetry collector as a sidecar.
Your app sends logs and metrics to the collector on localhost as OpenTelemtry, and the collector forwards everything to Better Stack.
Enable Google Run and SecretsManager APIs:
Save the following config as config.yaml:
Store the config as a secret so Cloud Run can mount it into the collector:
Grant access to the secret to the Cloud Run runtime:
Get your PROJECT_NUMBER using gcloud projects describe PROJECT_ID --format='value(projectNumber)'. If you're using a custom service account, grant the role to that account instead of the default compute one.
Save your service manifest as service.yaml. The container-dependencies annotation starts the collector before your app, and the app sends OTLP to the collector on localhost:4317:
Replace my-service, image, PROJECT_ID, PROJECT_NUMBER, and REGION with your own values. The image is your full Artifact Registry path. Then deploy:
Port 4317 is the collector's gRPC endpoint, so the app sets OTEL_EXPORTER_OTLP_PROTOCOL=grpc. To use HTTP instead, point OTEL_EXPORTER_OTLP_ENDPOINT at http://localhost:4318 and drop the protocol variable.
Instrument your app with the OpenTelemetry SDK for your language so it emits OTLP logs and traces. SDKs are available for JavaScript, Python, Go, and Java. Use the OTEL_EXPORTER_OTLP_ENDPOINT environment variable to point the SDK to the collector.
You should see your logs and traces in Better Stack → Live tail.
Cloud Run scales to zero, so send a request to your service URL to wake your instance.
Collect metrics for Google Cloud Run and other Google Cloud services. Deploy Google Cloud integration into your GCP project via ready-to-use script. Start by creating a GCP source.
Read more about Better Stack Google Cloud integration.
Please let us know at hello@betterstack.com.
We're happy to help! 🙏
We use cookies to authenticate users, improve the product user experience, and for personalized ads. Learn more.