Skip to content

Conversation

@tustanivsky
Copy link
Collaborator

@tustanivsky tustanivsky commented Mar 7, 2025

This PR adds beforeBreadcrumb hook allowing to modify the breadcrumb or decide to discard it entirely by returning nullptr before it's added.

The suggested changes are similar to #318.

beforeBreadcrumb hook won't be called on Android if the underlying SDK creates breadcrumb in a main thread (i.e. during Activity lifecycle callback handling).

Closes #807

Related to getsentry/sentry-native#1166

@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2025

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

Generated by 🚫 dangerJS against 29df7a7

@tustanivsky tustanivsky requested a review from bitsandfoxes March 7, 2025 13:45
{
if (!FTaskTagScope::IsCurrentTag(ETaskTag::EGameThread))
{
// Executing `onBeforeBreadcrumb` handler is not allowed when called from Android main thread.
Copy link
Member

Choose a reason for hiding this comment

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

running on the main thread will be quite common. Why is it not allowed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This causes issues when wrapping Android jobject instances in Unreal since USentryBreadcrumb and USentryHint (both derived from UObject) can only be safely created on the GameThread.

Despite certain breadcrumb types (i.e. Android activity and app lifecycle callbacks) originating from the main thread and lacking pre-processing support they will still be included in captured events.

Copy link
Member

Choose a reason for hiding this comment

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

what's the behavior a user can expect? some crumbs will go through the callback and some won't?
it just seems like a surprising behavior.

"why can't I drop these breadcrumbs through beforeBreadcrumb?"

Should we avoid adding a callback altogether then?
Or how do we avoid surprises/disapointments?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bruno-garcia The original error message I've seen while testing this led me to believe that calling the beforeBreadcrumb hook outside the game thread on Android was the issue but it turned out to be misleading. Similar to beforeSend (#860) the real limitation is that we can't call it during GC otherwise it works as expected.

I've added this limitation to the README and will also ensure it's mentioned in the documentation as @bitsandfoxes suggested.

@tustanivsky tustanivsky requested a review from bruno-garcia April 4, 2025 11:08
@tustanivsky tustanivsky merged commit 63992d9 into main Apr 7, 2025
27 checks passed
@tustanivsky tustanivsky deleted the feat/breadcrumb-hook branch April 7, 2025 06:09
tustanivsky added a commit to getsentry/sentry-docs that referenced this pull request May 5, 2025
This PR introduces the following changes to Unreal SDK docs:
- Added `beforeBreadcrumb` hook description
(getsentry/sentry-unreal#814)
- Added
[notice](getsentry/sentry-unreal#860 (review))
that hooks can't be invoked during garbage collection in Unreal
- Added fast-fail crash capturing to the feature comparison table for
different plugin versions
(getsentry/sentry-unreal#828)
- Added
[notice](getsentry/sentry-unreal#812 (comment))
about `EngineVersion` key in the plugin's descriptor file for GitHub
package
- Added GPU crash dump attachment option
(getsentry/sentry-unreal#712)
bitsandfoxes pushed a commit to getsentry/sentry-docs that referenced this pull request Jul 3, 2025
This PR introduces the following changes to Unreal SDK docs:
- Added `beforeBreadcrumb` hook description
(getsentry/sentry-unreal#814)
- Added
[notice](getsentry/sentry-unreal#860 (review))
that hooks can't be invoked during garbage collection in Unreal
- Added fast-fail crash capturing to the feature comparison table for
different plugin versions
(getsentry/sentry-unreal#828)
- Added
[notice](getsentry/sentry-unreal#812 (comment))
about `EngineVersion` key in the plugin's descriptor file for GitHub
package
- Added GPU crash dump attachment option
(getsentry/sentry-unreal#712)
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.

Add beforeBreadcrumb hook

3 participants