Skip to content

Commit 30b6d4e

Browse files
authored
ref: Emit transaction instead of culprit (#1330)
1 parent 166546b commit 30b6d4e

File tree

5 files changed

+145
-15
lines changed

5 files changed

+145
-15
lines changed

plugins/react-native.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ reactNativePlugin._transport = function(options) {
218218
};
219219

220220
/**
221-
* Strip device-specific IDs found in culprit and frame filenames
221+
* Strip device-specific IDs found in transaction and frame filenames
222222
* when running React Native applications on a physical device.
223223
*/
224224
reactNativePlugin._normalizeData = function(data, pathStripRe) {
@@ -230,6 +230,10 @@ reactNativePlugin._normalizeData = function(data, pathStripRe) {
230230
data.culprit = normalizeUrl(data.culprit, pathStripRe);
231231
}
232232

233+
if (data.transaction) {
234+
data.transaction = normalizeUrl(data.transaction, pathStripRe);
235+
}
236+
233237
// NOTE: if data.exception exists, exception.values and exception.values[0] are
234238
// guaranteed to exist
235239
var stacktrace =

src/raven.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ function now() {
4949
var _window =
5050
typeof window !== 'undefined'
5151
? window
52-
: typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
52+
: typeof global !== 'undefined'
53+
? global
54+
: typeof self !== 'undefined'
55+
? self
56+
: {};
5357
var _document = _window.document;
5458
var _navigator = _window.navigator;
5559

@@ -1695,7 +1699,7 @@ Raven.prototype = {
16951699
}
16961700
]
16971701
},
1698-
culprit: fileurl
1702+
transaction: fileurl
16991703
},
17001704
options
17011705
);
@@ -1810,7 +1814,7 @@ Raven.prototype = {
18101814
if (
18111815
!last ||
18121816
current.message !== last.message || // defined for captureMessage
1813-
current.culprit !== last.culprit // defined for captureException/onerror
1817+
current.transaction !== last.transaction // defined for captureException/onerror
18141818
)
18151819
return false;
18161820

test/plugins/angular.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Angular plugin', function() {
1515
logger: 'javascript',
1616
platform: 'javascript',
1717

18-
culprit: 'http://example.org/app.js',
18+
transaction: 'http://example.org/app.js',
1919
message: 'Error: crap',
2020
exception: {
2121
type: 'Error',
@@ -50,7 +50,7 @@ describe('Angular plugin', function() {
5050
logger: 'javascript',
5151
platform: 'javascript',
5252

53-
culprit: 'http://example.org/app.js',
53+
transaction: 'http://example.org/app.js',
5454
message: 'Error: crap',
5555
exception: {
5656
type: 'Error',

test/plugins/react-native.test.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,128 @@ describe('React Native plugin', function() {
136136
assert.equal(frames[0].filename, '/file1.js');
137137
assert.equal(frames[1].filename, '/file2.js');
138138
});
139+
140+
it('should normalize transaction and frame filenames/URLs from .app directory', function() {
141+
var data = {
142+
project: '2',
143+
logger: 'javascript',
144+
platform: 'javascript',
145+
146+
transaction:
147+
'file:///var/mobile/Containers/Bundle/Application/ABC/123.app/app.js',
148+
message: 'Error: crap',
149+
exception: {
150+
type: 'Error',
151+
values: [
152+
{
153+
stacktrace: {
154+
frames: [
155+
{
156+
filename:
157+
'file:///var/containers/Bundle/Application/ABC/123.app/file1.js',
158+
lineno: 10,
159+
colno: 11,
160+
function: 'broken'
161+
},
162+
{
163+
filename:
164+
'file:///var/mobile/Containers/Bundle/Application/ABC/123.app/file2.js',
165+
lineno: 12,
166+
colno: 13,
167+
function: 'lol'
168+
}
169+
]
170+
}
171+
}
172+
]
173+
}
174+
};
175+
reactNativePlugin._normalizeData(data);
176+
177+
assert.equal(data.transaction, '/app.js');
178+
var frames = data.exception.values[0].stacktrace.frames;
179+
assert.equal(frames[0].filename, '/file1.js');
180+
assert.equal(frames[1].filename, '/file2.js');
181+
});
182+
183+
it('should normalize transaction and frame filenames/URLs from stacktrace interface', function() {
184+
var data = {
185+
project: '2',
186+
logger: 'javascript',
187+
platform: 'javascript',
188+
189+
transaction:
190+
'file:///var/mobile/Containers/Bundle/Application/ABC/123.app/app.js',
191+
message: 'Error: crap',
192+
193+
stacktrace: {
194+
frames: [
195+
{
196+
filename: 'file:///var/containers/Bundle/Application/ABC/123.app/file1.js',
197+
lineno: 10,
198+
colno: 11,
199+
function: 'broken'
200+
},
201+
{
202+
filename:
203+
'file:///var/mobile/Containers/Bundle/Application/ABC/123.app/file2.js',
204+
lineno: 12,
205+
colno: 13,
206+
function: 'lol'
207+
}
208+
]
209+
}
210+
};
211+
reactNativePlugin._normalizeData(data);
212+
213+
assert.equal(data.transaction, '/app.js');
214+
var frames = data.stacktrace.frames;
215+
assert.equal(frames[0].filename, '/file1.js');
216+
assert.equal(frames[1].filename, '/file2.js');
217+
});
218+
219+
it('should normalize transaction and frame filenames/URLs from CodePush', function() {
220+
var data = {
221+
project: '2',
222+
logger: 'javascript',
223+
platform: 'javascript',
224+
225+
transaction:
226+
'file:///var/mobile/Containers/Data/Application/ABC/Library/Application%20Support/CodePush/CDE/CodePush/app.js',
227+
message: 'Error: crap',
228+
exception: {
229+
type: 'Error',
230+
values: [
231+
{
232+
stacktrace: {
233+
frames: [
234+
{
235+
filename:
236+
'file:///var/mobile/Containers/Data/Application/ABC/Library/Application%20Support/CodePush/CDE/CodePush/file1.js',
237+
lineno: 10,
238+
colno: 11,
239+
function: 'broken'
240+
},
241+
{
242+
filename:
243+
'file:///var/mobile/Containers/Data/Application/ABC/Library/Application%20Support/CodePush/CDE/CodePush/file2.js',
244+
lineno: 12,
245+
colno: 13,
246+
function: 'lol'
247+
}
248+
]
249+
}
250+
}
251+
]
252+
}
253+
};
254+
reactNativePlugin._normalizeData(data);
255+
256+
assert.equal(data.transaction, '/app.js');
257+
var frames = data.exception.values[0].stacktrace.frames;
258+
assert.equal(frames[0].filename, '/file1.js');
259+
assert.equal(frames[1].filename, '/file2.js');
260+
});
139261
});
140262

141263
describe('_transport()', function() {

test/raven.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ describe('globals', function() {
648648
}
649649
]
650650
},
651-
culprit: 'http://example.com/file1.js'
651+
transaction: 'http://example.com/file1.js'
652652
}
653653
]);
654654

@@ -666,7 +666,7 @@ describe('globals', function() {
666666
}
667667
]
668668
},
669-
culprit: 'http://example.com/file1.js'
669+
transaction: 'http://example.com/file1.js'
670670
}
671671
]);
672672

