-
-
Notifications
You must be signed in to change notification settings - Fork 361
feat(core): Extend TurboModule instrumentation to legacy NativeModules #6504
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
Open
alwx
wants to merge
2
commits into
main
Choose a base branch
from
alwx/features/6166
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,10 @@ import { | |
| setOnFirstTurboModuleRecord, | ||
| type TurboModuleCallStart, | ||
| type TurboModuleRecord, | ||
| wrapAllNativeModules, | ||
| wrapTurboModule, | ||
| } from '../turbomodule'; | ||
| import { isTurboModuleEnabled } from '../utils/environment'; | ||
| import { isRootSpan } from '../utils/span'; | ||
| import { getRNSentryModule } from '../wrapper'; | ||
| import { | ||
|
|
@@ -71,6 +73,24 @@ export interface TurboModuleContextOptions { | |
|
|
||
| /** Cap on per-`(module, method)` rows attributed to a single span. Default: `16`. */ | ||
| maxTopModulesPerSpan?: number; | ||
|
|
||
| /** | ||
| * On Old Architecture, auto-wrap registered `NativeModules.*`. Default: `true`. | ||
|
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. q: Is there any risk in defaulting to |
||
| * | ||
| * Lazily-exposed modules stay lazy β they are wrapped on first access rather than | ||
| * initialised during `Sentry.init`. | ||
| */ | ||
| enableLegacyNativeModules?: boolean; | ||
|
|
||
| /** | ||
| * Additional modules to skip in the legacy auto-wrap. `RNSentry` and hot React | ||
| * Native infrastructure (`Timing`, `UIManager`, and the animated modules) are | ||
| * always skipped; pass them via `modules` to instrument them deliberately. | ||
| */ | ||
| legacyModulesSkip?: ReadonlyArray<string>; | ||
|
|
||
| /** Per-module method skips for the legacy auto-wrap. */ | ||
| legacyModulesSkipMethods?: Readonly<Record<string, ReadonlyArray<string>>>; | ||
| } | ||
|
|
||
| // Scope-sync methods must NOT be tracked β `enableSyncToNative` calls them on | ||
|
|
@@ -101,6 +121,7 @@ export const turboModuleContextIntegration = (options: TurboModuleContextOptions | |
| const flushIntervalMs = options.aggregateFlushIntervalMs ?? DEFAULT_AGGREGATE_FLUSH_INTERVAL_MS; | ||
| const slowCallThresholdMs = options.slowCallThresholdMs ?? DEFAULT_SLOW_CALL_THRESHOLD_MS; | ||
| const maxTopModulesPerSpan = options.maxTopModulesPerSpan ?? DEFAULT_MAX_TOP_MODULES_PER_SPAN; | ||
| const contextArch: 'new' | 'legacy' = isTurboModuleEnabled() ? 'new' : 'legacy'; | ||
|
|
||
| let pendingFlushHandle: ReturnType<typeof setTimeout> | undefined; | ||
| let closed = false; | ||
|
|
@@ -120,10 +141,19 @@ export const turboModuleContextIntegration = (options: TurboModuleContextOptions | |
| return { | ||
| name: INTEGRATION_NAME, | ||
| setupOnce() { | ||
| wrapTurboModule('RNSentry', getRNSentryModule(), { skip: RNSENTRY_SKIP }); | ||
| // Wrap RNSentry first with its curated skip list; `wrapAllNativeModules` | ||
| // then skips it implicitly to avoid double-wrapping with a wider surface. | ||
| wrapTurboModule('RNSentry', getRNSentryModule(), { skip: RNSENTRY_SKIP, arch: contextArch }); | ||
|
|
||
| for (const entry of options.modules ?? []) { | ||
| wrapTurboModule(entry.name, entry.module, { skip: entry.skipMethods }); | ||
| wrapTurboModule(entry.name, entry.module, { skip: entry.skipMethods, arch: contextArch }); | ||
| } | ||
|
|
||
| if (options.enableLegacyNativeModules !== false) { | ||
| wrapAllNativeModules({ | ||
| skipModules: options.legacyModulesSkip, | ||
| skipMethodsPerModule: options.legacyModulesSkipMethods, | ||
| }); | ||
| } | ||
|
|
||
| setAggregateRecordingEnabled(enableAggregate); | ||
|
|
@@ -175,7 +205,7 @@ export const turboModuleContextIntegration = (options: TurboModuleContextOptions | |
| for (const window of windows) { | ||
| recordIntoWindow(window, record); | ||
| if (window.closed) { | ||
| attachWindowToSpan(window.span, window, maxTopModulesPerSpan, pendingSpanAttributes); | ||
| attachWindowToSpan(window.span, window, maxTopModulesPerSpan, contextArch, pendingSpanAttributes); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -229,7 +259,7 @@ export const turboModuleContextIntegration = (options: TurboModuleContextOptions | |
| openWindowList.splice(idx, 1); | ||
| } | ||
| window.closed = true; | ||
| attachWindowToSpan(span, window, maxTopModulesPerSpan, pendingSpanAttributes); | ||
| attachWindowToSpan(span, window, maxTopModulesPerSpan, contextArch, pendingSpanAttributes); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -344,6 +374,7 @@ function attachWindowToSpan( | |
| span: Span, | ||
| window: WindowState, | ||
| topN: number, | ||
| arch: 'new' | 'legacy', | ||
| pendingSpanAttributes: Map<string, Record<string, number | string | undefined>>, | ||
| ): void { | ||
| if (window.counters.size === 0) { | ||
|
|
@@ -369,6 +400,7 @@ function attachWindowToSpan( | |
| 'turbo_module.total_error_count': totalErrorCount, | ||
| 'turbo_module.total_duration_ms': roundMs(totalDurationMs), | ||
| 'turbo_module.unique_methods': rows.length, | ||
| 'turbo_module.arch': arch, | ||
| }; | ||
| const top = rows[0]; | ||
| if (top) { | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would advocate toward shortening this and skipping some of the implementation details