Correlating logs for App Engine Standard in Python3 using Flask

105 Views Asked by At

There has been many posts about this topic, but I was not able to find a definite answer on establishing correlated logs under the HTTP Request logs like it used to be in App Engine using Python 2.7

I already checked:

  1. Cloud Run Writing Structure logs which hasn't worked for me, I am also not sure when or how is this auto called on each HTTP request to correlate subsequent functions logs. I might have missed something or the Docs was not clear enough with a real example of adding multiple logs under the same HTTP request log. Again similar to what used to happen automatically in Python 2.7.
  • it was not also clear if this would work with the standard python logging, ex: logging.info(), logging.warning(), logging.error() ...etc.
  1. Add Engine docs "Writing structured logs to stdout and stderr" Also mentioned using X-Cloud-Trace-Context to set other logs under the same TraceID, but again it wasn't quite clear how can this be established despite the example listed. I hav etried multiple combinations of settings, but the logs still seem to be each on its own line in StackDriver logs.
  • it was not also clear if this would work with the standard python logging, ex: logging.info(), logging.warning(), logging.error() ...etc.
  1. Using Logging library to write structured logs seems to need quite a different setup than Python logging requiring to be called using logger.log_struct({}) which would require changing all the standard python logging calls, ex: logging.info(), logging.warning(), logging.error()

  2. GAE Python 3.x, errors logs are not correlated with request details Topic seems to be mentioned in issue tracker, but there seem to be no update or workaround until it is resolved

  3. Flask extension for grouped log lines for Google Cloud Logging Others have created individual repos to try to solve the problem, but they are usually old posts (3~5 years)

Has there been any final solution for correlating logs to HTTP requests as it used to be in Python 2.7 from Google? Sort of a standard way to accomplish the structured way logs were displayed allowing easy tracing of issues and logs? Preferably using the normal python logging logging.info()..

Thank you.

0

There are 0 best solutions below