3
votes

I'm using Google App Engine standard environment to host a python-flask-application and I'm having issues to get the errors to show up in StackDriver Error Reporting. By default Google App Engine should log errors to StackDriver Error Reporting, but it doesn't.

I've had errors before that showed up in StackDriver Error Reporting, but I can't reproduce that. The errors seem to go straight to the Server-Errors section and not to the Application-Errors. But it seems logical to me that both are logged in StackDriver Error Reporting.

I did some debugging in order to get it working using routes /error and /500. The result was the following:

  • The errors show up in the Google App Engine overview: All Google App Engine Errors
  • Both are visible in the logs: Errors visible in logs
  • But nothing shows up in StackDriver Error Reporting: No errors in StackDriver Error Reporting

Would anyone have an idea why this is the case?

UPDATE: I found that using the flask.logger seems to be the problem. Using logging works ok and ends up in StackDriver Error Reporting (except for some formatting issues). Both do end up in the logger though. I am using a logging.StreamHandler to register to flask.logger using addHandler. My best guess is that there is something wrong with the formatting of the logging.StreamHandler. Investigating further.

1
@Arun It doesn't seem like this is the same issue. My errors get logged correctly, but they just don't end up in StackDriver Error Reporting. - Lowie Huyghe
I have faced the same issue. Maybe during app engine instance scaling? - Arun
@Arun I checked the logs and they were logged on an instance with the same id, 1 minute and 18 seconds apart. So if scaling were the issue, then at least the second one should have been logged to StackDriver Error Reporting. Alas.. - Lowie Huyghe

1 Answers

2
votes

After some digging and debugging using the Google App Engine SDK I found that there is a logging-handler for GAE:

google.appengine.api.app_logging.AppLogsHandler

Google App Engine registers one to logging, but not to flask.logger. So if you use app.logger.error(my_error) for example, it won't register to StackDriver Error Reporting.

Now I register one manually which fixes the issue:

from google.appengine.api.app_logging import AppLogsHandler
app.logger.addHandler(AppLogsHandler())

app.logger.error(my_error)