Skip to content

fix(integrations): [Callback Errors 9] Guard custom callbacks - #6167

Draft
adinauer wants to merge 4 commits into
fix/callback-error-handling-profile-accountingfrom
fix/callback-error-handling-custom-callbacks
Draft

adinauer wants to merge 4 commits into
fix/callback-error-handling-profile-accountingfrom
fix/callback-error-handling-custom-callbacks

Conversation

@adinauer

@adinauer adinauer commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

PR Stack (Callback Errors)


📜 Description

Guard the remaining custom capture and span callbacks covered by this change:

  • Android screenshot and view hierarchy: log callback exceptions, skip attachment capture, and retain the error event.
  • OkHttp, OpenFeign, GraphQL (both integration versions), and Ktor: catch beforeSpan exceptions and drop the affected span without disrupting the request or replacing its original exception.
  • Apollo legacy/3/4: change existing exception handlers to drop the span instead of retaining it.

Failed spans still finish, including OkHttp event-listener cleanup. Normal callback return values, intentional drops, and existing catch types remain unchanged. New guards catch Exception; the broader catch-type sweep remains separate. No public API changes.

💡 Motivation and Context

Custom filtering callbacks must not cause requests to fail or allow potentially partially processed telemetry to be sent. Android callbacks decide whether to capture an attachment, so their failure skips that capture rather than dropping the error event.

💚 How did you test it?

  • Verified 18 regression cases fail before the production fix and pass afterward.
  • 454 tests passed across the OkHttp, OpenFeign, GraphQL core/17/22, Ktor, and Apollo legacy/3/4 suites, plus the Android screenshot and view-hierarchy processor suites.
  • Cover response preservation, original request exceptions, partial span mutations, synchronous/asynchronous GraphQL results, logging, span completion, breadcrumbs, and subsequent successful Android captures.
  • Corrected two test-fixture gaps: Ktor was not installing the supplied beforeSpan callback; the screenshot allow-capture test was setting the view-hierarchy callback.
  • ./gradlew spotlessApply apiDump and apiCheck passed; no API files changed.

📝 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

Profile/replay artifact cleanup and remaining scope/feedback callbacks are separate follow-ups. Existing Throwable callback-boundary handling remains deferred to the next major.

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

Skip Android screenshot and view hierarchy capture when their callbacks
throw, while retaining the error event. Drop spans on beforeSpan failures
in OkHttp, OpenFeign, GraphQL, Ktor, and Apollo without disrupting requests
or replacing the original request error.

Preserve normal callback results and existing catch types. Finish failed
spans and retain request cleanup and breadcrumbs.

Add regression coverage for callback failures, partial mutations, original
request errors, asynchronous GraphQL results, and subsequent Android
captures. Correct callback wiring in the Ktor and screenshot test fixtures.

Verify 18 regression cases fail before the fix and pass afterward; all 454
tests in the affected suites pass, along with formatting and API checks.

Refs #6081

Co-Authored-By: Claude <noreply@anthropic.com>
@sentry

sentry Bot commented Sep 25, 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 and others added 3 commits September 25, 2026 07:00
Link the Android capture and integration beforeSpan callback fixes to
Callback Errors 9 (#6167).

Co-Authored-By: Claude <noreply@anthropic.com>
Merge #6166 forward into #6167 without rewriting stack history.
Preserve integration callback guards alongside the updated sampler behavior.

Validate the combined core and OpenTelemetry suites, formatting, and API checks.

Refs #6167
Co-Authored-By: Claude <noreply@anthropic.com>
Record callback_error/span when a throwing beforeSpan callback drops a
sampled span in OkHttp, OpenFeign, GraphQL, Ktor, and Apollo. Use the
pre-callback sampling decision so partial callback mutations do not hide
losses, and leave unsampled spans and intentional null drops uncounted.

Add regression coverage for discard notifications, sampling states, and
intentional drops while preserving request and span completion behavior.

Refs #6167
Co-Authored-By: Claude <noreply@anthropic.com>

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.

1 participant