Skip to content

Commit d5b8ac0

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

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

plugins/react-native.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
/*global ErrorUtils:false*/
22

3+
"use strict";
4+
35
/**
46
* react-native plugin for Raven
57
*
68
* Usage:
79
* var Raven = require('raven-js');
810
* require('raven-js/plugins/react-native')(Raven);
911
*/
10-
module.exports = function (Raven) {
11-
"use strict";
1212

13+
var DEVICE_PATH_RE = /\/var\/mobile\/Containers\/Bundle\/Application\/[^\/]+\/[^\.]+\.app/;
14+
function normalizeUrl(url) {
15+
return url
16+
.replace(/file\:\/\//, '')
17+
.replace(DEVICE_PATH_RE, '');
18+
}
19+
20+
module.exports = function (Raven) {
1321
function urlencode(obj) {
1422
var pairs = [];
1523
for (var key in obj) {
@@ -47,5 +55,19 @@ module.exports = function (Raven) {
4755
// transport - use XMLHttpRequest instead
4856
Raven.setTransport(xhrTransport);
4957

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

0 commit comments

Comments
 (0)