Improve logging integration
Opened this issue · 1 comments
Currently there's some minor effort at logging integration with Google Cloud logging (Where this is usually running and deployed), however in particular the logs aren't grouped under the request due to not observing the Trace
behaviour described at https://cloud.google.com/run/docs/logging#correlate-logs
I like Logrus, I'd rather keep using it than switch to Google's logging library, I should refactor logging to add support for that trace mechanic, and also to toggle that structured logging on or off for deployment/execution in other environments
Interesting, https://pkg.go.dev/cloud.google.com/go/logging?tab=doc mentions additional constraints for tracing
Grouping Logs by Request
To group all the log entries written during a single HTTP request, create two Loggers, a "parent" and a "child," with different log IDs. Both should be in the same project, and have the same MonitoredResouce type and labels.
- Parent entries must have HTTPRequest.Request populated. (Strictly speaking, only the URL is necessary.)
- A child entry's timestamp must be within the time interval covered by the parent request (i.e., older than parent.Timestamp, and newer than parent.Timestamp - parent.HTTPRequest.Latency, assuming the parent timestamp marks the end of the request.
- The trace field must be populated in all of the entries and match exactly.
You should observe the child log entries grouped under the parent on the console. The parent entry will not inherit the severity of its children; you must update the parent severity yourself.