diff --git a/.changeset/sentry-debug-id-plugin.md b/.changeset/sentry-debug-id-plugin.md new file mode 100644 index 000000000..7e86f04f6 --- /dev/null +++ b/.changeset/sentry-debug-id-plugin.md @@ -0,0 +1,12 @@ +--- +"@callstack/repack": minor +--- + +Add `SentryDebugIdPlugin`, which stamps a Sentry Debug ID into the bundle and +its source map so Sentry can pair a JS stack trace with the source map that +resolves it. This is the Re.Pack counterpart of what `@sentry/react-native` +provides for Metro through `createSentryMetroSerializer`. + +The Debug ID is derived from the bundle content, and the runtime snippet is +copied from `@sentry/bundler-plugin-core`. `HermesBytecodePlugin` now carries +the Debug ID over to the composed source map. diff --git a/packages/repack/src/plugins/HermesBytecodePlugin/utils/composeSourceMaps.ts b/packages/repack/src/plugins/HermesBytecodePlugin/utils/composeSourceMaps.ts index c18c5aaa9..38a8a3788 100644 --- a/packages/repack/src/plugins/HermesBytecodePlugin/utils/composeSourceMaps.ts +++ b/packages/repack/src/plugins/HermesBytecodePlugin/utils/composeSourceMaps.ts @@ -1,6 +1,10 @@ import fs from 'node:fs'; import path from 'node:path'; import execa from 'execa'; +import { + addDebugIdToSourceMap, + getSourceMapDebugId, +} from '../../utils/sourceMapDebugId.js'; /** * {@link composeSourceMaps} options. @@ -33,11 +37,28 @@ export const composeSourceMaps = async ({ const composedSourceMapPath = packagerMapPath + '.composed'; try { + // `compose-source-maps.js` writes a fresh map without the Debug ID, and the packager map is + // removed below, so carry the id over to the composed map. + const debugId = getSourceMapDebugId( + await fs.promises.readFile(packagerMapPath, 'utf-8') + ); + await execa.node( path.join(reactNativePath, 'scripts', 'compose-source-maps.js'), [packagerMapPath, compilerMapPath, '-o', composedSourceMapPath] ); + if (debugId) { + const composedSourceMap = await fs.promises.readFile( + composedSourceMapPath, + 'utf-8' + ); + await fs.promises.writeFile( + composedSourceMapPath, + addDebugIdToSourceMap(composedSourceMap, debugId) + ); + } + // Remove intermediate files await fs.promises.unlink(packagerMapPath); await fs.promises.unlink(compilerMapPath); diff --git a/packages/repack/src/plugins/SentryDebugIdPlugin.ts b/packages/repack/src/plugins/SentryDebugIdPlugin.ts new file mode 100644 index 000000000..4bea05088 --- /dev/null +++ b/packages/repack/src/plugins/SentryDebugIdPlugin.ts @@ -0,0 +1,191 @@ +import { createHash } from 'node:crypto'; +import type { Compiler as RspackCompiler } from '@rspack/core'; +import type { Compiler as WebpackCompiler } from 'webpack'; + +import { addDebugIdToSourceMap } from './utils/sourceMapDebugId.js'; + +/** + * {@link SentryDebugIdPlugin} configuration options. + */ +export interface SentryDebugIdPluginConfig { + /** + * Matches the bundles that should receive a Debug ID. + * + * @default /\.([cm]?jsx?|bundle)$/ + */ + test?: RegExp; +} + +const DEFAULT_TEST = /\.([cm]?jsx?|bundle)$/; + +const PLUGIN_NAME = 'RepackSentryDebugIdPlugin'; + +/** + * Creates the snippet that registers the Debug ID on the global object. + * + * The snippet is copied from `@sentry/bundler-plugin-core`, so the Sentry SDK picks the id up at + * runtime. Diff against it when Sentry changes the format. The function wrapper keeps its + * variables out of the global scope, since the snippet runs at the top level of the bundle. + */ +function getDebugIdSnippet(debugId: string) { + return `;!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="${debugId}",e._sentryDebugIdIdentifier="sentry-dbid-${debugId}")}catch(e){}}();\n`; +} + +/** + * Turns a string into a UUID the same way `stringToUUID` in `@sentry/bundler-plugin-core` does, + * so the same input always gets the same Debug ID. + */ +function stringToUUID(value: string) { + const hash = createHash('sha256').update(value).digest('hex'); + const variant = ['8', '9', 'a', 'b'][hash.charCodeAt(16) % 4]; + return [ + hash.substring(0, 8), + hash.substring(8, 12), + `4${hash.substring(13, 16)}`, + `${variant}${hash.substring(17, 20)}`, + hash.substring(20, 32), + ].join('-'); +} + +/** + * Plugin for stamping a Sentry Debug ID into the bundle and its source map. + * + * A Debug ID is a UUID present in both artifacts. Sentry uses it to pair a JS stack trace with + * the source map that resolves it, which is what Metro provides through + * `@sentry/react-native`'s `createSentryMetroSerializer`. + * + * `@sentry/webpack-plugin` cannot fill this role for React Native: it only processes `.js`-like + * filenames, so it skips `index.bundle` and its source map. + * + * The plugin only runs in `production` mode, like `createSentryMetroSerializer`, which skips + * development builds. + * + * @example Usage in Rspack config (ESM): + * ```ts + * import * as Repack from '@callstack/repack'; + * + * export default (env) => ({ + * plugins: [new Repack.plugins.SentryDebugIdPlugin()], + * }); + * ``` + * + * @category Webpack Plugin + */ +export class SentryDebugIdPlugin { + constructor(private config: SentryDebugIdPluginConfig = {}) {} + + apply(compiler: RspackCompiler): void; + apply(compiler: WebpackCompiler): void; + + apply(__compiler: unknown) { + const compiler = __compiler as RspackCompiler; + const logger = compiler.getInfrastructureLogger(PLUGIN_NAME); + + // Plugins are applied before config defaults, and an unset mode means production. + if ((compiler.options.mode ?? 'production') !== 'production') { + logger.debug('Skipping Debug IDs outside of production mode.'); + return; + } + + const { Compilation, sources } = compiler.webpack; + const test = this.config.test ?? DEFAULT_TEST; + + compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { + // Scoped to the compilation, so watch rebuilds never reuse a stale id. + const debugIds = new Map(); + + // Inject before minification and source map generation, so the snippet is minified with the + // bundle and the maps account for it. The id comes from the chunk's pre-injection hash, + // since a hash of the output would depend on the id it contains. + compilation.hooks.processAssets.tap( + { + name: PLUGIN_NAME, + stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS, + }, + () => { + for (const chunk of compilation.chunks) { + for (const file of chunk.files) { + const asset = compilation.getAsset(file); + if (!asset || !test.test(file)) { + continue; + } + + const debugId = stringToUUID( + chunk.contentHash.javascript ?? + chunk.hash ?? + asset.source.source().toString() + ); + debugIds.set(file, debugId); + + compilation.updateAsset( + file, + (source) => + new sources.ConcatSource(getDebugIdSnippet(debugId), source) + ); + } + } + } + ); + + // Stamp the maps right after the devtool stage emits them, so later stages, like content + // hashing, see the final assets. + compilation.hooks.processAssets.tap( + { + name: PLUGIN_NAME, + stage: Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING + 1, + }, + () => { + for (const [file, debugId] of debugIds) { + const asset = compilation.getAsset(file); + if (!asset) { + continue; + } + + // `sentry-cli` pairs the bundle with its map through this comment, which matters for + // JSC builds and for uploads outside the Gradle and Xcode scripts. + const code = asset.source.source().toString(); + const sourceMappingURLIndex = code.lastIndexOf( + '//# sourceMappingURL=' + ); + compilation.updateAsset(file, (source) => { + const updated = new sources.ReplaceSource(source); + if (sourceMappingURLIndex === -1) { + updated.insert(code.length, `\n//# debugId=${debugId}\n`); + } else { + updated.insert( + sourceMappingURLIndex, + `//# debugId=${debugId}\n` + ); + } + return updated; + }); + + const related = asset.info.related?.sourceMap; + const mapFile = [ + ...(Array.isArray(related) ? related : [related]), + `${file}.map`, + ].find( + (name): name is string => !!name && !!compilation.getAsset(name) + ); + if (!mapFile) { + continue; + } + + let sourceMap: string; + try { + sourceMap = addDebugIdToSourceMap( + compilation.getAsset(mapFile)!.source.source().toString(), + debugId + ); + } catch { + logger.warn(`Could not parse ${mapFile}, skipping Debug ID.`); + continue; + } + + compilation.updateAsset(mapFile, new sources.RawSource(sourceMap)); + } + } + ); + }); + } +} diff --git a/packages/repack/src/plugins/__tests__/HermesBytecodePlugin.test.ts b/packages/repack/src/plugins/__tests__/HermesBytecodePlugin.test.ts index d4625da68..9d491b28e 100644 --- a/packages/repack/src/plugins/__tests__/HermesBytecodePlugin.test.ts +++ b/packages/repack/src/plugins/__tests__/HermesBytecodePlugin.test.ts @@ -4,6 +4,7 @@ import path from 'node:path'; import { type Compiler, ModuleFilenameHelpers } from '@rspack/core'; import execa from 'execa'; import { HermesBytecodePlugin } from '../HermesBytecodePlugin/index.js'; +import { composeSourceMaps } from '../HermesBytecodePlugin/utils/composeSourceMaps.js'; import { getHermesCLIPath } from '../HermesBytecodePlugin/utils/getHermesCLIPath.js'; jest.mock('node:fs', () => ({ @@ -12,8 +13,10 @@ jest.mock('node:fs', () => ({ existsSync: jest.fn(), promises: { access: jest.fn(), + readFile: jest.fn(), rename: jest.fn(), unlink: jest.fn(), + writeFile: jest.fn(), }, }, })); @@ -213,6 +216,42 @@ describe('HermesBytecodePlugin', () => { ]); }); + describe('composeSourceMaps', () => { + const options = { + reactNativePath: 'path/to/react-native', + packagerMapPath: 'output/path/example.bundle.map', + compilerMapPath: 'output/path/example.bundle.hbc.map', + }; + + it('carries the Debug ID over to the composed source map', async () => { + const debugId = '3f1c2d4e-5a6b-4c7d-8e9f-0a1b2c3d4e5f'; + const fsMock = fs.promises as jest.Mocked; + fsMock.readFile + .mockResolvedValueOnce(`{"version":3,"debugId":"${debugId}"}`) + .mockResolvedValueOnce('{"version":3}'); + + await composeSourceMaps(options); + + expect(fsMock.writeFile).toHaveBeenCalledWith( + `${options.packagerMapPath}.composed`, + `{"version":3,"debugId":"${debugId}","debug_id":"${debugId}"}` + ); + expect(fsMock.rename).toHaveBeenCalledWith( + `${options.packagerMapPath}.composed`, + options.packagerMapPath + ); + }); + + it('leaves the composed source map alone without a Debug ID', async () => { + const fsMock = fs.promises as jest.Mocked; + fsMock.readFile.mockResolvedValueOnce('{"version":3}'); + + await composeSourceMaps(options); + + expect(fsMock.writeFile).not.toHaveBeenCalled(); + }); + }); + describe('getHermesCLIPath', () => { const reactNativePath = 'path/to/react-native'; diff --git a/packages/repack/src/plugins/__tests__/SentryDebugIdPlugin.test.ts b/packages/repack/src/plugins/__tests__/SentryDebugIdPlugin.test.ts new file mode 100644 index 000000000..61f0c96ab --- /dev/null +++ b/packages/repack/src/plugins/__tests__/SentryDebugIdPlugin.test.ts @@ -0,0 +1,216 @@ +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import vm from 'node:vm'; +import { rspack } from '@rspack/core'; +import webpack from 'webpack'; + +import * as Repack from '../../index.js'; +import { SentryDebugIdPlugin } from '../SentryDebugIdPlugin.js'; + +const DEBUG_ID_REGEX = + /_sentryDebugIdIdentifier\s*=\s*"sentry-dbid-([0-9a-f-]{36})"/; + +interface CompileOptions { + bundler?: 'rspack' | 'webpack'; + mode?: 'production' | 'development'; + filename?: string; + entries?: Record; + plugin?: { apply(compiler: any): void }; + context?: string; +} + +async function compile(options: CompileOptions = {}) { + // An explicit `mode: undefined` leaves mode unset, so the bundler default applies. + const mode = 'mode' in options ? options.mode : 'production'; + return compileWithMode(mode, options); +} + +async function compileWithMode( + mode: CompileOptions['mode'], + { + bundler = 'rspack', + filename = '[name].bundle', + entries = { index: "console.log('hello');" }, + plugin = new SentryDebugIdPlugin(), + context = fs.mkdtempSync(path.join(os.tmpdir(), 'sentry-debug-id-')), + }: CompileOptions +) { + const outputPath = path.join(context, 'out'); + for (const [name, code] of Object.entries(entries)) { + fs.writeFileSync(path.join(context, `${name}.js`), code); + } + + const config = { + context, + ...(mode && { mode }), + devtool: 'source-map' as const, + entry: Object.fromEntries( + Object.keys(entries).map((name) => [name, `./${name}.js`]) + ), + output: { filename, path: outputPath }, + plugins: [plugin], + }; + const compiler = + bundler === 'rspack' ? rspack(config) : webpack(config as any); + + await new Promise((resolve, reject) => { + compiler.run((error: Error | null, stats: any) => { + if (error) { + reject(error); + return; + } + if (stats?.hasErrors()) { + reject(new Error(stats.toString({ all: false, errors: true }))); + return; + } + compiler.close(() => resolve()); + }); + }); + + const read = (file: string) => { + const bundle = fs.readFileSync(path.join(outputPath, file), 'utf-8'); + const mapPath = path.join(outputPath, `${file}.map`); + const sourceMap = fs.existsSync(mapPath) + ? JSON.parse(fs.readFileSync(mapPath, 'utf-8')) + : undefined; + return { + bundle, + sourceMap, + debugId: bundle.match(DEBUG_ID_REGEX)?.[1], + }; + }; + + return { + read, + context, + cleanup: () => fs.rmSync(context, { recursive: true }), + }; +} + +describe('SentryDebugIdPlugin', () => { + it('injects a Debug ID into the bundle and its source map', async () => { + const { read, cleanup } = await compile(); + const { bundle, sourceMap, debugId } = read('index.bundle'); + cleanup(); + + expect(debugId).toBeDefined(); + expect(sourceMap.debugId).toBe(debugId); + expect(sourceMap.debug_id).toBe(debugId); + + expect(bundle).toMatch( + new RegExp(`//# debugId=${debugId}\\n//# sourceMappingURL=`) + ); + }); + + it('registers the Debug ID at runtime without leaking globals', async () => { + const { read, cleanup } = await compile(); + const { bundle, debugId } = read('index.bundle'); + cleanup(); + + const context = vm.createContext({ console: { log() {} } }); + vm.runInContext(bundle, context, { filename: 'index.bundle' }); + + expect(Object.values(context._sentryDebugIds)).toEqual([debugId]); + expect(context._sentryDebugIdIdentifier).toBe(`sentry-dbid-${debugId}`); + expect(context).not.toHaveProperty('e'); + expect(context).not.toHaveProperty('n'); + }); + + it('injects a Debug ID for bundles with a .js extension', async () => { + const { read, cleanup } = await compile({ filename: '[name].js' }); + const { sourceMap, debugId } = read('index.js'); + cleanup(); + + expect(debugId).toBeDefined(); + expect(sourceMap.debugId).toBe(debugId); + }); + + it('gives each chunk its own Debug ID', async () => { + const { read, cleanup } = await compile({ + entries: { + index: "console.log('hello');", + other: "console.log('other');", + }, + }); + const index = read('index.bundle'); + const other = read('other.bundle'); + cleanup(); + + expect(index.sourceMap.debugId).toBe(index.debugId); + expect(other.sourceMap.debugId).toBe(other.debugId); + expect(index.debugId).not.toBe(other.debugId); + }); + + it('derives the Debug ID from the bundle content', async () => { + const first = await compile(); + const firstId = first.read('index.bundle').debugId; + const second = await compile({ context: first.context }); + const secondId = second.read('index.bundle').debugId; + const changed = await compile({ + context: first.context, + entries: { index: "console.log('changed');" }, + }); + const changedId = changed.read('index.bundle').debugId; + changed.cleanup(); + + expect(firstId).toBe(secondId); + expect(changedId).not.toBe(firstId); + }); + + it('skips development builds', async () => { + const { read, cleanup } = await compile({ mode: 'development' }); + const { bundle, sourceMap, debugId } = read('index.bundle'); + cleanup(); + + expect(debugId).toBeUndefined(); + expect(bundle).not.toContain('//# debugId='); + expect(sourceMap.debugId).toBeUndefined(); + }); + + it.each(['rspack', 'webpack'] as const)( + 'treats an unset mode as production with %s', + async (bundler) => { + // Given a config without `mode`, which both bundlers default to production + // webpack's devtool only emits maps for `.js` files. + const filename = bundler === 'webpack' ? '[name].js' : '[name].bundle'; + const { read, cleanup } = await compile({ + bundler, + filename, + mode: undefined, + }); + + // When the bundle is read back + const { sourceMap, debugId } = read(filename.replace('[name]', 'index')); + cleanup(); + + // Then it still gets a Debug ID that matches its map + expect(debugId).toBeDefined(); + expect(sourceMap.debugId).toBe(debugId); + } + ); + + it('works with webpack', async () => { + const { read, cleanup } = await compile({ + bundler: 'webpack', + filename: '[name].js', + }); + const { bundle, sourceMap, debugId } = read('index.js'); + cleanup(); + + expect(debugId).toBeDefined(); + expect(sourceMap.debugId).toBe(debugId); + expect(bundle).toContain(`//# debugId=${debugId}`); + }); + + it('is exposed as Repack.plugins.SentryDebugIdPlugin', async () => { + const { read, cleanup } = await compile({ + plugin: new Repack.plugins.SentryDebugIdPlugin(), + }); + const { sourceMap, debugId } = read('index.bundle'); + cleanup(); + + expect(debugId).toBeDefined(); + expect(sourceMap.debugId).toBe(debugId); + }); +}); diff --git a/packages/repack/src/plugins/index.ts b/packages/repack/src/plugins/index.ts index 65a3d74ad..31efcc0fc 100644 --- a/packages/repack/src/plugins/index.ts +++ b/packages/repack/src/plugins/index.ts @@ -11,3 +11,4 @@ export * from './ModuleFederationPluginV2.js'; export * from './NativeEntryPlugin/index.js'; export * from './OutputPlugin/index.js'; export * from './RepackTargetPlugin/index.js'; +export * from './SentryDebugIdPlugin.js'; diff --git a/packages/repack/src/plugins/utils/__tests__/sourceMapDebugId.test.ts b/packages/repack/src/plugins/utils/__tests__/sourceMapDebugId.test.ts new file mode 100644 index 000000000..25af51094 --- /dev/null +++ b/packages/repack/src/plugins/utils/__tests__/sourceMapDebugId.test.ts @@ -0,0 +1,73 @@ +import { + addDebugIdToSourceMap, + getSourceMapDebugId, +} from '../sourceMapDebugId.js'; + +const DEBUG_ID = '3f1c2d4e-5a6b-4c7d-8e9f-0a1b2c3d4e5f'; + +describe('sourceMapDebugId', () => { + it('adds both spellings of the Debug ID', () => { + const sourceMap = addDebugIdToSourceMap( + JSON.stringify({ version: 3, mappings: 'AAAA' }, null, 2) + '\n', + DEBUG_ID + ); + + expect(JSON.parse(sourceMap)).toEqual({ + version: 3, + mappings: 'AAAA', + debugId: DEBUG_ID, + debug_id: DEBUG_ID, + }); + }); + + it('adds the Debug ID to an empty source map', () => { + expect(JSON.parse(addDebugIdToSourceMap('{}', DEBUG_ID))).toEqual({ + debugId: DEBUG_ID, + debug_id: DEBUG_ID, + }); + }); + + it('overwrites an existing Debug ID instead of adding duplicate keys', () => { + const sourceMap = `{"version":3,"debugId":"old","mappings":"AAAA"}`; + + const stamped = addDebugIdToSourceMap(sourceMap, DEBUG_ID); + + expect(stamped.match(/"debugId"/g)).toHaveLength(1); + expect(stamped.match(/"debug_id"/g)).toHaveLength(1); + expect(JSON.parse(stamped)).toEqual({ + version: 3, + debugId: DEBUG_ID, + mappings: 'AAAA', + debug_id: DEBUG_ID, + }); + }); + + it('leaves a Debug ID inside sourcesContent untouched when stamping', () => { + const sourceMap = JSON.stringify({ + sourcesContent: [`const map = {"debugId": "old"};`], + }); + + const stamped = JSON.parse(addDebugIdToSourceMap(sourceMap, DEBUG_ID)); + + expect(stamped.sourcesContent).toEqual([`const map = {"debugId": "old"};`]); + expect(stamped.debugId).toBe(DEBUG_ID); + }); + + it('throws when the source map is not a JSON object', () => { + expect(() => addDebugIdToSourceMap('', DEBUG_ID)).toThrow(); + }); + + it('reads either spelling of the Debug ID', () => { + expect(getSourceMapDebugId(`{"debugId":"${DEBUG_ID}"}`)).toBe(DEBUG_ID); + expect(getSourceMapDebugId(`{"debug_id":"${DEBUG_ID}"}`)).toBe(DEBUG_ID); + }); + + it('ignores a Debug ID inside sourcesContent', () => { + const sourceMap = JSON.stringify({ + sourcesContent: [`const map = {"debugId": "${DEBUG_ID}"};`], + names: ['debugId'], + }); + + expect(getSourceMapDebugId(sourceMap)).toBeUndefined(); + }); +}); diff --git a/packages/repack/src/plugins/utils/sourceMapDebugId.ts b/packages/repack/src/plugins/utils/sourceMapDebugId.ts new file mode 100644 index 000000000..a1d18d26e --- /dev/null +++ b/packages/repack/src/plugins/utils/sourceMapDebugId.ts @@ -0,0 +1,47 @@ +// The lookbehind skips escaped quotes, so a `"debugId":` inside `sourcesContent` doesn't match. +const DEBUG_ID_REGEX = /(?(); + const replaced = sourceMap.replace( + DEBUG_ID_FIELD_REGEX, + (_match, key: string, colon: string) => { + present.add(key); + return `"${key}"${colon}"${debugId}"`; + } + ); + const missing = ['debugId', 'debug_id'] + .filter((key) => !present.has(key)) + .map((key) => `"${key}":"${debugId}"`); + if (missing.length === 0) { + return replaced; + } + + const head = replaced.slice(0, replaced.lastIndexOf('}')).trimEnd(); + const separator = head.endsWith('{') ? '' : ','; + return `${head}${separator}${missing.join(',')}}`; +} diff --git a/website/src/latest/api/plugins/_meta.json b/website/src/latest/api/plugins/_meta.json index 3d3c3ddad..f5ddcb058 100644 --- a/website/src/latest/api/plugins/_meta.json +++ b/website/src/latest/api/plugins/_meta.json @@ -24,6 +24,11 @@ "name": "hermes-bytecode", "label": "HermesBytecodePlugin" }, + { + "type": "file", + "name": "sentry-debug-id", + "label": "SentryDebugIdPlugin" + }, { "type": "file", "name": "internal", diff --git a/website/src/latest/api/plugins/sentry-debug-id.md b/website/src/latest/api/plugins/sentry-debug-id.md new file mode 100644 index 000000000..2e7ac81dd --- /dev/null +++ b/website/src/latest/api/plugins/sentry-debug-id.md @@ -0,0 +1,41 @@ +# SentryDebugId Plugin + +This plugin stamps a [Sentry](https://sentry.io) Debug ID into the bundle and its source map, and adds a `//# debugId=` comment to the bundle. + +A Debug ID is a UUID present in both artifacts. The Sentry SDK reports it with every event, and Sentry uses it to pair a JS stack trace with the source map that resolves it. Without it, symbolication falls back to matching on `release` and `dist`, which only works when the values used at upload time match the ones the SDK reports at runtime. + +For Metro, `@sentry/react-native` provides this through `createSentryMetroSerializer`. This plugin is the Re.Pack counterpart. + +:::info Why `@sentry/webpack-plugin` is not enough +`@sentry/webpack-plugin` only processes `.js`-like filenames, so it skips React Native bundle names such as `index.bundle` and their source maps. `@sentry/react-native`'s Gradle and Xcode upload scripts read the Debug ID from the emitted source map, so without it symbolication fails silently. + +You can use both plugins together: this one handles the Debug ID, `@sentry/webpack-plugin` handles release creation and upload. +::: + +## Usage + +```js title="rspack.config.cjs" +const Repack = require("@callstack/repack"); + +module.exports = { + plugins: [ + new Repack.plugins.SentryDebugIdPlugin({ + // options + }), + ], +}; +``` + +The plugin only runs when `mode` is `production`, since Debug IDs are only useful for release builds. + +The Debug ID is derived from the bundle content, so the same input always gets the same ID. When [`HermesBytecodePlugin`](/api/plugins/hermes-bytecode) compiles a bundle to bytecode, the Debug ID is carried over to the composed source map. + +## Options + +### test + +- Type: `RegExp` +- Required: `false` +- Default: `/\.([cm]?jsx?|bundle)$/` + +Matches the bundles that should receive a Debug ID.