GCP: add testbed logging to cloud run #227
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR presents a new approach for logging in Cloud Run following best practices. It should (not sure since Cloud Run Logging has been a nightmare) ensure that all logs from the
testbedpackage appear in Cloud Run Logs.If this works, we can iterate over this implementation to make it more robust and use in our other projects.
Close #222
Currently we only have Cloud Run's infrastructure logs which are automatically generated for every HTTP request/response. Cloud Run creates these automatically without any inference from us (but we have been able to modify the looks of them and how they propagate).
Application logs seems to be missing due to
StructuredLogHandlerwhich writes logs to stdout but Cloud Run is not ingesting them.Our new
CloudLoggingHandlershould sends logs directly to Cloud Logging API with explicit logName, NOT to stdout.As a result, we'll have two types of logs:
1. Infrastructure Logs (already working):
{ "logName": "projects/.../logs/run.googleapis.com%2Frequests", "httpRequest": {...}, "trace": "projects/.../traces/751dff...", // Automatic from Cloud Run }2. Application Logs (NEW - what we'll add):
{ "logName": "projects/.../logs/testbed", // ← Custom name! "message": "User logged in successfully", "trace": "projects/.../traces/751dff...", // ← Same trace! "jsonPayload": { "environment": "staging", "service": "activitypub-testbed-stg-run", ... } }This is an architecture overview describing the new implementation:
CloudLoggingHandlers (from google-cloud-logging library) sends logs records directly to Cloud Logging API
I added a environment variable in our Cloud Run Staging Service called USE_CLOUD_LOGGING.