UNPKG

1.44 kBJavaScriptView Raw
1/** Add node transaction to the event */
2class Transaction {constructor() { Transaction.prototype.__init.call(this); }
3 /**
4 * @inheritDoc
5 */
6 static __initStatic() {this.id = 'Transaction';}
7
8 /**
9 * @inheritDoc
10 */
11 __init() {this.name = Transaction.id;}
12
13 /**
14 * @inheritDoc
15 */
16 setupOnce(addGlobalEventProcessor, getCurrentHub) {
17 addGlobalEventProcessor(event => {
18 const self = getCurrentHub().getIntegration(Transaction);
19 if (self) {
20 return self.process(event);
21 }
22 return event;
23 });
24 }
25
26 /**
27 * @inheritDoc
28 */
29 process(event) {
30 const frames = this._getFramesFromEvent(event);
31
32 // use for loop so we don't have to reverse whole frames array
33 for (let i = frames.length - 1; i >= 0; i--) {
34 const frame = frames[i];
35
36 if (frame.in_app === true) {
37 event.transaction = this._getTransaction(frame);
38 break;
39 }
40 }
41
42 return event;
43 }
44
45 /** JSDoc */
46 _getFramesFromEvent(event) {
47 const exception = event.exception && event.exception.values && event.exception.values[0];
48 return (exception && exception.stacktrace && exception.stacktrace.frames) || [];
49 }
50
51 /** JSDoc */
52 _getTransaction(frame) {
53 return frame.module || frame.function ? `${frame.module || '?'}/${frame.function || '?'}` : '<unknown>';
54 }
55} Transaction.__initStatic();
56
57export { Transaction };
58//# sourceMappingURL=transaction.js.map