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

feat: crashpad backend allows inspecting the event-id in the on_crash/before_send hooks #840

Closed
wants to merge 3 commits into from

Conversation

supervacuus
Copy link
Collaborator

fixes #779

@github-actions
Copy link

github-actions bot commented May 9, 2023

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against ceff52f

@supervacuus supervacuus force-pushed the feat/crashpad_hooks_support_event_id branch from 6a2f469 to ceff52f Compare May 9, 2023 16:43
@codecov
Copy link

codecov bot commented May 9, 2023

Codecov Report

Merging #840 (ceff52f) into master (6011498) will increase coverage by 0.47%.
The diff coverage is 77.77%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #840      +/-   ##
==========================================
+ Coverage   82.08%   82.56%   +0.47%     
==========================================
  Files          52       53       +1     
  Lines        7141     7354     +213     
  Branches     1149     1185      +36     
==========================================
+ Hits         5862     6072     +210     
+ Misses       1181     1173       -8     
- Partials       98      109      +11     

@supervacuus supervacuus marked this pull request as ready for review May 9, 2023 17:19
@supervacuus
Copy link
Collaborator Author

supervacuus commented May 9, 2023

So, this basic implementation "works" as it does what it's supposed to do. But as mentioned in the second paragraph here: #779 (comment), why don't we take this further?

According to this comment in relay, __sentry-event supports a full event payload. So why don't we replace the event_id in crashpad_state_t with an actual event (or crash_event for bikeshed's sake), and if the event isn't null (which only happens when we crash), we use it instead of the empty object to init the msg-pack container when flushing the scope? Then the crashpad backend could officially enrich events in the hooks. We don't have to do this in this PR, but I would love to hear any things unconsidered on my side.

And yes, we don't have to flush the scope in the crash handler as suggested in this PR, we can also only serialize the event_id in an otherwise empty object. I just wanted to test this towards event enrichment. We may no longer be async-safe, although we currently do many things in the handler, where I am unsure if we are.

Copy link
Member

@markushi markushi left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -141,7 +146,9 @@ sentry__crashpad_handler(int signum, siginfo_t *info, ucontext_t *user_context)
sentry_value_t event = sentry_value_new_event();

SENTRY_WITH_OPTIONS (options) {

auto *data = static_cast<crashpad_state_t *>(options->backend->data);
data->event_id = sentry_value_get_by_key(event, "event_id");
Copy link
Member

Choose a reason for hiding this comment

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

I guess there should never be the situation where data->event_id has already been set / needs to be freed first right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is a good question. If we end up in the handler function the way we currently return to the FirstChanceHandler (or plain exit at the end), there is practically no way for the handler to execute again. And since it is the first mutation of event_id where an allocation happens, I guess we are fine (also considering that we are in the process of crashing).

} crashpad_state_t;

static void
sentry__crashpad_backend_user_consent_changed(sentry_backend_t *backend)
crashpad_backend_user_consent_changed(sentry_backend_t *backend)
Copy link
Member

Choose a reason for hiding this comment

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

is there a particular reason for renaming all these functions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The main reason is that across the modules, it seemed that the naming scheme is (or was at some point):

  • sentry_* for all publicly available interfaces via sentry.h
  • sentry__* for all private interfaces which cross module boundaries (i.e., are only internally exposed via module headers)
  • no prefix for all static (i.e., module-private) functions, which shouldn't easily conflict in any "namespace"

So one part is trivial consistency, but it also gets easier to navigate if I know from the name if there might be an external contract to consider.

@supervacuus
Copy link
Collaborator Author

closing in favor of #843

@supervacuus supervacuus deleted the feat/crashpad_hooks_support_event_id branch September 12, 2023 13:53
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

Successfully merging this pull request may close these issues.

Allow inspecting event-id for crashpad events
3 participants