Custom contexts allow you to attach arbitrary data to an event. Often, this context is shared among any issue captured in its lifecycle. You cannot search these, but they are viewable on the issue page:
If you need to be able to search on custom data, use tags instead.
The best practice to attach custom data is via structured contexts. A context must always be a dictionary or map, and its values can be arbitrary. Use
set_context and give the context a unique name:
#include <sentry.h> sentry_value_t character = sentry_value_new_object(); sentry_value_set_by_key(character, "name", sentry_value_new_string("Mighty Fighter")); sentry_value_set_by_key(character, "age", sentry_value_new_int32(19)); sentry_value_set_by_key(character, "attack_type", sentry_value_new_string("melee")); sentry_set_context("character", character);
There are no restrictions for naming contexts or their fields. However, there is a set of conventions for common contexts. For more information, refer to the contexts interface developer documentation.
When sending context, consider payload size limits. Sentry does not recommend sending the entire application state and large data blobs in contexts. If you exceed the maximum payload size, Sentry will respond with HTTP error
413 Payload Too Large and reject the event.
The Sentry SDK will try its best to accommodate the data you send and trim large context payloads or truncate them entirely. For more details, see the developer documentation on SDK data handling.
In addition to structured contexts, Sentry supports adding unstructured "Additional Data" via
set_extra. Additional Data is deprecated in favor of structured contexts and should be avoided when possible.