Advanced Configuration
The Native SDK sets the options when you first initialize the SDK:
sentry_options_t *options = sentry_options_new();
sentry_options_set_environment(options, "Production");
sentry_options_set_release(options, "5fd7a6cd");
sentry_options_set_debug(options, 1);
sentry_init(options);For more information, see:
Capturing Events
The Native SDK exposes a Value API to construct values like Exceptions, User objects, Tags, and even entire Events. There are several ways to create an event.
Manual Events
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 atimestampandevent_id. - Add custom attributes to the event, like a
messageor anexception. - Send the event to Sentry by invoking
sentry_capture_event.
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 extra = sentry_value_new_object();
sentry_value_set_by_key(extra, "screen_size", screen);
sentry_value_set_by_key(event, "extra", extra);
sentry_capture_event(event);For the full list of supported values, see Event Payloads and linked documents.
Exceptions
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);
sentry_capture_event(event);This exception does not contain a stack trace, which must be added separately.
Message Events
To simplify creating events, there are shorthand functions that construct
prepopulated event objects. The most important one is
sentry_value_new_message_event. The logger and message parameters are each
optional.
sentry_value_t event = sentry_value_new_message_event(
/* level */ SENTRY_LEVEL_INFO,
/* logger */ "custom",
/* message */ "It works!"
);Application Crashes
By default, the Native SDK intercepts crash signals and unhandled exceptions to send crash reports to Sentry. Depending on the backend, the crash report can be sent as a conventional event or as a native crash report file. On Windows, Linux, and macOS, the default backends send binary Minidump files. Sentry processes them to extract stack traces and exception information into a readable crash report.
For more information on Minidumps and the limits that apply, see What is a Minidump.
Size Limits
The size of Minidumps can vary between a few kilobytes and many megabytes. Contributing factors are the number of threads, size of stack space, and the number of heap memory regions referenced from the stack. As Minidumps often contain large regions of empty memory, the SDK compresses Minidumps before uploading. Sentry drops requests with a body larger than 20MB, or if they contain files larger than 100MB.
- Package:
- github:getsentry/sentry-native
- Version:
- 0.4.2
- Repository:
- https://github.com/getsentry/sentry-native