You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/includes/configuration/before-send/native.mdx
+53-1Lines changed: 53 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -17,8 +17,60 @@ int main(void) {
17
17
18
18
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`.
19
19
20
+
21
+
#### Using `on_crash` (starting with version 0.4.19)
22
+
23
+
The `before_send` callback implementation in `sentry-native` makes it hard to distinguish between normal events
24
+
and crashes. For this reason, we introduced another callback, `on_crash`, which - at this point - only exists
25
+
in `sentry_native`:
26
+
27
+
```c
28
+
#include <sentry.h>
29
+
30
+
static sentry_value_t
31
+
crash_cleanup(
32
+
const sentry_ucontext_t *uctx, // provides the user-space context of the crash
33
+
sentry_value_t event, // used the same way as in `before_send`
34
+
void *closure // user-data that you can provide at configuration time
35
+
)
36
+
{
37
+
// Do contextual clean-up before the crash is sent to sentry's backend infrastructure
38
+
39
+
/* ... */
40
+
41
+
// tell the backend to retain the event (+ dump)
42
+
// or to discard it, you could free the event and return a `null`:
The `on_crash` callback replaces `before_send` as a callback for crash events only. They can
58
+
be defined simultaneously, where the SDK prevents `before_send` from being invoked for crash
59
+
events. This allows for better differentiation between crashes and other events and
60
+
gradual migration from existing `before_send` implementations:
61
+
62
+
- If you have a `before_send` implementation and do not define an `on_crash`
63
+
callback `before_send` will receive both normal and crash events as before
64
+
- If you only want to pre-process normal events with `before_send`, then
65
+
you can define an "empty" `on_crash` callback that returns the
66
+
passed-in event and does nothing else.
67
+
- If you are not interested in pre-processing normal events but only want
68
+
to act on crashes, then only define an `on_crash` callback with the option
69
+
to filter (available for all backends) or enrich (only for `inproc`) the
70
+
crash event.
71
+
20
72
<Alertlevel="warning"title="Not Supported in Crashpad on macOS">
21
73
22
-
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.
74
+
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.
0 commit comments