Skip to content

feat(native): update before_send docs #13984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions docs/platforms/native/common/configuration/filtering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ All Sentry SDKs support the <PlatformIdentifier name="before-send" /> callback m

Note also that breadcrumbs can be filtered, as discussed in [our Breadcrumbs documentation](/product/error-monitoring/breadcrumbs/).

#### Event Hints

The <PlatformIdentifier name="before-send" /> callback is passed both the `event` and a second argument, `hint`, that holds one or more hints.

Typically, a `hint` holds the original exception so that additional data can be extracted or grouping is affected. In this example, the fingerprint is forced to a common value if an exception of a certain type has been caught:

<PlatformContent includePath="configuration/before-send-hint" />

When the SDK creates an event or breadcrumb for transmission, that transmission is typically created from some sort of source object. For instance, an error event is typically created from a log record or exception instance. For better customization, SDKs send these objects to certain callbacks (<PlatformIdentifier name="before-send" />, <PlatformIdentifier name="before-breadcrumb" /> or the event processor system in the SDK).


## Filtering Transaction Events

To prevent certain transactions from being reported to Sentry, use the <PlatformIdentifier name="traces-sampler" /> or <PlatformIdentifier name="before-send-transaction" /> configuration option, which allows you to provide a function to evaluate the current transaction and drop it if it's not one you want.
Expand Down
38 changes: 0 additions & 38 deletions platform-includes/configuration/before-send-hint/native.mdx

This file was deleted.

38 changes: 28 additions & 10 deletions platform-includes/configuration/before-send/native.mdx
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
```c
#include <sentry.h>

sentry_value_t strip_sensitive_data(sentry_value_t event, void *hint) {
/* modify event here or return NULL to discard the event */
return event;
sentry_value_t strip_sensitive_data(sentry_value_t event, void *hint, void *user_data) {
(void)hint; // unlike in other SDKs, `hint` currently contains no data.
// to get more crash context into a callback, use the `on_crash` hook instead.

if (strcmp(sentry_value_as_string(sentry_value_get_by_key(event, "level")), "info") == 0) {
// remove the user data from "info" level events
sentry_value_remove_by_key(event, "user");
// make our mark on the event
sentry_value_t tags = sentry_value_get_by_key(event, "tags");
if (!sentry_value_is_null(tags)) {
sentry_value_set_by_key(tags, "info", sentry_value_new_string((char*) user_data));
}
}

// return the modified event, or discard it by freeing it and returning `null`
// sentry_value_decref(event);
// return sentry_value_new_null();
return event;
}

int main(void) {
sentry_options_t *options = sentry_options_new();
sentry_options_set_before_send(options, strip_sensitive_data, NULL);
sentry_options_set_before_send(options, strip_sensitive_data, "anonymized");
sentry_init(options);

/* ... */
Expand All @@ -25,14 +40,17 @@ The `before_send` callback implementation in `sentry-native` makes it hard to di
#include <sentry.h>

static sentry_value_t
crash_cleanup(
on_crash_callback(
const sentry_ucontext_t *uctx, // provides the user-space context of the crash
sentry_value_t event, // used the same way as in `before_send`
void *closure // user-data that you can provide at configuration time
sentry_value_t event, // used the same way as in `before_send`; mostly empty for minidump-generating backends (crashpad, breakpad)
void *user_data // user-data that you can provide at configuration time
)
{
// Do contextual clean-up before the crash is sent to sentry's backend infrastructure

// Enrich an event before the crash is sent to sentry's backend infrastructure
sentry_value_t tags = sentry_value_get_by_key(event, "tags");
if (!sentry_value_is_null(tags)) {
sentry_value_set_by_key(tags, "crash_hook", sentry_value_new_string("invoked"));
}
/* ... */

// tell the backend to retain the event (+ dump)
Expand All @@ -44,7 +62,7 @@ crash_cleanup(

int main(void) {
sentry_options_t *options = sentry_options_new();
sentry_options_set_on_crash(options, crash_cleanup, NULL);
sentry_options_set_on_crash(options, on_crash_callback, NULL);
sentry_init(options);

/* ... */
Expand Down