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 one 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 C# you can capture any exception object that you caught:

using Sentry;

catch (Exception err)

To capture an event in Go, you can pass any struct implementing an error interface to CaptureException(). If you use a 3rd party library instead of native errors package, we’ll do our best to extract a stack trace.

The SDK is fully compatible with (but not limited to):


If there is an errors package that’s not working out of the box, let us know!

f, err := os.Open("filename.ext")
if err != nil {

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

try {
} catch (err) {

To capture an error or exception condition, create events containing an exception object. It needs to contain at least a value and type:

#include <sentry.h>

sentry_value_t exc = sentry_value_new_object();
sentry_value_set_by_key(exc, "type", sentry_value_new_string("Exception"));
sentry_value_set_by_key(exc, "value", sentry_value_new_string("Error message."));

sentry_value_t event = sentry_value_new_event();
sentry_value_set_by_key(event, "exception", exc);

This exception does not contain a stack trace, which must be added separately.

In PHP you can either capture a caught exception or capture the last error with captureLastError.

try {
} catch (\Throwable $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 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.

using Sentry;

SentrySdk.CaptureMessage("Something went wrong");
sentry.CaptureMessage("Something went wrong")
Sentry.captureMessage('Something went wrong');
#include <sentry.h>

sentry_value_t event = sentry_value_new_event();
sentry_value_set_by_key(event, "message", sentry_value_new_string("Hello!"));
Sentry\captureMessage('Something went wrong');
from sentry_sdk import capture_message

capture_message('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.

Next Steps

  • Need to add extra data to your events? Have a look at our context documentation.

  • Captured too much data? Have a look at filtering to remove spam or sensitive information from your events.