sentry-native
sentry-native copied to clipboard
Perform operations after crash
Description
When does the problem happen
- [ ] During build
- [x] 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.
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.
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_send
hook was called on an actual crash or with some other non-crashing random kind of event?
Looking at https://github.com/getsentry/sentry-native/blob/9e12f81695bb22a79e141c2e357c4aecf9bc2703/src/backends/sentry_backend_crashpad.cpp#L140-L146 and https://github.com/getsentry/sentry-native/blob/9e12f81695bb22a79e141c2e357c4aecf9bc2703/src/sentry_core.c#L455-L482
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_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.