sentry-react-native / core
AGENTS.md1.8k starsChanged 3 months agoMITView on GitHub
Depth lives in the skills. The code-guidelines and test-guidelines skills (.agents/skills/) hold the authoritative, current guidance on code style, API/integration design, the bridge, and tests — load them before non-trivial work. This file covers the package's build/test commands, quick-reference conventions, and the TurboModule subsystem, which is documented nowhere else. Where a convention here overlaps a skill, the skill wins. Use describe/it blocks (preferred) or flat test() calls: Arrange-Act-Assert pattern — always structure tests with clear sections. Use specific Jest matchers:
Trending
Quiet this year.thin dataabout the whole repository
Who's talking about getsentry/sentry-react-native
- bluesky-social/social-app“Make Sentry optional”GitHub · Sep 8, 2023 · 21 reactions
- expo/sentry-expo“Critical Security - Upgrade @sentry/react-native to 1.3.9”GitHub · May 21, 2020 · 15 reactions
- expo/expo“[SDK 51] Xcode 16 compilation fails on pegged Sentry version”GitHub · Jul 2, 2024 · 14 reactions
- react/react-native“[0.60.3] --sourcemap-output | enableHermes: false | gradle file | wrong output path”GitHub · Jul 17, 2019 · 10 reactions
- expo/expo“[expo] Bump recommended @sentry/react-native version”GitHub · Sep 25, 2024 · 8 reactions
The biggest 5 of 9 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 9
Talked about on GitHub (9 times).
On GitHub · 9
- Sep 8, 2023Make Sentry optional — bluesky-social/social-app21 reactions
- May 21, 2020Critical Security - Upgrade @sentry/react-native to 1.3.9 — expo/sentry-expo15 reactions · 28 comments
- Jul 2, 2024[SDK 51] Xcode 16 compilation fails on pegged Sentry version — expo/expo14 reactions · 12 comments
- Jul 17, 2019[0.60.3] --sourcemap-output | enableHermes: false | gradle file | wrong output path — react/react-native10 reactions · 8 comments
- Sep 25, 2024[expo] Bump recommended @sentry/react-native version — expo/expo8 reactions · 1 comment
4 more on GitHub
- Jul 19, 2024Update sessions after running beforeSend — getsentry/sentry-cocoa7 reactions · 6 comments
- Jun 22, 2022Bundling React Native with Hermes manually — react/react-native7 reactions · 24 comments
- Nov 6, 2019Implement hermes source maps — getsentry/rust-sourcemap7 reactions · 2 comments
- May 30, 2023Upgrade `@sentry/react-native` to version `5` — expo/sentry-expo6 reactions · 6 comments
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository12 other files it gives its agents.
- AGENTS.mdAGENTS.md
- packages/core/android/AGENTS.mdAGENTS.md
- packages/core/ios/AGENTS.mdAGENTS.md
- samples/expo/AGENTS.mdAGENTS.md
- samples/react-native/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- code-guidelinesSkill
- design-firstSkill
- diagnosing-bugsSkill
- reviewSkill
- specSkill
- test-guidelinesSkill
The file
We split this AGENTS.md into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 19
Use optional chaining (?.) and nullish coalescing (??)
- Distinctive: line 27
Use TypeScript strict mode conventions
- Very specific: line 28
Prefer interface over type for object shapes
- Very specific: line 29
Use unknown instead of any when possible
- Very specific: line 52
Use describe/it blocks (preferred) or flat test() calls:
- Distinctive: line 206
A method with no completion signal is recorded as ~0ms: Only a plain return and a thenable return are recognised.
- Very specific: line 256
Do not add new keys under either prefix until that lands — conventions must be merged *before* an SDK ships an attribute, and renaming a …
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
packages/core — TypeScript/JavaScript SDK
Depth lives in the skills. The
code-guidelinesandtest-guidelinesskills (.agents/skills/) hold the authoritative, current guidance on code style, API/integration design, the bridge, and tests — load them before non-trivial work. This file covers the package's build/test commands, quick-reference conventions, and the TurboModule subsystem, which is documented nowhere else. Where a convention here overlaps a skill, the skill wins.
Build & Test
yarn build:sdk:watch # Watch mode for development
yarn test:watch # Jest watch mode
yarn test:sdk # SDK tests only
yarn test:tools # Tools tests onlyCode Style
- Single quotes for strings
- Arrow functions preferred for callbacks
- async/await is allowed (React Native bundle size isn't a concern)
- Use optional chaining (
?.) and nullish coalescing (??) - Maximum line length: 120 characters
- Trailing commas: always
- Arrow parens: avoid when possible (
x => xnot(x) => x)
Type Annotations
- Explicitly type function parameters and return types
- Use TypeScript strict mode conventions
- Prefer
interfaceovertypefor object shapes - Use
unknowninstead ofanywhen possible
interface UserData {
id: string;
name: string;
email?: string;
}
const processUser = (user: UserData): string => {
return user.email ?? 'no-email@example.com';
};Import Ordering
- External packages (e.g.,
@sentry/core,react-native) - Internal absolute imports
- Relative imports
- Type imports (can be inline with
import type)
Test Naming Convention
Use describe/it blocks (preferred) or flat test() calls:
describe('functionName', () => {
it('returns expected value when input is valid', () => {
// Arrange
const input = 'test';
// Act
const result = functionName(input);
// Assert
expect(result).toBe('expected');
});
});Test Code Style
Arrange-Act-Assert pattern — always structure tests with clear sections.
Use specific Jest matchers:
// Good
expect(value).toBe(true);
expect(array).toHaveLength(3);
expect(object).toMatchObject({ key: 'value' });
expect(fn).toThrow(Error);
expect(promise).resolves.toBe('success');
// Avoid
expect(value === true).toBe(true);
expect(array.length).toBe(3);Mock cleanup:
describe('MyComponent', () => {
afterEach(() => {
jest.clearAllMocks();
});
});Common Patterns
Diagnostics use
debugfrom@sentry/core, notlogger—loggeris the Logs API and emits log events (and recurses in the bridge hot path). See TurboModule Instrumentation below.
Error Handling
import { debug } from '@sentry/core';
try {
const result = await riskyOperation();
return result;
} catch (error) {
debug.error('Operation failed', error);
// Don't throw - log and return fallback
return fallbackValue;
}Native Bridge (JS side)
import { NativeModules } from 'react-native';
const { RNSentry } = NativeModules;
export async function nativeOperation(param: string): Promise<boolean> {
if (!RNSentry) {
debug.warn('Native module not available');
return false;
}
try {
return await RNSentry.nativeOperation(param);
} catch (error) {
debug.error('Native operation failed', error);
return false;
}
}Platform-Specific Code
import { Platform } from 'react-native';
const platformSpecificValue = Platform.select({
ios: 'iOS value',
android: 'Android value',
default: 'Default value',
});Mocking Native Modules in Tests
jest.mock('react-native', () => ({
NativeModules: {
RNSentry: {
nativeOperation: jest.fn(() => Promise.resolve(true)),
},
},
Platform: {
OS: 'ios',
},
}));TurboModule Instrumentation
There are two independent stacks with confusingly similar names. Read this before touching either.
1. JS stack — live, on by default
Wraps native module methods in JS. This is what produces every user-visible
TurboModule signal today. Registered in integrations/default.ts whenever
options.enableNative is true, with no separate opt-in.
Data flow, in call order:
| File | Role |
turbomodule/wrapTurboModule.ts | wrapTurboModule(name, module, { skip, arch }) — replaces each method with a timing wrapper. De-dupes via a module-level WeakSet. Walks the prototype chain (Object.getPrototypeOf) because JSI HostObject proxies expose nothing as own properties. |
turbomodule/turboModuleTracker.ts | LIFO stack of in-flight calls, mirrored onto the isolation scope (that is what enableSyncToNative forwards to native). This is the crash-attribution frame. Writes contexts.turbo_module plus the turbo_module.name / turbo_module.method tags. |
turbomodule/turboModuleAggregator.ts | O(1) counters per (module, method, kind, arch) plus a fixed-bucket latency histogram (HISTOGRAM_BUCKETS_MS). Fans out to record/call-start observers. |
turbomodule/wrapNativeModules.ts | Old Architecture NativeModules.* auto-wrap. Returns [] immediately when isTurboModuleEnabled(). Opt-in via enableLegacyNativeModules. |
integrations/turboModuleContext.ts | Wiring: integration name is 'TurboModuleContext', factory is turboModuleContextIntegration(). Owns TurboModuleContextOptions and all defaults. |
integrations/turboModuleContextFlush.ts | Drains the aggregate onto transaction events (child span + measurements) and onto a periodic standalone event. |
Gotchas, all of which have already caused bugs:
- Never wrap the scope-sync methods on
RNSentry.RNSENTRY_SKIPinturboModuleContext.tsexcludessetTag,setContext,addBreadcrumb,setUserand friends. Wrapping them recurses: recording a call syncs the scope, which calls back into the wrapped method. RNSentryis in the defaultignoreTurboModulesfor the same reason — the SDK's own transport calls would dominate the aggregate and re-arm the periodic flush timer forever.loggerimported from@sentry/coreis the Logs API, not the debug logger.@sentry/coreexportsloggeras./logs/public-apiand the debug logger asdebug. The 7logger.warncalls inwrapTurboModule.tsand 2 inwrapNativeModules.tstherefore capture log events from the wrap hot path, recursing through the wrappedRNSentry.captureEnvelope. Usedebugin new code here; the pre-existing calls are a known bug.- Crash attribution pops synchronously, even for async calls. Holding the frame until completion that may never arrive would blame this module for an unrelated later native crash.
- A method with no completion signal is recorded as ~0ms. Only a plain
return and a thenable return are recognised. Fire-and-forget bridge methods
that report completion through a trailing callback return
undefined, so they close on return and land in the aggregate as sync calls with a near-zero duration. Tracked in #6542.
Tests: test/turbomodule/*.test.ts and test/integrations/turboModuleContext.test.ts.
2. Native stack — installed, inert
Gated by the enableTurboModuleTracking option (src/js/options.ts).
cpp/SentryTurboModulePerfLogger.{h,cpp}— afacebook::react::NativeModulePerfLoggersubclass that claims React Native's perf-logger slot and forwards every callback to a swappable sink.cpp/SentryTurboModulePerfSink.h— theISentryTurboModulePerfSinkinterface.- Install points:
ios/RNSentry.mm,android/.../RNSentryModuleImpl.java,android/src/main/jni/OnLoad.cpp.
The SDK ships no production sink.
SentryTurboModulePerfController::setSink is only ever called from
RNSentryCocoaTester/.../RNSentryTurboModulePerfControllerTests.mm, so
enableTurboModuleTracking: true currently forwards every callback into
nullptr and emits nothing. The option is @internal for that reason.
The two stacks do not talk to each other. turboModuleContextIntegration
never reads enableTurboModuleTracking, and nothing in JS consumes the native
perf-logger callbacks. If you are adding a consumer, register a sink — do not
route it through the JS wrapper.
Emitted keys
Two namespaces, which is a known inconsistency:
turbo_module.*— scope context, event tags, root-span attributes (turboModuleContext.ts).turbo_modules.*— aggregate child-span data and measurements (turboModuleContextFlush.ts), plus the span opturbo_modules.aggregateand originauto.tracing.turbo_modules.
Per-(module, method) keys embed the dynamic segment in the middle
(turbo_module.<name>.<method>.call_count). safeKeyPart escapes _ to __
then . to _ so a module name cannot forge a key boundary.
Both the namespace split and the mid-key dynamic segment are not registrable
in sentry-conventions,
whose schema only models a trailing has_dynamic_suffix. Unifying them is
tracked in #6168.
Do not add new keys under either prefix until that lands — conventions must be
merged before an SDK ships an attribute, and renaming a shipped name costs a
90-day backfill deprecation cycle.
Old Architecture support policy
The legacy NativeModules path (enableLegacyNativeModules) is opt-in and
best-effort, and stays that way while React Native still ships the Old
Architecture. It is not deprecated and has no removal timeline. Unlike the New
Architecture path, which only sees modules the app actually imports, it
instruments every registered bridge module including third-party ones — hence
the opt-in and the IMPLICIT_MODULE_SKIP list in wrapNativeModules.ts
(RNSentry, Timing, UIManager, and the animated modules).
Privacy
Native module and method names are app-defined identifiers and are sent by
default — in tags, in contexts.turbo_module, in span attributes and in slow
call breadcrumbs — regardless of sendDefaultPii. This is deliberate: the
crash-attribution frame is the reason the integration is default-on. Users who
need to reduce it can pass ignoreTurboModules, or disable
enableAggregateStats / enableSpanAttribution.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

