Usage

Use the SDK to manually capture errors and other events.

Sentry's SDK hooks into your runtime environment and automatically reports errors, uncaught exceptions, and unhandled rejections as well as other types of errors depending on the platform.

Python exceptions are captured in Sentry. You can omit the argument to capture_exception and Sentry will attempt to capture the current exception. It is also useful for manual reporting of exceptions or messages to Sentry.

While capturing an event, you can also record the breadcrumbs that lead up to that event. Breadcrumbs are different from events: they will not create an event in Sentry, but will be buffered until the next event is sent. Learn more about breadcrumbs in our Breadcrumbs documentation.

In Python you can either capture a caught exception or the one currently held in sys.exc_info() by not passing an argument:

Copied
import sentry_sdk  try:  a_potentially_failing_function() except Exception as e:  # Alternatively the argument can be omitted  sentry_sdk.capture_exception(e) 

Another common operation is to capture a bare message. A message is textual information that should be sent to Sentry. Typically, our SDKs don't automatically capture messages, but you can capture them manually.

Messages show up as issues on your issue stream, with the message as the issue name.

Copied
import sentry_sdk  sentry_sdk.capture_message('Something went wrong') 
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").