Skip to content

fix(apollo): Set span status to cancelled on CancellationException - #6284

Draft
lbloder wants to merge 2 commits into
9.x.xfrom
fix/apollo-cancelled-span-status
Draft

lbloder wants to merge 2 commits into
9.x.xfrom
fix/apollo-cancelled-span-status

Conversation

@lbloder

@lbloder lbloder commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

📜 Description

The Apollo 3, 4, and 5 HTTP interceptors now set the span status to CANCELLED when request execution throws a CancellationException, instead of INTERNAL_ERROR.

The exception is still attached to the span and rethrown unchanged, so coroutine cancellation semantics are unaffected. ApolloHttpException and other failures keep their existing status mapping.

Notes for reviewers:

  • TimeoutCancellationException (from withTimeout) is a CancellationException subclass and therefore also maps to CANCELLED. No other HTTP integration in the SDK distinguishes timeouts; OkHttp, Ktor, and OpenFeign all report INTERNAL_ERROR for failures, and DEADLINE_EXCEEDED is only used for SDK-owned deadlines.
  • The span keeps the throwable, consistent with every other integration. Span.finish only links the throwable to the span context; it does not create an event.
  • Cancellation that Apollo surfaces as a network error (e.g. an IOException("Canceled") wrapped in ApolloNetworkException) still maps to INTERNAL_ERROR. This PR only covers CancellationException.

💡 Motivation and Context

Cancellation is expected control flow, not an internal error.

Follow-up from #6074 (comment)

💚 How did you test it?

  • Added one unit test per integration that calls the interceptor with a chain throwing a specific CancellationException and asserts that the same instance is rethrown and the span status is CANCELLED. The tests failed before the fix with INTERNAL_ERROR.
  • ./gradlew :sentry-apollo-3:check :sentry-apollo-4:check :sentry-apollo-5:check

Added google-truth as a test dependency to sentry-apollo-3 and sentry-apollo-4 for the new tests.

📝 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

Apollo 3, 4, and 5 HTTP interceptors reported coroutine cancellation as
INTERNAL_ERROR. Cancellation is expected control flow, so map it to
CANCELLED. The original exception is still attached to the span and
rethrown unchanged.

Fixes #6193
@linear-code

linear-code Bot commented Oct 19, 2026

Copy link
Copy Markdown

JAVA-757

@sentry

sentry Bot commented Oct 19, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

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