Skip to content

feat(native): update before_send docs #13984

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JoshuaMoelans
Copy link
Member

@JoshuaMoelans JoshuaMoelans commented Jun 10, 2025

Latest Vercel Preview

DESCRIBE YOUR PR

Fixes getsentry/sentry-native#1268

We fix some ancient docs which wrongly state that before_send uses the hint parameter in the Native SDK, by cleaning up the unnecessary 'Event Hints' section.

We move the example snippet into the corresponding before_send and on_crash sections, better showcasing how to use the passed-in values.

IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs to go live.

  • Urgent deadline (GA date, etc.):
  • Other deadline:
  • None: Not urgent, can wait up to 1 week+

SLA

  • Teamwork makes the dream work, so please add a reviewer to your PRs.
  • Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it.
    Thanks in advance for your help!

PRE-MERGE CHECKLIST

Make sure you've checked the following before merging your changes:

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

Copy link

vercel bot commented Jun 10, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sentry-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 11, 2025 10:49am
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
changelog ⬜️ Ignored (Inspect) Visit Preview Jun 11, 2025 10:49am
develop-docs ⬜️ Ignored (Inspect) Visit Preview Jun 11, 2025 10:49am

@codeowner-assignment codeowner-assignment bot requested a review from a team June 10, 2025 14:40
Copy link

codecov bot commented Jun 10, 2025

Bundle Report

