Skip to content
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

Perform operations after crash #720

Closed
1 of 3 tasks
arijith96 opened this issue May 30, 2022 · 6 comments
Closed
1 of 3 tasks

Perform operations after crash #720

arijith96 opened this issue May 30, 2022 · 6 comments

Comments

@arijith96
Copy link

Description

When does the problem happen

  • During build
  • During run-time
  • When capturing a hard crash

Environment

  • OS: [e.g. Windows 10, 64-bit] Windows 10, 64-bit
  • Compiler: [e.g. MSVC 19] MSVC 19
  • CMake version and config: [e.g. 3.17.2, SENTRY_BACKEND=inproc] 3.16.4, SENTRY_BACKEND=crashpad_handler

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:

  • trim a log file to include only the last 100 lines and then write it into a file and upload that file along with the crash report to sentry
  • zip a certain file and send it along the crash report

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.

@Swatinem
Copy link
Member

The docs are partly out of date. We got the before_send hook 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.

@arijith96
Copy link
Author

Okay, thank you for the update. Will close this issue as soon as I have tried and verified this.

@p0358
Copy link

p0358 commented May 30, 2022

Is there any reliable way to tell whether the before_send hook was called on an actual crash or with some other non-crashing random kind of event?

Looking at

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__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

@p0358
Copy link

p0358 commented May 30, 2022

It seems like the native handler generates a generic event only to discard it after the before_send function...

@Swatinem
Copy link
Member

Swatinem commented Jun 1, 2022

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.

@supervacuus
Copy link
Collaborator

@arijith96, were you able to verify this? feel free to reopen if you still have issues with this.

@p0358, we introduced an on_crash hook 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants