Capturing Events

Out of the box SDKs will attempt to hook themselves into your runtime environment or framework to automatically report fatal errors. However in many situations it’s useful to manually report errors or messages to Sentry. This is called “capturing”. When an event is captured it’s sent to Sentry and will create a new issue group or be added to an already existing once based on Sentry’s grouping algorithm. Separately to capturing you can also record “breadcrumbs” that lead up to an event. Breadcrumbs are different in that they will not create an event in Sentry but will be buffered until the next event is sent. For more information have a look at the breadcrumbs documentation.

Capturing Errors / Exceptions

The most common form of capturing is to capture errors. What can be captured as an error will depend on the platform. In general if you have something that looks like an exception it can be captured. For some SDKs you can also omit the argument to capture_exception and it will attempt to capture the current exception.

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

from sentry_sdk import capture_exception

except Exception as e:
    # Alternatively the argument can be omitted

In JavaScript you can pass an error object to captureException() to get it captured as event. Note that it’s possible to throw strings as errors in which case no traceback can be recorded.

try {
} catch (err) {

In C# you can capture any exception object that you caught:

using Sentry;

catch (Exception err)

In Rust you can capture errors that implement the Fail trait or that are failure::Error objects:

use sentry::integrations::failure::capture_error;

let result = match function_that_might_fail() {
    Ok(result) => result,
    Err(err) => {
        return Err(err);

Capturing Messages

Another common operation is to capture a bare message. A message is just some textual information that should be sent to Sentry. Typically messages are not emitted but there are situations when this is useful.

from sentry_sdk import capture_message

capture_message('Something went wrong')
Sentry.captureMessage('Something went wrong');
using Sentry;

SentrySdk.CaptureMessage("Something went wrong");
use sentry::{capture_message, Level};

capture_message("Something went wrong", Level::Info);

Capturing Events

SDKs generally also provide ways to capture entire custom event objects. This is what integrations internally use to capture bespoke events with a lot of extra data fed into. For more information about that consult the API documentation of the SDK.