Our flask app is structured as follows:
flask_app/ |--app |--utils
in the logging config dict in the app dir BOTH the app and utils logger include an identical sentry handler. Now here is where it gets interesting. In file utils.crasher I have:
import logging logger = getLogger(__name__) def crash_boy(): try: 1 + '123' except Exception as e: logger.exception('Oh gosh we messed up big time here') raise e
and in app.main
@bp.route('/crash') def crash(): try: return crash_boy() except Exception as e: logger.exception('OH GREAT') return 'WE HAD A CRASH BOIZ'
The utils logger DOES include a traceback but the app logger will only log the string (‘OH GREAT’) with no stack trace.
After thorough testing our app logger will ONLY log an exceptions stack trace in an uncaught exception of an except block like so:
# 1/0 here would log an error and line number in sentry UI but no stack trace try: 1/0 except Exception as e: logger.exception('Probably did 1/0') # No stack trace in web UI 1 + '1' #will include a stack trace in web UI
So it seems sentry CAN include a traceback via the app logger but only in uncaught exceptions inside an except block.