Changes will decrease total bundle size by 237 bytes (-0.0%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sentry-docs-server-cjs 10.86MB -231 bytes (-0.0%) ⬇️
sentry-docs-client-array-push 9.77MB -6 bytes (-0.0%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: sentry-docs-client-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
static/chunks/pages/_app-*.js -3 bytes 873.24kB -0.0%
static/chunks/7750-*.js -3 bytes 401.83kB -0.0%
static/Ft84B9YPuO1tT4ZMXAW4p/_buildManifest.js (New) 616 bytes 616 bytes 100.0% 🚀
static/Ft84B9YPuO1tT4ZMXAW4p/_ssgManifest.js (New) 77 bytes 77 bytes 100.0% 🚀
static/_JO8KwStScyId4M36-*.js (Deleted) -616 bytes 0 bytes -100.0% 🗑️
static/_JO8KwStScyId4M36-*.js (Deleted) -77 bytes 0 bytes -100.0% 🗑️
view changes for bundle: sentry-docs-server-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
1729.js -3 bytes 1.63MB -0.0%
../instrumentation.js -3 bytes 957.45kB -0.0%
9523.js -3 bytes 933.5kB -0.0%
../app/[[...path]]/page.js.nft.json -74 bytes 399.53kB -0.02%
../app/platform-redirect/page.js.nft.json -74 bytes 399.44kB -0.02%
../app/sitemap.xml/route.js.nft.json -74 bytes 397.41kB -0.02%

const char *custom_error = (const char *)hint;
const char *custom_error = (const char *)user_data;
Copy link
Collaborator

@supervacuus supervacuus Jun 11, 2025

Choose a reason for hiding this comment

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

I think this is still confusing, because it characterizes user_data as something that should contribute to error resolution, which is absolutely not what it is used for. user_data is about passing in context from the user, so they can call into their code or retrieve relevant data.

hint and user_data are entirely unrelated. If user_data gets assigned to a hook variable called custom_error, that weakens the clear distinction we should accomplish in the docs.

The Native SDK does not pass exception information into the hint, but instead allows to set a custom hint in SDK options. To detect the exception type, inspect the event instead.
The Native SDK does not pass exception information into the hint, but instead allows to set custom `user_data` in the `before_send` SDK option. To detect the exception type, inspect the event instead.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should note here that the Native SDK's solution to the problem of obtaining additional crash context is the on_crash hook, and that the usage of the before_send hook for handling crashes is deprecated and provided only as a compatibility fallback.

This is particularly confusing because the entire first section of this document clearly addresses this particular issue. I guess that this snippet has only "recently" been added as an included section below as part of a larger refactoring, because otherwise this confusing and contradictory explanation would have been evident in documenting the much later added on_crash hook.

Comment on lines 38 to +41
crash_cleanup(
const sentry_ucontext_t *uctx, // provides the user-space context of the crash
sentry_value_t event, // used the same way as in `before_send`
void *closure // user-data that you can provide at configuration time
void *user_data // user-data that you can provide at configuration time
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not quite sure what kind of cleanup one could do with the data one gets from the uctx and event; @supervacuus do you have any inspiration? I was thinking about using fields from uctx->siginfo to discard specific types of crashes, but maybe you know of something nicer.

Copy link
Collaborator

@supervacuus supervacuus Jun 11, 2025

Choose a reason for hiding this comment

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

Clean-up is the wrong concept for on_crash to convey to users. This is precisely where before_send and on_crash dramatically diverge:

  • the event we get in on_crash is essentially empty for all minidump generating backends
  • inproc is the only backend that passes complete event data to either hook
  • so, if you aren't using inproc, the event parameter is not a proper clean-up or filter discriminator
  • the event can, up to a certain point, be enriched inside the on_crash hook as the last client interaction before the crashed application terminates
  • in the same vein, it can be used to act at all before the crashed application terminates
  • while the ucontext can provide a rich source of metadata, which can find its way back into the event or as a filter mechanism, the interactions would have to be very specific to a particular use case, and describing those might lead to more confusion than insight
  • it is enormously rare, for any minidump generating backend to remove any events, solely by looking at the ucontext, since the biggest source of meta-data is the snapshot collection for the minidump which is currently not accessible in the client (and if we would make it accessible we probably wouldn't go indirectly via minidump)

Having said all that, a concrete example from the field was from a user who reported C++ exceptions via a std::terminate handler that would capture a manual exception event and didn't want the resulting crash of an unhandled C++ exception to generate an additional error report. To prevent sending C++ exceptions on Windows, I provided an on_crash approach for this particular scenario: getsentry/sentry-native#860 (comment). However, I question whether this approach falls into the "nice" category.

Copy link
Collaborator

@supervacuus supervacuus left a comment

Choose a reason for hiding this comment

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

I'm happy to remove the hint, however, since we do not eliminate the "hint" concept in our API, we should explain in the remaining code why we ignore it.

/* modify event here or return NULL to discard the event */
(void)hint;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this would be a sensible location to specify that hint is currently not expected to contain any data, and maybe to repeat that users who want more crash context should use the on_crash hook.

Comment on lines 38 to +41
crash_cleanup(
const sentry_ucontext_t *uctx, // provides the user-space context of the crash
sentry_value_t event, // used the same way as in `before_send`
void *closure // user-data that you can provide at configuration time
void *user_data // user-data that you can provide at configuration time
Copy link
Collaborator

@supervacuus supervacuus Jun 11, 2025

Choose a reason for hiding this comment

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

Clean-up is the wrong concept for on_crash to convey to users. This is precisely where before_send and on_crash dramatically diverge:

  • the event we get in on_crash is essentially empty for all minidump generating backends
  • inproc is the only backend that passes complete event data to either hook
  • so, if you aren't using inproc, the event parameter is not a proper clean-up or filter discriminator
  • the event can, up to a certain point, be enriched inside the on_crash hook as the last client interaction before the crashed application terminates
  • in the same vein, it can be used to act at all before the crashed application terminates
  • while the ucontext can provide a rich source of metadata, which can find its way back into the event or as a filter mechanism, the interactions would have to be very specific to a particular use case, and describing those might lead to more confusion than insight
  • it is enormously rare, for any minidump generating backend to remove any events, solely by looking at the ucontext, since the biggest source of meta-data is the snapshot collection for the minidump which is currently not accessible in the client (and if we would make it accessible we probably wouldn't go indirectly via minidump)

Having said all that, a concrete example from the field was from a user who reported C++ exceptions via a std::terminate handler that would capture a manual exception event and didn't want the resulting crash of an unhandled C++ exception to generate an additional error report. To prevent sending C++ exceptions on Windows, I provided an on_crash approach for this particular scenario: getsentry/sentry-native#860 (comment). However, I question whether this approach falls into the "nice" category.

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.

before_send hint is ignored + docs are wrong
2 participants