-
-
Notifications
You must be signed in to change notification settings - Fork 358
WIP: 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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ | |
| spotlightIntegration, | ||
| stallTrackingIntegration, | ||
| timeToDisplayIntegration, | ||
| turboModuleContextIntegration, | ||
|
Check warning on line 44 in packages/core/src/js/integrations/default.ts
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. popTurboModuleCall clears scope that still has active calls when scopes interleave In Evidence
Also found at 3 additional locations
Identified by Warden code-review · AEP-X5X |
||
| userInteractionIntegration, | ||
| viewHierarchyIntegration, | ||
| } from './exports'; | ||
|
|
@@ -174,5 +175,10 @@ | |
|
|
||
| integrations.push(primitiveTagIntegration()); | ||
|
|
||
| if (options.enableNative) { | ||
| // Attribute native crashes to the active TurboModule method (see #6163). | ||
| integrations.push(turboModuleContextIntegration()); | ||
| } | ||
|
|
||
| return integrations; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| 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> }>; | ||
| } | ||
|
|
||
| // `addListener` / `removeListeners` are RN event-emitter stubs that fire on | ||
| // every subscriber registration — tracking them would just churn the scope. | ||
| const RNSENTRY_SKIP = ['addListener', 'removeListeners'] as const; | ||
|
|
||
| /** | ||
| * 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 }); | ||
|
|
||
| for (const entry of options.modules ?? []) { | ||
| wrapTurboModule(entry.name, entry.module, { skip: entry.skipMethods }); | ||
| } | ||
| }, | ||
| }; | ||
| }; |
| 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'; |
Uh oh!
There was an error while loading. Please reload this page.