Sentry's SDK hooks into your runtime environment and automatically reports errors, exceptions, and rejections.
- An event is one instance of sending data to Sentry. Generally, this data is an error or exception.
- An issue is a grouping of similar events.
- The reporting of an event is called capturing. When an event is captured, it’s sent to Sentry.
The most common form of capturing is to capture errors. What can be captured as an error varies by 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 Sentry will attempt to capture the current exception. It is also useful for manual reporting of errors 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.
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 exceptions = sentry_value_new_object(); sentry_value_t values = sentry_value_new_list(); sentry_value_set_by_key(exceptions, "values", values); sentry_value_append(values, exc); sentry_value_t event = sentry_value_new_event(); sentry_value_set_by_key(event, "exception", exceptions); sentry_capture_event(event);
This exception does not contain a stack trace, which must be added separately.
Another common operation is to capture a bare message. A message is textual information that should be sent to Sentry. Typically messages are not emitted, but they can be useful for some teams.
To simplify creating events, there are shorthand functions that construct prepopulated event objects. The most important one is
message parameters are each optional.
#include <sentry.h> sentry_value_t event = sentry_value_new_message_event( /* level */ SENTRY_LEVEL_INFO, /* logger */ "custom", /* message */ "It works!" ); sentry_capture_event(event);
To create and capture a manual event, follow these steps:
- Create an event value using
sentry_value_new_event. This internally creates an object value and initializes it with common event attributes, like a
- Add custom attributes to the event, like a
- Send the event to Sentry by invoking
In a more complex example, it looks like this:
sentry_value_t event = sentry_value_new_event(); sentry_value_set_by_key(event, "message", sentry_value_new_string("Hello!")); sentry_value_t screen = sentry_value_new_object(); sentry_value_set_by_key(screen, "width", sentry_value_new_int32(1920)); sentry_value_set_by_key(screen, "height", sentry_value_new_int32(1080)); sentry_value_t contexts = sentry_value_new_object(); sentry_value_set_by_key(contexts, "screen_size", screen); sentry_value_set_by_key(event, "contexts", contexts); sentry_capture_event(event);
For the full list of supported values, see Event Payloads and linked documents.