Phil Sheard
Phil Sheard

Reputation: 2162

Sentry logging via Flask app

I'm testing the Sentry error logging system (getsentry.com) within a Flask app. As well as exceptions I'm trying to record some key logging.INFO messages for background processes.

To test I'm using the built-in Flask logger to send messages to Sentry for key URL requests.

The problem is that the logging entries aren't sent to Sentry as they happen. Instead they seem to be 'saved up' and only get sent once the app process has finished, which is no use for a production server.

I thought it might be an issue that I'm using Docker containers but I've tested Sentry within a basic app and debug server and the same happens.

I can provide code if needed (just on phone ATM) but thought this might be enough with someone familiar with the issue.

Upvotes: 2

Views: 2476

Answers (1)

David Cramer
David Cramer

Reputation: 1998

It's likely that whatever thread model youre application is using isn't playing well with the Sentry SDK's default threaded transport:

https://github.com/getsentry/raven-python/blob/master/raven/transport/threaded.py#L26

You'll notice that it forces any pending messages to be sent when the process is terminated, which is likely what you're hitting. The real issue however, is that the worker thread seems to not be running.

You should try using the synchronous HttpTransport, or determine whether the above is true or not:

https://docs.getsentry.com/hosted/clients/python/transports/

Upvotes: 1

Related Questions