Skip to content

fix(core): [Callback Errors 1] Report callback failures - #6141

Open
adinauer wants to merge 1 commit into
fix/callback-error-handlingfrom
fix/callback-error-handling-discard-reason
Open

adinauer wants to merge 1 commit into
fix/callback-error-handlingfrom
fix/callback-error-handling-discard-reason

Conversation

@adinauer

@adinauer adinauer commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

PR Stack (Callback Errors)


📜 Description

Adds DiscardReason.CALLBACK_ERROR and uses it when an existing beforeSend* callback throws and drops telemetry. Intentional null returns continue to use before_send.

The change preserves transaction/root-span and log/metric byte accounting, and exposes the new reason through OnDiscardCallback.

💡 Motivation and Context

Callback failures and intentional filtering currently share the same discard reason. Distinguishing them makes client reports and local discard observers accurately describe why telemetry was dropped.

💚 How did you test it?

  • ./gradlew spotlessApply apiDump
  • ./gradlew :sentry:test --tests io.sentry.SentryClientTest --tests io.sentry.clientreport.ClientReportTest
  • ./gradlew :sentry:apiCheck

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

The next stack PR (#6162) marks SDK-owned event processors, followed by event processor exception handling in #6142.

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

Add the callback_error discard reason and use it when a beforeSend callback throws. Preserve before_send for callbacks that intentionally return null and retain item, span, and byte accounting.

Refs #6081
Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor
Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Fixes

- [Callback Errors 1] Report callback failures ([#6141](https://github.com/getsentry/sentry-java/pull/6141))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 28af8f2

@sentry

sentry Bot commented Sep 22, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.57.0 (1) release

⚙️ sentry-android Build Distribution Settings

@adinauer adinauer mentioned this pull request Sep 22, 2026
9 tasks
@adinauer
adinauer marked this pull request as ready for review September 23, 2026 08:50

@runningcode runningcode left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should check if/how we should be logging these failures against the spec.

The spec should also clarify if non-recoverable errors should be swallowed. I don't think non-recoverable errors should be swallowed since they aren't recoverable and make it harder for customers to debug real issues.

final int spanCountAfterCallback = transaction.getSpans().size();
if (spanCountAfterCallback < spanCountBeforeCallback) {
final int droppedSpanCount = spanCountBeforeCallback - spanCountAfterCallback;
options

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know if I'm understanding the spec correctly. I see different interpretations available.

It says On failure, SDKs **MUST** emit an error-level internal log together with failure **MUST NOT** produce a billed event of any type.

Its unclear what "internal log" exactly means but isn't calling log a billable event?

Aside from being a billable event, it can also lead to failures because we have a BeforeSendLogCallback.

This branch has not been deployed

No deployments
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.

2 participants