Skip to content

Commit

Permalink
feat(native): Provide documentation for on_crash (#5355)
Browse files Browse the repository at this point in the history
  • Loading branch information
supervacuus committed Jul 28, 2022
1 parent f341d2e commit 5321d0c
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/includes/configuration/before-send/native.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,60 @@ int main(void) {
The callback is executed in the same thread as the call to `sentry_capture_event`. Work performed by the function may thus block the executing thread. For this reason, consider avoiding heavy work in `before_send`.
#### Using `on_crash` (starting with version 0.4.19)
The `before_send` callback implementation in `sentry-native` makes it hard to distinguish between normal events
and crashes. For this reason, we introduced another callback, `on_crash`, which - at this point - only exists
in `sentry_native`:
```c
#include <sentry.h>
static sentry_value_t
crash_cleanup(
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
)
{
// Do contextual clean-up before the crash is sent to sentry's backend infrastructure
/* ... */
// tell the backend to retain the event (+ dump)
// or to discard it, you could free the event and return a `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_on_crash(options, crash_cleanup, NULL);
sentry_init(options);
/* ... */
}
```

The `on_crash` callback replaces `before_send` as a callback for crash events only. They can
be defined simultaneously, where the SDK prevents `before_send` from being invoked for crash
events. This allows for better differentiation between crashes and other events and
gradual migration from existing `before_send` implementations:

- If you have a `before_send` implementation and do not define an `on_crash`
callback `before_send` will receive both normal and crash events as before
- If you only want to pre-process normal events with `before_send`, then
you can define an "empty" `on_crash` callback that returns the
passed-in event and does nothing else.
- If you are not interested in pre-processing normal events but only want
to act on crashes, then only define an `on_crash` callback with the option
to filter (available for all backends) or enrich (only for `inproc`) the
crash event.

<Alert level="warning" title="Not Supported in Crashpad on macOS">

The Crashpad backend on macOS doesn't currently support notifying the crashing process and thus can't correctly terminate sessions or call the registered `before_send` hook. It will also lose any events queued for sending at the time of the crash.
The Crashpad backend on macOS doesn't currently support notifying the crashing process and thus can't correctly terminate sessions or call the registered `before_send` or `on_crash` hooks. It will also lose any events queued for sending at the time of the crash.

</Alert>

1 comment on commit 5321d0c

@vercel
Copy link

@vercel vercel bot commented on 5321d0c Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sentry-docs – ./

sentry-docs-git-master.sentry.dev
sentry-docs.sentry.dev
docs.sentry.io

Please sign in to comment.