Skip to content

Commit 7c3bc66

Browse files
Merge 0955f2d into 5fefdf7
2 parents 5fefdf7 + 0955f2d commit 7c3bc66

14 files changed

+791
-74
lines changed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
!/android/**/*
1414
!src/js/NativeRNSentry.ts
1515
!scripts/collect-modules.sh
16+
!scripts/copy-debugid.js
17+
!scripts/hasSourceMapDebugId.js

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,23 @@
7272
"@sentry/wizard": "3.13.0",
7373
"@types/jest": "^29.5.3",
7474
"@types/react": "^18.2.14",
75+
"@types/uuid": "^9.0.4",
7576
"babel-jest": "^29.6.2",
7677
"downlevel-dts": "^0.11.0",
7778
"eslint": "^7.6.0",
7879
"eslint-plugin-react": "^7.20.6",
7980
"eslint-plugin-react-native": "^3.8.1",
8081
"jest": "^29.6.2",
8182
"jest-environment-jsdom": "^29.6.2",
83+
"metro": "0.76",
8284
"prettier": "^2.0.5",
8385
"react": "18.2.0",
8486
"react-native": "0.72.4",
8587
"replace-in-file": "^7.0.1",
8688
"rimraf": "^4.1.1",
8789
"ts-jest": "^29.1.1",
88-
"typescript": "4.9.5"
90+
"typescript": "4.9.5",
91+
"uuid": "^9.0.1"
8992
},
9093
"rnpm": {
9194
"commands": {},

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/hasSourceMapDebugId.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/metro.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
22
const path = require('path');
33
const blacklist = require('metro-config/src/defaults/exclusionList');
44

5+
const {
6+
createSentryMetroSerializer,
7+
} = require('../dist/js/tools/sentryMetroSerializer');
58
const parentDir = path.resolve(__dirname, '..');
69

710
/**
@@ -41,6 +44,10 @@ const config = {
4144
},
4245
),
4346
},
47+
serializer: {
48+
customSerializer: createSentryMetroSerializer(),
49+
},
4450
};
4551

46-
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
52+
const m = mergeConfig(getDefaultConfig(__dirname), config);
53+
module.exports = m;

scripts/copy-debugid.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const process = require('process');
2+
const fs = require('fs');
3+
4+
console.log('Copy `debugId` from packager source map to Hermes source map...');
5+
6+
const packagerSourceMapPath = process.argv[2];
7+
const hermesSourceMapPath = process.argv[3];
8+
9+
if (!packagerSourceMapPath) {
10+
console.log('Please provide packager source map path (A path to copy `debugId` from).');
11+
process.exit(0);
12+
}
13+
if (!hermesSourceMapPath) {
14+
console.log('Please provide Hermes source map path. ((A path to copy `debugId` to))');
15+
process.exit(0);
16+
}
17+
if (!fs.existsSync(packagerSourceMapPath)) {
18+
console.log('Packager source map path (A path to copy `debugId` from).');
19+
process.exit(0);
20+
}
21+
if (!fs.existsSync(hermesSourceMapPath)) {
22+
console.log('Hermes source map not found. ((A path to copy `debugId` to))');
23+
process.exit(0);
24+
}
25+
26+
const from = fs.readFileSync(process.argv[2], 'utf8');
27+
const to = fs.readFileSync(process.argv[3], 'utf8');
28+
29+
const fromParsed = JSON.parse(from);
30+
const toParsed = JSON.parse(to);
31+
32+
if (!fromParsed.debugId && !fromParsed.debug_id) {
33+
console.log('Packager source map does not have `debugId`.');
34+
process.exit(0);
35+
}
36+
37+
if (toParsed.debugId || toParsed.debug_id) {
38+
console.log('Hermes combined source map already has `debugId`.');
39+
process.exit(0);
40+
}
41+
42+
if (fromParsed.debugId) {
43+
toParsed.debugId = fromParsed.debugId;
44+
toParsed.debug_id = fromParsed.debugId;
45+
} else if (fromParsed.debug_id) {
46+
toParsed.debugId = fromParsed.debug_id;
47+
toParsed.debug_id = fromParsed.debug_id;
48+
}
49+
50+
fs.writeFileSync(process.argv[3], JSON.stringify(toParsed));
51+
52+
console.log('Done.');

scripts/hasSourceMapDebugId.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const process = require('process');
2+
const fs = require('fs');
3+
4+
const sourceMapPath = process.argv[2];
5+
6+
if (!sourceMapPath) {
7+
console.log('Add source map path as first argument of the script.');
8+
process.exit(1);
9+
}
10+
11+
if (!fs.existsSync(sourceMapPath)) {
12+
console.log(`${sourceMapPath} does not exist.`);
13+
process.exit(1);
14+
}
15+
16+
let sourceMap;
17+
try {
18+
sourceMap = JSON.parse(fs.readFileSync(sourceMapPath, 'utf8'));
19+
} catch (e) {
20+
console.log(`${sourceMapPath} is not valid JSON`, e);
21+
process.exist(1);
22+
}
23+
24+
if (typeof sourceMap.debugId === 'string' && sourceMap.debugId.length > 0) {
25+
console.log(sourceMap.debugId);
26+
} else if (typeof sourceMap.debug_id === 'string' && sourceMap.debug_id.length > 0) {
27+
console.log(sourceMap.debug_id);
28+
} else {
29+
console.log(`${sourceMapPath} does not contain 'debugId' nor 'debug_id'.`);
30+
process.exist(1);
31+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This is non minified version the debug id injection snippet used in the Metro plugin.
2+
var _sentryDebugIds = {};
3+
var _sentryDebugIdIdentifier = '';
4+
try {
5+
var stack = new Error().stack;
6+
if (stack) {
7+
_sentryDebugIds[stack] = '__SENTRY_DEBUG_ID__';
8+
// eslint-disable-next-line no-unused-vars
9+
_sentryDebugIdIdentifier = 'sentry-dbid-__SENTRY_DEBUG_ID__';
10+
}
11+
} catch (e) {
12+
/**/
13+
}

0 commit comments

Comments
 (0)