Flask error handling removes error transactions from APM

Kibana version: 7.11.1

Elasticsearch version: 7.11.1

APM Server version: 7.11.0

APM Agent language and version: Python 6.3.3

Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):

Hi, I'm running a Python Flask application and connected it to APM. However, I've noticed that when I add an error handler to my application as below, APM will see the error without providing a stack trace.

    @app.errorhandler(Exception)
    def handle_anything(error):
        try:
            status_code = error.status_code
        except AttributeError:
            status_code = 500
        response_dict = {"type": str(type(error)), "exception_message": str(error)}
        app.logger.exception(response_dict, status_code=status_code)
        response = jsonify(error=response_dict)
        response.content_type = "application/json"
        response.status_code = status_code
        return response

If I remove this error handling, I get the expected output.

My question is can I add some more sophisticated error handling in a Flask application while still ensuring error traces are captured by the APM agent? Or explicitly ship error traces to APM server somehow?

I have to admit I'm a little surprised that it's reporting it as an error but not collecting the trace. I think this might be a bug. Would you mind reporting it here so we don't lose track of it? I'll try to find some time to reproduce and look into it.

Thanks! I will do so.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.