APM Flask - Treating all transactions as Errors

Errors are a special case -- we won't surface error logs as errors; they are a specific type of document in the APM data stream.

The APM Agent automatically sends error documents when it catches an unhandled exception. However, it doesn't know about exceptions that your app successfully handles; this is why we provide the Client.capture_exception() function:

import elasticapm
try:
    # do some work
except Exception as e:
    # handle exception
    elasticapm.get_client().capture_exception()

This will capture the stacktrace and other contextual information about the active exception and send it to the APM Server as an error document.

1 Like