@@ -686,7 +686,7 @@ describe('globals', function() {
686686
}
687687
]
688688
},
689-
culprit: 'http://example.com/file1.js',
689+
transaction: 'http://example.com/file1.js',
690690
extra: 'awesome'
691691
}
692692
]);
@@ -722,7 +722,7 @@ describe('globals', function() {
722722
}
723723
]
724724
},
725-
culprit: 'http://example.com/override.js'
725+
transaction: 'http://example.com/override.js'
726726
}
727727
]);
728728

@@ -753,7 +753,7 @@ describe('globals', function() {
753753
}
754754
]
755755
},
756-
culprit: 'http://example.com/override.js'
756+
transaction: 'http://example.com/override.js'
757757
}
758758
]);
759759

@@ -779,7 +779,7 @@ describe('globals', function() {
779779
}
780780
]
781781
},
782-
culprit: 'http://example.com/override.js',
782+
transaction: 'http://example.com/override.js',
783783
extra: 'awesome'
784784
}
785785
]);
@@ -2071,7 +2071,7 @@ describe('globals', function() {
20712071
pre_context: ['line4']
20722072
}]
20732073
},
2074-
culprit: 'http://example.com',
2074+
transaction: 'http://example.com',
20752075
message: 'Error: pickleRick',
20762076
foo: 'bar'
20772077
}]);
@@ -3805,7 +3805,7 @@ describe('Raven (private methods)', function() {
38053805
describe('from captureException/onerror', function() {
38063806
beforeEach(function() {
38073807
Raven._lastData = {
3808-
culprit: 'https://example.com/js/foo.js',
3808+
transaction: 'https://example.com/js/foo.js',
38093809
exception: {
38103810
type: 'TypeError',
38113811
value: 'foo is not defined',
@@ -3834,7 +3834,7 @@ describe('Raven (private methods)', function() {
38343834

38353835
it('should return false for different exceptions', function() {
38363836
var data = JSON.parse(JSON.stringify(Raven._lastData)); // copy
3837-
data.culprit = 'https://example.com/js/bar.js';
3837+
data.transaction = 'https://example.com/js/bar.js';
38383838
assert.isFalse(Raven._isRepeatData(data));
38393839

38403840
data = JSON.parse(JSON.stringify(Raven._lastData)); // copy

0 commit comments

Comments
 (0)