Skip to content

feat(core): Capture events with breadcrumbs for severe long tasks - #7147

Draft
alwx wants to merge 3 commits into
alwx/feature/7074from
alwx/feature/7076
Draft

alwx wants to merge 3 commits into
alwx/feature/7074from
alwx/feature/7076

Conversation

@alwx

@alwx alwx commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Adds the captureThresholdMs option to longTaskIntegration. For each long task of at least this duration, the SDK captures a warning event JS thread blocked with the breadcrumbs up to the end of the task, for example Redux actions, HTTP requests and navigation. The option is off by default, and an app launch captures at most 10 of these events.

The events have no stack, so Sentry groups them by the route at the start of the task (fingerprint: ['long-task', route], contexts.app.view_names). The duration is in contexts.long_task.duration_ms. React Native can deliver the entry long after the task ends, so the event timestamp is the task end, and processEvent drops the breadcrumbs after it. The task end is converted relative to now on the Date.now() clock that breadcrumbs use, so it does not depend on performance.timeOrigin.

💡 Motivation and Context

A long task tells you that the JS thread was blocked, but not what led to it. Customers keep their own ring buffer next to the SDK to get this timeline, and the SDK already records most of it as breadcrumbs. Closes #7076.

This PR is based on #7119, which adds the route history.

💚 How did you test it?

Unit tests cover the threshold, the breadcrumb window, the route fingerprint, the limit of 10 events, and events with metrics disabled or below minDurationMs. The breadcrumb test fails without the filter. yarn build, yarn test, yarn lint and yarn circularDepCheck pass. The sample app turns the option on. I have not tested it on a device yet.

📝 Checklist

  • I added tests to verify 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.
  • All tests passing.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.
  • No breaking changes.

🔮 Next steps

Test on a device. Agree on the option name, the limit of 10 events and the fingerprint. Check if the default maxBreadcrumbs (100) keeps enough history in apps that dispatch many Redux actions. Change the base to main after #7119 merges.

alwx added 3 commits November 30, 2026 11:26
The react_native.long_task.duration metric had only sentry.origin, so long tasks could not be broken down by where they happened. Each metric now has the route (route), the foreground state (app.in_foreground), the app start phase (app.start_phase: app_start or steady_state) and the name and op of the root span (sentry.segment.name, sentry.op).

React Native delivers long task entries to the observer callback with idle priority, which can run up to 5 minutes after the task when the JS thread is busy. The context at callback time can then belong to a later screen. So the integration keeps a short history of route changes, app state changes and root spans, and reads the values at the start time of each task. The long tasks that a transaction reads with takeRecords() before the observer delivers them go through the same path, so they get the same context. The tracing integration and the app start code emit the new currentRouteChange and appStartEnd client hooks for this.

The app start end comes from Sentry.wrap, ReactNativeProfiler or appLoaded(). Tasks wait for it, so the long tasks of the app start get the phase too. If the app records no app start end within 30 seconds, the waiting tasks are reported without the phase. The oldest task is reported without the phase when more than 50 tasks wait, and the client close reports the waiting tasks. The root span op is used instead of the op of the active leaf span, because the leaf span at the task start is not known and its op has more values.
Adds the captureThresholdMs option to longTaskIntegration. For each long task that reaches the threshold, the SDK captures a warning event with the breadcrumbs up to the end of the task, so users can see the Redux actions, requests and navigation that led to the block without their own ring buffer.

The events are off by default and an app launch captures at most 10 of them. Sentry groups them by the route at the start of the task, because they have no stack. The route history moves out of the metric reporter, so events work also with metrics disabled.

The task end is converted on the Date.now() clock that breadcrumbs use, relative to now, so the window does not depend on performance.timeOrigin. processEvent drops the breadcrumbs after the task, because React Native can deliver the entry long after the task ends.
Replaces the placeholder in the CHANGELOG entry for captureThresholdMs with the number of the opened PR (#7147).
@github-actions

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

⚪ None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • feat(core): Capture events with breadcrumbs for severe long tasks by alwx in #7147
  • feat(core): Add the task context to the long task metric by alwx in #7119
  • chore(deps): bump getsentry/github-workflows/danger from bce11fe6eaa86dbb9d360ab45a96e659828877f0 to edc87d6f133ac6204e22dee5123167a5eff3ed79 by dependabot in #7137
  • chore(deps): bump ruby/setup-ruby from 1.342.0 to 1.345.0 by dependabot in #7136
  • chore(deps): bump getsentry/craft from 3.13.0 to 3.14.1 by dependabot in #7135
  • chore(deps): bump getsentry/craft/.github/workflows/changelog-preview.yml from 3.13.0 to 3.14.1 by dependabot in #7134
  • chore(deps): bump the codeql-action group with 3 updates by dependabot in #7133
  • chore(deps): update Sentry Android Gradle Plugin to v6.28.0 by github-actions in #7129
  • feat(tracing): Report long tasks as ui.long-task spans in transactions by alwx in #7110
  • chore(deps): update Maestro to v2.13.0 by github-actions in #7126
  • chore(tooling): Make the verify-pr gate stop at the first no by antonis and claude with sentry-junior in #7125
  • chore(tooling): Add review checks and a gate-only mode to verify-pr by antonis and claude in #7121
  • chore(tooling): Fold the open-PR run findings into verify-pr by antonis and claude in #7115

🤖 This preview updates automatically when you update the PR.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor
Fails
🚫 Pull request is not ready for merge, please add the "ready-to-merge" label to the pull request
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 3e0c33f

@alwx
alwx force-pushed the alwx/feature/7074 branch from 2c747f8 to c6d842e Compare December 1, 2026 09:52
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