Skip to content

Commit 7f6d414

Browse files
committed
Strip device-specific paths/urls from react native paths
1 parent d2ab38b commit 7f6d414

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

plugins/react-native.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
* var Raven = require('raven-js');
88
* require('raven-js/plugins/react-native')(Raven);
99
*/
10+
11+
var DEVICE_PATH_RE = /^\/var\/mobile\/Containers\/Bundle\/Application\/[^\/]+\/[^\.]+\.app/;
12+
function normalizeUrl(url) {
13+
"use strict";
14+
15+
return url
16+
.replace(/file\:\/\//, '')
17+
.replace(DEVICE_PATH_RE, '');
18+
}
19+
1020
module.exports = function (Raven) {
1121
"use strict";
1222

@@ -47,5 +57,19 @@ module.exports = function (Raven) {
4757
// transport - use XMLHttpRequest instead
4858
Raven.setTransport(xhrTransport);
4959

60+
61+
// Use data callback to strip device-specific paths from stack traces
62+
Raven.setDataCallback(function (data) {
63+
if (data.culprit) {
64+
data.culprit = normalizeUrl(data.culprit);
65+
}
66+
67+
if (data.stacktrace && data.stacktrace.frames && data.stacktrace.frames.length) {
68+
data.stacktrace.frames.forEach(function (frame) {
69+
frame.filename = normalizeUrl(frame.filename);
70+
});
71+
}
72+
});
73+
5074
ErrorUtils.setGlobalHandler(Raven.captureException);
5175
};

0 commit comments

Comments
 (0)