Skip to content

feat: Add before_send_transaction #1236

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

Merged
merged 7 commits into from
May 15, 2025

Conversation

JoshuaMoelans
Copy link
Member

@JoshuaMoelans JoshuaMoelans commented May 13, 2025

Fixes #1214 (and related to #864 (comment))

ToDo

questions (resolved)

  • Why do we have invoke_before_send passed into prepare_event (see code), and why is it true for sentry_core occurrences (1, 2), but passed as !options->on_crash_func for breakpad?

    For crashes, we only before_send if there is no on_crash hook.

  • Where do we callback? Before or after applying scope?

    As late as possible, to give the user maximal context.

  • (void* hint) parameter (which is unused for the other callbacks, but exists afaict), see here

    Not relevant for before_send_transaction.

  • Do we want to add before_transaction_data to modify transactions before sending? see here

    Yes.

Copy link

github-actions bot commented May 13, 2025

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

Generated by 🚫 dangerJS against bdc89fe

@supervacuus
Copy link
Collaborator

Why do we have invoke_before_send passed into prepare_event (see code), and why is it true for sentry_core occurrences (1, 2), but passed as !options->on_crash_func for breakpad?

Because this function is used for regular event capture, and during the capture of crashes from the handler. We want to invoke the before_send hook with regular events, because that is what we use it for. For crashes, we only run the before_send hook if no on_crash hook has been defined. This is documented in the respective hook docs.

Where do we callback? Before or after applying scope?

As late as possible: after applying the scope. What would your argument be against that?

(void* hint) parameter (which is unused for the other callbacks, but exists afaict), see here

The hint parameter isn't really applicable to the Native SDK, but we could pass in the ucontext or exception_ptrs if it is used in the crash context as we do for the on_crash hook (but in an untyped fashion). I don't think it is relevant to the before_send_transaction.

Do we want to add before_transaction_data to modify transactions before sending? see here

I think so, but similar to the concrete place of calling the callback I would compare with other SDKs.

@JoshuaMoelans JoshuaMoelans marked this pull request as ready for review May 14, 2025 16:08
@JoshuaMoelans JoshuaMoelans requested a review from supervacuus May 14, 2025 16:08
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.

Looks great. Just wonder about the parameter naming and whether we should use the PR to make its use consistent.

JoshuaMoelans added a commit to getsentry/sentry-docs that referenced this pull request May 15, 2025
<!-- Use this checklist to make sure your PR is ready for merge. You may
delete any sections you don't need. -->

## DESCRIBE YOUR PR
Part of getsentry/sentry-native#1236


## 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.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [x] None: Not urgent, can wait up to 1 week+
@JoshuaMoelans JoshuaMoelans merged commit 5224a83 into master May 15, 2025
37 checks passed
@JoshuaMoelans JoshuaMoelans deleted the joshua/feat/before_send_transaction branch May 15, 2025 10:26
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.

Prevent sending running Transactions/Spans if app has been put to sleep
2 participants