Monitoring and Speed · Chapter 2 of 4 · 2 min

Logs and Errors

Where Cloud Run logs go, how to find the error that matters in seconds, what a good log line contains, and what must never be logged.

Where the logs are

Everything the server writes to standard output and standard error on Cloud Run goes to Cloud Logging, tagged with the service, the revision and the time. Cloud Run also logs every request: address, status code, latency. Builds log there too. You do not install anything to get this.

Finding errors fast

The console's Logs Explorer is good for browsing. For a quick answer, the command line is faster:

gcloud logging read 'resource.type="cloud_run_revision" AND resource.labels.service_name="iamravi-site" AND severity>=ERROR' \
  --project=PROJECT_ID --freshness=1d --limit=20

Useful variations:

To find Add to the filter
Server errors seen by visitors httpRequest.status>=500
Slow requests httpRequest.latency>"2s"
One deploy's logs resource.labels.revision_name="REVISION"
A word in a message textPayload:"payment"

Read logs backwards

When something breaks, start at the first error after the last good moment, not the last one on the screen. Later errors are often consequences of the first. A missing setting at start-up becomes a hundred failed requests a minute later. Fix the first, and the rest usually vanish.

What a good log line contains

This site's payment code, for example, logs [pay] webhook: amount mismatch for <payment> ... price <amount> when it refuses a payment. Someone reading that line at midnight knows what happened and that nothing was granted.

What must never be logged

Log the name of what is missing, never its value.

Errors visitors should not see

A visitor should get a calm error page, not a stack trace. A dependency failing should cost one feature, not the page: if analytics or the database are unreachable, the dashboard says so in a sentence and the rest still loads. Write the detailed reason to the log, where you can read it, and show the visitor only what helps them.

Keep logs useful

Try it yourself

Run the error query above for your own service over the last week. Group what you find by message. The most frequent error you did not know about is your next fix.