Repository navigation
Perform operations after crash #720
Description
Activity
The docs are partly out of date. We got the
before_sendhook working on Windows and Linux. However macOS is the odd one out here that still does not support this.Switching to the breakpad handler should also provide this functionality, as with that backend, the hook is being invoked on all platforms.
Okay, thank you for the update. Will close this issue as soon as I have tried and verified this.
Is there any reliable way to tell whether the
before_sendhook was called on an actual crash or with some other non-crashing random kind of event?Looking at
sentry-native/src/backends/sentry_backend_crashpad.cpp
Lines 140 to 146 in 9e12f81
sentry_value_t event = sentry_value_new_event(); if (options->before_send_func) { SENTRY_TRACE("invoking `before_send` hook"); event = options->before_send_func( event, NULL, options->before_send_data); } sentry_value_decref(event);
and
sentry-native/src/sentry_core.c
Lines 455 to 482 in 9e12f81
sentry__prepare_event(const sentry_options_t *options, sentry_value_t event, sentry_uuid_t *event_id) { sentry_envelope_t *envelope = NULL; if (event_is_considered_error(event)) { sentry__record_errors_on_current_session(1); } bool should_skip = !sentry__roll_dice(options->sample_rate); if (should_skip) { SENTRY_DEBUG("throwing away event due to sample rate"); goto fail; } SENTRY_WITH_SCOPE (scope) { SENTRY_TRACE("merging scope into event"); sentry_scope_mode_t mode = SENTRY_SCOPE_ALL; if (!options->symbolize_stacktraces) { mode &= ~SENTRY_SCOPE_STACKTRACES; } sentry__scope_apply_to_event(scope, options, event, mode); } if (options->before_send_func) { SENTRY_TRACE("invoking `before_send` hook"); event = options->before_send_func(event, NULL, options->before_send_data); it seems like one way would be to check if the event passed to the hook function is empty/null (as with crash) or not empty (as with other kind of event), is that the expected way to go about this?
And the telling those apart itself is definitely needed, since a random silent event shouldn't generate stuff like extra diagnostic logging or displaying a message to the user about crash
It seems like the native handler generates a generic event only to discard it after the before_send function...
Depending on the crash backend, we may also have a full event object (in case of inproc).
We could think about exposing a new hook that is only called in case of crash.
@arijith96, were you able to verify this? feel free to reopen if you still have issues with this.
@p0358, we introduced an
on_crashhook with 0.5.0. Depending on the backend, you will still get different behavior concerning enrichment and filtering, but it allows you to distinguish between crashes and other events.Reacted by p0358
Description
When does the problem happen
Environment
Steps To Reproduce
I wanted to know how I could perform some operations right after a crash has occurred, since I want to do somethings like the following:
I came across
before_send()but as stated in the docs, but it states that crashpad does not invoke this when a crash occurs. Please note that my primary intention is for crashes only and not for any message/error events.