-
-
Notifications
You must be signed in to change notification settings - Fork 358
Turbo Modules crash time context #6227
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f43a4f5
Turbo Modules crash time context
alwx de4c63d
fixes
alwx 1d8f659
Merge branch 'main' into alwx/improvement/turbo-modules-chash-time-coโฆ
alwx 4f68d95
fix(turbomodule): address review feedback
alwx 99eeacb
fix(turbomodule): address remaining PR review feedback
alwx 653dd1d
Merge branch 'main' into alwx/improvement/turbo-modules-chash-time-coโฆ
alwx c8d960b
fix(turbomodule): prevent scope-sync recursion and harden wrapper edges
alwx 4201154
fix(turbomodule): keep native context in sync after cross-scope pop
alwx 9689475
fix(turbomodule): never let instrumentation break user TurboModule calls
alwx 94c0c59
Merge branch 'main' into alwx/improvement/turbo-modules-chash-time-coโฆ
alwx 5cf66a9
Lint fixes
alwx adb5c97
chore(api-report): regenerate with workspace TypeScript 5.9.3
alwx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import type { Integration } from '@sentry/core'; | ||
|
|
||
| import { wrapTurboModule } from '../turbomodule'; | ||
| import { getRNSentryModule } from '../wrapper'; | ||
|
|
||
| export const INTEGRATION_NAME = 'TurboModuleContext'; | ||
|
|
||
| export interface TurboModuleContextOptions { | ||
| /** | ||
| * Additional TurboModules to track. Each entry's methods will be wrapped so | ||
| * that any native crash happening inside a method call gets `contexts.turbo_module` | ||
| * + `turbo_module.name` / `turbo_module.method` attached to the crash report. | ||
| * | ||
| * The built-in `RNSentry` TurboModule is always tracked. | ||
| */ | ||
| modules?: Array<{ name: string; module: object | null | undefined; skipMethods?: ReadonlyArray<string> }>; | ||
| } | ||
|
|
||
| // Methods on RNSentry that must NOT be tracked: | ||
| // | ||
| // - `addListener` / `removeListeners` are RN event-emitter stubs that fire on | ||
| // every subscriber registration โ tracking them would just churn the scope. | ||
| // | ||
| // - The scope-sync methods (`setContext`, `setTag`, `setExtra`, `setUser`, | ||
| // `addBreadcrumb`, `clearBreadcrumbs`, `setAttribute`, `setAttributes`, | ||
| // `removeAttribute`) are called by our own `enableSyncToNative` hook every | ||
| // time anything writes to a JS Scope. Tracking them would cause infinite | ||
| // recursion: `pushTurboModuleCall` -> `scope.setContext` -> `NATIVE.setContext` | ||
| // -> `RNSentry.setContext` (wrapped) -> `pushTurboModuleCall` -> ... . | ||
| const RNSENTRY_SKIP = [ | ||
| 'addListener', | ||
| 'removeListeners', | ||
| 'setContext', | ||
| 'setTag', | ||
| 'setExtra', | ||
| 'setUser', | ||
| 'addBreadcrumb', | ||
| 'clearBreadcrumbs', | ||
| 'setAttribute', | ||
| 'setAttributes', | ||
| 'removeAttribute', | ||
| ] as const; | ||
|
|
||
| /** | ||
|
alwx marked this conversation as resolved.
|
||
| * Attaches the currently-executing TurboModule method to the Sentry scope so | ||
| * that native crashes can be attributed to the high-level RN module + method | ||
| * (e.g. `RNSentry.captureEnvelope`) on top of the native stack trace. | ||
| * | ||
| * The active call is mirrored as `contexts.turbo_module` and the | ||
| * `turbo_module.name` / `turbo_module.method` tags, both of which are already | ||
| * synced to the native SDKs by the existing scope-sync hooks and therefore end | ||
| * up in crash reports captured by sentry-cocoa / sentry-java. | ||
| * | ||
| * See https://github.com/getsentry/sentry-react-native/issues/6163. | ||
| */ | ||
| export const turboModuleContextIntegration = (options: TurboModuleContextOptions = {}): Integration => { | ||
| return { | ||
| name: INTEGRATION_NAME, | ||
| setupOnce() { | ||
| // Wrap the live RNSentry TurboModule. Other integrations import the same | ||
| // instance by reference, so wrapping here transparently tracks every call | ||
| // made from JS โ including the SDK's own internal envelope/scope sync | ||
| // calls, which are the most likely entry points for native crashes. | ||
| wrapTurboModule('RNSentry', getRNSentryModule(), { skip: RNSENTRY_SKIP }); | ||
|
sentry[bot] marked this conversation as resolved.
|
||
|
|
||
| for (const entry of options.modules ?? []) { | ||
| wrapTurboModule(entry.name, entry.module, { skip: entry.skipMethods }); | ||
| } | ||
| }, | ||
| }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| export { | ||
| getActiveTurboModuleCall, | ||
| getTurboModuleCallStack, | ||
| popTurboModuleCall, | ||
| pushTurboModuleCall, | ||
| } from './turboModuleTracker'; | ||
| export type { TurboModuleCall } from './turboModuleTracker'; | ||
| export { wrapTurboModule } from './wrapTurboModule'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.