问题
I have a module running in App Engine Classic and another module running in App Engine Flexible. When viewing logs running in App Engine Classic, the log entries are nested within each request.
However, when viewing logs running in App Engine Flexible, they are not nested. Each log entry appears to be unconnected from the request. This makes it very difficult to determine which log is associated with which request.
Is it possible to get the logs in App Engine Flexible to be nested under each request (as they are with App Engine Classic)?
I cannot find anything in the documentation that explains this discrepancy.
回答1:
You can now write nested application logs that behave similarly to App Engine Standard by following the instructions here: https://cloud.google.com/logging/docs/view/service/appengine-logs#linking_application_logs_and_requests
回答2:
As you might imagine, App Engine Flexible uses a good bit of different machinery from traditional App Engine, and these different environments do log differently. It is unfortunately not currently possible to induce Flexible to log in the same data format as Classic.
If this is sufficiently important to you, you can always directly log via the Cloud Logging API, which is what the App Engine logging API ends up passing through to today. You can infer the data format to log by looking at traditional App Engine entries, though we have open a feature request to publicly document this more explicitly.
Also, as a passing note, on the Stackdriver Logging (formerly Cloud Logging) front, we're definitely thinking about ways to support this kind of denormalization of log data more generally, rather than just special-casing for App Engine logging in a specific format, as this would be broadly useful functionality. However, we don't have any specific plans or timelines that we can share at this point—just noting that this is on our radar.
回答3:
The suggestion by Marc Unangst to link application logs and requests sounds great, unfortunately the documentation on how to achieve this is not very clear (https://cloud.google.com/appengine/articles/logging#linking_app_logs_and_requests).
Using the "Google App Engine flexible Log Handler" from the Google Cloud Client Libraries for Python (https://google-cloud-python.readthedocs.io/en/latest/logging/handlers-app-engine.html) I have been able to log to the 'app' log that is part of the log-stack of the app engine flexible app itself. So I am currently in the same boat as the topic starter.
I noticed that, as required for log linking, the resource.labels
and resource.type
properties are automatically set correctly this way. However, trace
information is absent, instructions seem to be missing on how to include this.
Next, the timing seems to always be off as well. The instructions require the timestamp
of the app log entries to be in between parent.timestamp - parent.httpRequest.latency
of the corresponding HTTP request. I'm noticing that the timestamps of my app log entries are always slightly later then the timestamp
of the corresponding request. Which is weird since these entries are made during the request.
To me it currently looks like the log handler is unaware of an HTTP request cycle going on while writing log entries (I am using this with Django), hence the missing trace
id's? Not sure on how to continue from here, love to hear what others may have achieved.
来源:https://stackoverflow.com/questions/36883027/logs-are-not-nested-under-requests-in-flexible-vm