Skip to content

Commit 185debc

Browse files
feat(sourcemaps): Add Debug Ids support for JSC and Hermes bundles (#3164)
Co-authored-by: Abhijeet Prasad <[email protected]>
1 parent 457e29f commit 185debc

30 files changed

+1210
-123
lines changed

.github/workflows/e2e.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ jobs:
263263
run: |
264264
patch --verbose --strip=0 --force --ignore-whitespace --fuzz 4 < ../../../rn.patch
265265
../../../rn.patch.app.js --app .
266+
../../../rn.patch.metro.config.js --path metro.config.js
266267
267268
- name: Patch Android App RN
268269
if: ${{ matrix.platform == 'android' }}

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@
1313
!/android/**/*
1414
!src/js/NativeRNSentry.ts
1515
!scripts/collect-modules.sh
16+
!scripts/copy-debugid.js
17+
!scripts/has-sourcemap-debugid.js
18+
!scripts/sentry-xcode.sh
19+
!scripts/sentry-xcode-debug-files.sh

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,32 @@
55
### Features
66

77
- Add `buildFeatures.buildConfig=true` to support AGP 8 ([#3298](https://github.com/getsentry/sentry-react-native/pull/3298))
8+
- Add Debug ID support ([#3164](https://github.com/getsentry/sentry-react-native/pull/3164))
9+
10+
This is optional to use Debug IDs. Your current setup will keep working as is.
11+
12+
Add Sentry Metro Serializer to `metro.config.js` to generate Debug ID for the application bundle and source map.
13+
14+
```javascript
15+
const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');
16+
const config = {serializer: createSentryMetroSerializer()};
17+
```
18+
19+
On iOS update `Bundle React Native Code and Images` and `Upload Debug Symbols to Sentry` build phases.
20+
21+
```bash
22+
set -e
23+
WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
24+
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
25+
26+
/bin/sh -c "$WITH_ENVIRONMENT \"/bin/sh ../scripts/sentry-xcode.sh $REACT_NATIVE_XCODE\""
27+
```
28+
29+
```bash
30+
/bin/sh ../../scripts/sentry-xcode-debug-files.sh
31+
```
32+
33+
More information about the new setup [can be found here](https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/).
834

935
### Fixes
1036

jest.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
collectCoverage: true,
3+
preset: 'react-native',
4+
setupFilesAfterEnv: ['<rootDir>/test/mockConsole.ts'],
5+
globals: {
6+
__DEV__: true,
7+
'ts-jest': {
8+
tsConfig: './tsconfig.json',
9+
diagnostics: false,
10+
},
11+
},
12+
moduleFileExtensions: ['ts', 'tsx', 'js'],
13+
testPathIgnorePatterns: ['<rootDir>/test/e2e/', '<rootDir>/test/tools/', '<rootDir>/test/react-native/versions'],
14+
testEnvironment: 'node',
15+
testMatch: ['**/*.test.(ts|tsx)'],
16+
};

jest.config.tools.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
collectCoverage: true,
3+
preset: 'ts-jest',
4+
setupFilesAfterEnv: ['<rootDir>/test/mockConsole.ts'],
5+
globals: {
6+
__DEV__: true,
7+
},
8+
testMatch: ['**/test/tools/**/*.ts'],
9+
transform: {
10+
'^.+\\.(ts|tsx)$': [
11+
'ts-jest',
12+
{
13+
tsconfig: './tsconfig.build.tools.json',
14+
diagnostics: false,
15+
},
16+
],
17+
},
18+
};

package.json

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"build:tools": "tsc -p tsconfig.build.tools.json",
2525
"downlevel": "downlevel-dts dist ts3.8/dist --to=3.8",
2626
"clean": "rimraf dist coverage",
27-
"test": "jest",
27+
"test": "yarn test:sdk && yarn test:tools",
28+
"test:sdk": "jest",
29+
"test:tools": "jest --config jest.config.tools.js",
2830
"fix": "yarn fix:eslint && yarn fix:prettier",
2931
"fix:eslint": "eslint --config .eslintrc.js --fix .",
3032
"fix:prettier": "prettier --write \"{src,test,scripts}/**/**.ts\"",
@@ -72,20 +74,25 @@
7274
"@sentry/wizard": "3.13.0",
7375
"@types/jest": "^29.5.3",
7476
"@types/react": "^18.2.14",
77+
"@types/uglify-js": "^3.17.2",
78+
"@types/uuid": "^9.0.4",
7579
"babel-jest": "^29.6.2",
7680
"downlevel-dts": "^0.11.0",
7781
"eslint": "^7.6.0",
7882
"eslint-plugin-react": "^7.20.6",
7983
"eslint-plugin-react-native": "^3.8.1",
8084
"jest": "^29.6.2",
8185
"jest-environment-jsdom": "^29.6.2",
86+
"metro": "0.76",
8287
"prettier": "^2.0.5",
8388
"react": "18.2.0",
8489
"react-native": "0.72.4",
8590
"replace-in-file": "^7.0.1",
8691
"rimraf": "^4.1.1",
8792
"ts-jest": "^29.1.1",
88-
"typescript": "4.9.5"
93+
"typescript": "4.9.5",
94+
"uglify-js": "^3.17.4",
95+
"uuid": "^9.0.1"
8996
},
9097
"rnpm": {
9198
"commands": {},
@@ -95,33 +102,6 @@
95102
},
96103
"ios": {}
97104
},
98-
"jest": {
99-
"collectCoverage": true,
100-
"preset": "react-native",
101-
"setupFilesAfterEnv": [
102-
"<rootDir>/test/mockConsole.ts"
103-
],
104-
"globals": {
105-
"__DEV__": true,
106-
"ts-jest": {
107-
"tsConfig": "./tsconfig.json",
108-
"diagnostics": false
109-
}
110-
},
111-
"moduleFileExtensions": [
112-
"ts",
113-
"tsx",
114-
"js"
115-
],
116-
"testPathIgnorePatterns": [
117-
"<rootDir>/test/e2e/",
118-
"<rootDir>/test/react-native/versions"
119-
],
120-
"testEnvironment": "node",
121-
"testMatch": [
122-
"**/*.test.(ts|tsx)"
123-
]
124-
},
125105
"codegenConfig": {
126106
"name": "RNSentrySpec",
127107
"type": "modules",

sample-new-architecture/android/app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ project.ext.sentryCli = [
7474
"../..",
7575
],
7676
skipCollectModules: false,
77+
copyDebugIdScript: "../../../scripts/copy-debugid.js",
78+
hasSourceMapDebugIdScript: "../../../scripts/has-sourcemap-debugid.js",
7779
]
7880

7981
apply from: "../../../sentry.gradle"

sample-new-architecture/android/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# The setting is particularly useful for tweaking memory settings.
1212
# Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
1313
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
14+
org.gradle.logging.level=lifecycle
1415

1516
# When configured, Gradle will run in incubating parallel mode.
1617
# This option should only be used with decoupled projects. More details, visit

sample-new-architecture/ios/.xcode.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@
99
# For example, to use nvm with brew, add the following line
1010
#. "$(brew --prefix nvm)/nvm.sh" --no-use
1111
export NODE_BINARY=$(command -v node)
12+
13+
export EXTRA_COMPILER_ARGS="-w"
14+
15+
export SENTRY_CLI_EXECUTABLE="../../node_modules/@sentry/cli/bin/sentry-cli"
16+
export SENTRY_CLI_EXTRA_ARGS="--force-foreground"
17+
export SENTRY_CLI_DEBUG_FILES_UPLOAD_EXTRA_ARGS=""
18+
export SENTRY_CLI_RN_XCODE_EXTRA_ARGS=""
19+
export MODULES_PATHS="$PWD/../node_modules,$PWD/../../.."

sample-new-architecture/ios/sampleNewArchitecture.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271
);
272272
runOnlyForDeploymentPostprocessing = 0;
273273
shellPath = /bin/sh;
274-
shellScript = "set -e\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\n\nexport SENTRY_PROPERTIES=sentry.properties\nexport EXTRA_PACKAGER_ARGS=\"--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map\"\n\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\nSENTRY_CLI=\"../../node_modules/@sentry/cli/bin/sentry-cli\"\nBUNDLE_REACT_NATIVE=\"$SENTRY_CLI react-native xcode --force-foreground $REACT_NATIVE_XCODE\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"$BUNDLE_REACT_NATIVE\\\"\"\n\nexport MODULES_PATHS=\"$PWD/../node_modules,$PWD/../../..\"\nCOLLECT_MODULES=\"../../scripts/collect-modules.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"$COLLECT_MODULES\\\"\"\n";
274+
shellScript = "set -e\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\nBUNDLE_REACT_NATIVE=\"/bin/sh ../../scripts/sentry-xcode.sh $REACT_NATIVE_XCODE\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"$BUNDLE_REACT_NATIVE\\\"\"\n";
275275
};
276276
00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = {
277277
isa = PBXShellScriptBuildPhase;
@@ -303,7 +303,7 @@
303303
);
304304
runOnlyForDeploymentPostprocessing = 0;
305305
shellPath = /bin/sh;
306-
shellScript = "set -e\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\n\nexport SENTRY_PROPERTIES=sentry.properties\n\n[[ $SENTRY_INCLUDE_NATIVE_SOURCES == \"true\" ]] && INCLUDE_SOURCES_FLAG=\"--include-sources\" || INCLUDE_SOURCES_FLAG=\"\"\nSENTRY_CLI=\"../../node_modules/@sentry/cli/bin/sentry-cli\"\nFLAGS=\"--force-foreground $INCLUDE_SOURCES_FLAG\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"$UPLOAD_DEBUG_FILES\\\"\"\n";
306+
shellScript = "/bin/sh ../../scripts/sentry-xcode-debug-files.sh\n";
307307
};
308308
A55EABD7B0C7F3A422A6CC61 /* [CP] Check Pods Manifest.lock */ = {
309309
isa = PBXShellScriptBuildPhase;

0 commit comments

Comments
 (0)