@sentry/browser 7.0.0-alpha.0 → 7.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/README.md +2 -3
  2. package/cjs/client.js +130 -68
  3. package/cjs/client.js.map +1 -1
  4. package/cjs/eventbuilder.js +227 -168
  5. package/cjs/eventbuilder.js.map +1 -1
  6. package/cjs/exports.js +55 -42
  7. package/cjs/exports.js.map +1 -1
  8. package/cjs/flags.js +7 -3
  9. package/cjs/flags.js.map +1 -1
  10. package/cjs/helpers.js +123 -130
  11. package/cjs/helpers.js.map +1 -1
  12. package/cjs/index.js +78 -13
  13. package/cjs/index.js.map +1 -1
  14. package/cjs/integrations/breadcrumbs.js +223 -193
  15. package/cjs/integrations/breadcrumbs.js.map +1 -1
  16. package/cjs/integrations/dedupe.js +183 -143
  17. package/cjs/integrations/dedupe.js.map +1 -1
  18. package/cjs/integrations/globalhandlers.js +212 -171
  19. package/cjs/integrations/globalhandlers.js.map +1 -1
  20. package/cjs/integrations/httpcontext.js +51 -0
  21. package/cjs/integrations/httpcontext.js.map +1 -0
  22. package/cjs/integrations/index.js +18 -14
  23. package/cjs/integrations/index.js.map +1 -1
  24. package/cjs/integrations/linkederrors.js +79 -48
  25. package/cjs/integrations/linkederrors.js.map +1 -1
  26. package/cjs/integrations/trycatch.js +245 -216
  27. package/cjs/integrations/trycatch.js.map +1 -1
  28. package/cjs/sdk.js +168 -108
  29. package/cjs/sdk.js.map +1 -1
  30. package/cjs/stack-parsers.js +134 -83
  31. package/cjs/stack-parsers.js.map +1 -1
  32. package/cjs/transports/fetch.js +34 -80
  33. package/cjs/transports/fetch.js.map +1 -1
  34. package/cjs/transports/index.js +10 -12
  35. package/cjs/transports/index.js.map +1 -1
  36. package/cjs/transports/utils.js +57 -52
  37. package/cjs/transports/utils.js.map +1 -1
  38. package/cjs/transports/xhr.js +53 -63
  39. package/cjs/transports/xhr.js.map +1 -1
  40. package/esm/client.js +128 -67
  41. package/esm/client.js.map +1 -1
  42. package/esm/eventbuilder.js +218 -159
  43. package/esm/eventbuilder.js.map +1 -1
  44. package/esm/exports.js +12 -7
  45. package/esm/exports.js.map +1 -1
  46. package/esm/flags.js +5 -2
  47. package/esm/flags.js.map +1 -1
  48. package/esm/helpers.js +121 -127
  49. package/esm/helpers.js.map +1 -1
  50. package/esm/index.js +28 -10
  51. package/esm/index.js.map +1 -1
  52. package/esm/integrations/breadcrumbs.js +219 -191
  53. package/esm/integrations/breadcrumbs.js.map +1 -1
  54. package/esm/integrations/dedupe.js +180 -141
  55. package/esm/integrations/dedupe.js.map +1 -1
  56. package/esm/integrations/globalhandlers.js +209 -169
  57. package/esm/integrations/globalhandlers.js.map +1 -1
  58. package/esm/integrations/httpcontext.js +49 -0
  59. package/esm/integrations/httpcontext.js.map +1 -0
  60. package/esm/integrations/index.js +7 -7
  61. package/esm/integrations/index.js.map +1 -1
  62. package/esm/integrations/linkederrors.js +75 -45
  63. package/esm/integrations/linkederrors.js.map +1 -1
  64. package/esm/integrations/trycatch.js +242 -214
  65. package/esm/integrations/trycatch.js.map +1 -1
  66. package/esm/sdk.js +164 -105
  67. package/esm/sdk.js.map +1 -1
  68. package/esm/stack-parsers.js +126 -82
  69. package/esm/stack-parsers.js.map +1 -1
  70. package/esm/transports/fetch.js +32 -79
  71. package/esm/transports/fetch.js.map +1 -1
  72. package/esm/transports/index.js +3 -6
  73. package/esm/transports/index.js.map +1 -1
  74. package/esm/transports/utils.js +56 -51
  75. package/esm/transports/utils.js.map +1 -1
  76. package/esm/transports/xhr.js +51 -62
  77. package/esm/transports/xhr.js.map +1 -1
  78. package/package.json +4 -5
  79. package/types/client.d.ts +42 -11
  80. package/types/client.d.ts.map +1 -1
  81. package/types/eventbuilder.d.ts +10 -12
  82. package/types/eventbuilder.d.ts.map +1 -1
  83. package/types/exports.d.ts +7 -6
  84. package/types/exports.d.ts.map +1 -1
  85. package/types/helpers.d.ts +0 -5
  86. package/types/helpers.d.ts.map +1 -1
  87. package/types/index.d.ts +2 -3
  88. package/types/index.d.ts.map +1 -1
  89. package/types/integrations/breadcrumbs.d.ts +6 -7
  90. package/types/integrations/breadcrumbs.d.ts.map +1 -1
  91. package/types/integrations/dedupe.d.ts.map +1 -1
  92. package/types/integrations/globalhandlers.d.ts.map +1 -1
  93. package/types/integrations/{useragent.d.ts → httpcontext.d.ts} +3 -3
  94. package/types/integrations/httpcontext.d.ts.map +1 -0
  95. package/types/integrations/index.d.ts +1 -1
  96. package/types/integrations/index.d.ts.map +1 -1
  97. package/types/integrations/linkederrors.d.ts +3 -3
  98. package/types/integrations/linkederrors.d.ts.map +1 -1
  99. package/types/sdk.d.ts +5 -5
  100. package/types/sdk.d.ts.map +1 -1
  101. package/types/stack-parsers.d.ts +8 -6
  102. package/types/stack-parsers.d.ts.map +1 -1
  103. package/types/transports/fetch.d.ts +6 -15
  104. package/types/transports/fetch.d.ts.map +1 -1
  105. package/types/transports/index.d.ts +2 -5
  106. package/types/transports/index.d.ts.map +1 -1
  107. package/types/transports/types.d.ts +10 -0
  108. package/types/transports/types.d.ts.map +1 -0
  109. package/types/transports/utils.d.ts.map +1 -1
  110. package/types/transports/xhr.d.ts +6 -10
  111. package/types/transports/xhr.d.ts.map +1 -1
  112. package/cjs/backend.d.ts +0 -39
  113. package/cjs/backend.d.ts.map +0 -1
  114. package/cjs/backend.js +0 -58
  115. package/cjs/backend.js.map +0 -1
  116. package/cjs/client.d.ts +0 -33
  117. package/cjs/client.d.ts.map +0 -1
  118. package/cjs/eventbuilder.d.ts +0 -39
  119. package/cjs/eventbuilder.d.ts.map +0 -1
  120. package/cjs/exports.d.ts +0 -9
  121. package/cjs/exports.d.ts.map +0 -1
  122. package/cjs/flags.d.ts +0 -3
  123. package/cjs/flags.d.ts.map +0 -1
  124. package/cjs/helpers.d.ts +0 -52
  125. package/cjs/helpers.d.ts.map +0 -1
  126. package/cjs/index.d.ts +0 -16
  127. package/cjs/index.d.ts.map +0 -1
  128. package/cjs/integrations/breadcrumbs.d.ts +0 -47
  129. package/cjs/integrations/breadcrumbs.d.ts.map +0 -1
  130. package/cjs/integrations/dedupe.d.ts +0 -21
  131. package/cjs/integrations/dedupe.d.ts.map +0 -1
  132. package/cjs/integrations/globalhandlers.d.ts +0 -30
  133. package/cjs/integrations/globalhandlers.d.ts.map +0 -1
  134. package/cjs/integrations/index.d.ts +0 -7
  135. package/cjs/integrations/index.d.ts.map +0 -1
  136. package/cjs/integrations/linkederrors.d.ts +0 -42
  137. package/cjs/integrations/linkederrors.d.ts.map +0 -1
  138. package/cjs/integrations/trycatch.d.ts +0 -33
  139. package/cjs/integrations/trycatch.d.ts.map +0 -1
  140. package/cjs/integrations/useragent.d.ts +0 -17
  141. package/cjs/integrations/useragent.d.ts.map +0 -1
  142. package/cjs/integrations/useragent.js +0 -42
  143. package/cjs/integrations/useragent.js.map +0 -1
  144. package/cjs/sdk.d.ts +0 -112
  145. package/cjs/sdk.d.ts.map +0 -1
  146. package/cjs/stack-parsers.d.ts +0 -7
  147. package/cjs/stack-parsers.d.ts.map +0 -1
  148. package/cjs/transports/base.d.ts +0 -65
  149. package/cjs/transports/base.d.ts.map +0 -1
  150. package/cjs/transports/base.js +0 -141
  151. package/cjs/transports/base.js.map +0 -1
  152. package/cjs/transports/fetch.d.ts +0 -17
  153. package/cjs/transports/fetch.d.ts.map +0 -1
  154. package/cjs/transports/index.d.ts +0 -6
  155. package/cjs/transports/index.d.ts.map +0 -1
  156. package/cjs/transports/new-fetch.d.ts +0 -10
  157. package/cjs/transports/new-fetch.d.ts.map +0 -1
  158. package/cjs/transports/new-fetch.js +0 -27
  159. package/cjs/transports/new-fetch.js.map +0 -1
  160. package/cjs/transports/new-xhr.d.ts +0 -11
  161. package/cjs/transports/new-xhr.d.ts.map +0 -1
  162. package/cjs/transports/new-xhr.js +0 -46
  163. package/cjs/transports/new-xhr.js.map +0 -1
  164. package/cjs/transports/utils.d.ts +0 -48
  165. package/cjs/transports/utils.d.ts.map +0 -1
  166. package/cjs/transports/xhr.d.ts +0 -11
  167. package/cjs/transports/xhr.d.ts.map +0 -1
  168. package/cjs/version.d.ts +0 -2
  169. package/cjs/version.d.ts.map +0 -1
  170. package/cjs/version.js +0 -4
  171. package/cjs/version.js.map +0 -1
  172. package/esm/backend.d.ts +0 -39
  173. package/esm/backend.d.ts.map +0 -1
  174. package/esm/backend.js +0 -57
  175. package/esm/backend.js.map +0 -1
  176. package/esm/client.d.ts +0 -33
  177. package/esm/client.d.ts.map +0 -1
  178. package/esm/eventbuilder.d.ts +0 -39
  179. package/esm/eventbuilder.d.ts.map +0 -1
  180. package/esm/exports.d.ts +0 -9
  181. package/esm/exports.d.ts.map +0 -1
  182. package/esm/flags.d.ts +0 -3
  183. package/esm/flags.d.ts.map +0 -1
  184. package/esm/helpers.d.ts +0 -52
  185. package/esm/helpers.d.ts.map +0 -1
  186. package/esm/index.d.ts +0 -16
  187. package/esm/index.d.ts.map +0 -1
  188. package/esm/integrations/breadcrumbs.d.ts +0 -47
  189. package/esm/integrations/breadcrumbs.d.ts.map +0 -1
  190. package/esm/integrations/dedupe.d.ts +0 -21
  191. package/esm/integrations/dedupe.d.ts.map +0 -1
  192. package/esm/integrations/globalhandlers.d.ts +0 -30
  193. package/esm/integrations/globalhandlers.d.ts.map +0 -1
  194. package/esm/integrations/index.d.ts +0 -7
  195. package/esm/integrations/index.d.ts.map +0 -1
  196. package/esm/integrations/linkederrors.d.ts +0 -42
  197. package/esm/integrations/linkederrors.d.ts.map +0 -1
  198. package/esm/integrations/trycatch.d.ts +0 -33
  199. package/esm/integrations/trycatch.d.ts.map +0 -1
  200. package/esm/integrations/useragent.d.ts +0 -17
  201. package/esm/integrations/useragent.d.ts.map +0 -1
  202. package/esm/integrations/useragent.js +0 -41
  203. package/esm/integrations/useragent.js.map +0 -1
  204. package/esm/sdk.d.ts +0 -112
  205. package/esm/sdk.d.ts.map +0 -1
  206. package/esm/stack-parsers.d.ts +0 -7
  207. package/esm/stack-parsers.d.ts.map +0 -1
  208. package/esm/transports/base.d.ts +0 -65
  209. package/esm/transports/base.d.ts.map +0 -1
  210. package/esm/transports/base.js +0 -140
  211. package/esm/transports/base.js.map +0 -1
  212. package/esm/transports/fetch.d.ts +0 -17
  213. package/esm/transports/fetch.d.ts.map +0 -1
  214. package/esm/transports/index.d.ts +0 -6
  215. package/esm/transports/index.d.ts.map +0 -1
  216. package/esm/transports/new-fetch.d.ts +0 -10
  217. package/esm/transports/new-fetch.d.ts.map +0 -1
  218. package/esm/transports/new-fetch.js +0 -25
  219. package/esm/transports/new-fetch.js.map +0 -1
  220. package/esm/transports/new-xhr.d.ts +0 -11
  221. package/esm/transports/new-xhr.d.ts.map +0 -1
  222. package/esm/transports/new-xhr.js +0 -44
  223. package/esm/transports/new-xhr.js.map +0 -1
  224. package/esm/transports/utils.d.ts +0 -48
  225. package/esm/transports/utils.d.ts.map +0 -1
  226. package/esm/transports/xhr.d.ts +0 -11
  227. package/esm/transports/xhr.d.ts.map +0 -1
  228. package/esm/version.d.ts +0 -2
  229. package/esm/version.d.ts.map +0 -1
  230. package/esm/version.js +0 -3
  231. package/esm/version.js.map +0 -1
  232. package/types/backend.d.ts +0 -39
  233. package/types/backend.d.ts.map +0 -1
  234. package/types/integrations/useragent.d.ts.map +0 -1
  235. package/types/transports/base.d.ts +0 -65
  236. package/types/transports/base.d.ts.map +0 -1
  237. package/types/transports/new-fetch.d.ts +0 -10
  238. package/types/transports/new-fetch.d.ts.map +0 -1
  239. package/types/transports/new-xhr.d.ts +0 -11
  240. package/types/transports/new-xhr.d.ts.map +0 -1
  241. package/types/version.d.ts +0 -2
  242. package/types/version.d.ts.map +0 -1
@@ -1,62 +1,93 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- var tslib_1 = require("tslib");
3
- var core_1 = require("@sentry/core");
4
- var utils_1 = require("@sentry/utils");
5
- var eventbuilder_1 = require("../eventbuilder");
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ var core = require('@sentry/core');
4
+ var utils = require('@sentry/utils');
5
+ var eventbuilder = require('../eventbuilder.js');
6
+
6
7
  var DEFAULT_KEY = 'cause';
7
8
  var DEFAULT_LIMIT = 5;
9
+
8
10
  /** Adds SDK info to an event. */
9
- var LinkedErrors = /** @class */ (function () {
10
- /**
11
- * @inheritDoc
12
- */
13
- function LinkedErrors(options) {
14
- if (options === void 0) { options = {}; }
15
- /**
16
- * @inheritDoc
17
- */
18
- this.name = LinkedErrors.id;
19
- this._key = options.key || DEFAULT_KEY;
20
- this._limit = options.limit || DEFAULT_LIMIT;
11
+ class LinkedErrors {
12
+ /**
13
+ * @inheritDoc
14
+ */
15
+ static __initStatic() {this.id = 'LinkedErrors';}
16
+
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ __init() {this.name = LinkedErrors.id;}
21
+
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+
26
+
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+
31
+
32
+ /**
33
+ * @inheritDoc
34
+ */
35
+ constructor(options = {}) {;LinkedErrors.prototype.__init.call(this);
36
+ this._key = options.key || DEFAULT_KEY;
37
+ this._limit = options.limit || DEFAULT_LIMIT;
38
+ }
39
+
40
+ /**
41
+ * @inheritDoc
42
+ */
43
+ setupOnce() {
44
+ var client = core.getCurrentHub().getClient();
45
+ if (!client) {
46
+ return;
21
47
  }
22
- /**
23
- * @inheritDoc
24
- */
25
- LinkedErrors.prototype.setupOnce = function () {
26
- core_1.addGlobalEventProcessor(function (event, hint) {
27
- var self = core_1.getCurrentHub().getIntegration(LinkedErrors);
28
- return self ? _handler(self._key, self._limit, event, hint) : event;
29
- });
30
- };
31
- /**
32
- * @inheritDoc
33
- */
34
- LinkedErrors.id = 'LinkedErrors';
35
- return LinkedErrors;
36
- }());
37
- exports.LinkedErrors = LinkedErrors;
48
+ core.addGlobalEventProcessor((event, hint) => {
49
+ var self = core.getCurrentHub().getIntegration(LinkedErrors);
50
+ return self ? _handler(client.getOptions().stackParser, self._key, self._limit, event, hint) : event;
51
+ });
52
+ }
53
+ } LinkedErrors.__initStatic();
54
+
38
55
  /**
39
56
  * @inheritDoc
40
57
  */
41
- function _handler(key, limit, event, hint) {
42
- if (!event.exception || !event.exception.values || !hint || !utils_1.isInstanceOf(hint.originalException, Error)) {
43
- return event;
44
- }
45
- var linkedErrors = _walkErrorTree(limit, hint.originalException, key);
46
- event.exception.values = tslib_1.__spread(linkedErrors, event.exception.values);
58
+ function _handler(
59
+ parser,
60
+ key,
61
+ limit,
62
+ event,
63
+ hint,
64
+ ) {
65
+ if (!event.exception || !event.exception.values || !hint || !utils.isInstanceOf(hint.originalException, Error)) {
47
66
  return event;
67
+ }
68
+ var linkedErrors = _walkErrorTree(parser, limit, hint.originalException , key);
69
+ event.exception.values = [...linkedErrors, ...event.exception.values];
70
+ return event;
48
71
  }
49
- exports._handler = _handler;
72
+
50
73
  /**
51
74
  * JSDOC
52
75
  */
53
- function _walkErrorTree(limit, error, key, stack) {
54
- if (stack === void 0) { stack = []; }
55
- if (!utils_1.isInstanceOf(error[key], Error) || stack.length + 1 >= limit) {
56
- return stack;
57
- }
58
- var exception = eventbuilder_1.exceptionFromError(error[key]);
59
- return _walkErrorTree(limit, error[key], key, tslib_1.__spread([exception], stack));
76
+ function _walkErrorTree(
77
+ parser,
78
+ limit,
79
+ error,
80
+ key,
81
+ stack = [],
82
+ ) {
83
+ if (!utils.isInstanceOf(error[key], Error) || stack.length + 1 >= limit) {
84
+ return stack;
85
+ }
86
+ var exception = eventbuilder.exceptionFromError(parser, error[key]);
87
+ return _walkErrorTree(parser, limit, error[key], key, [exception, ...stack]);
60
88
  }
89
+
90
+ exports.LinkedErrors = LinkedErrors;
91
+ exports._handler = _handler;
61
92
  exports._walkErrorTree = _walkErrorTree;
62
- //# sourceMappingURL=linkederrors.js.map
93
+ //# sourceMappingURL=linkederrors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"linkederrors.js","sourceRoot":"","sources":["../../../../src/integrations/linkederrors.ts"],"names":[],"mappings":";;AAAA,qCAAsE;AAEtE,uCAA6C;AAE7C,gDAAqD;AAErD,IAAM,WAAW,GAAG,OAAO,CAAC;AAC5B,IAAM,aAAa,GAAG,CAAC,CAAC;AAOxB,iCAAiC;AACjC;IAqBE;;OAEG;IACH,sBAAmB,OAA0C;QAA1C,wBAAA,EAAA,YAA0C;QAlB7D;;WAEG;QACa,SAAI,GAAW,YAAY,CAAC,EAAE,CAAC;QAgB7C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,IAAI,WAAW,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,IAAI,aAAa,CAAC;IAC/C,CAAC;IAED;;OAEG;IACI,gCAAS,GAAhB;QACE,8BAAuB,CAAC,UAAC,KAAY,EAAE,IAAgB;YACrD,IAAM,IAAI,GAAG,oBAAa,EAAE,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;YAC1D,OAAO,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACtE,CAAC,CAAC,CAAC;IACL,CAAC;IApCD;;OAEG;IACW,eAAE,GAAW,cAAc,CAAC;IAkC5C,mBAAC;CAAA,AAtCD,IAsCC;AAtCY,oCAAY;AAwCzB;;GAEG;AACH,SAAgB,QAAQ,CAAC,GAAW,EAAE,KAAa,EAAE,KAAY,EAAE,IAAgB;IACjF,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,oBAAY,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,EAAE;QACxG,OAAO,KAAK,CAAC;KACd;IACD,IAAM,YAAY,GAAG,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,iBAAkC,EAAE,GAAG,CAAC,CAAC;IACzF,KAAK,CAAC,SAAS,CAAC,MAAM,oBAAO,YAAY,EAAK,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACtE,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,4BAOC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,KAAa,EAAE,KAAoB,EAAE,GAAW,EAAE,KAAuB;IAAvB,sBAAA,EAAA,UAAuB;IACtG,IAAI,CAAC,oBAAY,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,EAAE;QACjE,OAAO,KAAK,CAAC;KACd;IACD,IAAM,SAAS,GAAG,iCAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACjD,OAAO,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,oBAAG,SAAS,GAAK,KAAK,EAAE,CAAC;AACvE,CAAC;AAND,wCAMC","sourcesContent":["import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';\nimport { Event, EventHint, Exception, ExtendedError, Integration } from '@sentry/types';\nimport { isInstanceOf } from '@sentry/utils';\n\nimport { exceptionFromError } from '../eventbuilder';\n\nconst DEFAULT_KEY = 'cause';\nconst DEFAULT_LIMIT = 5;\n\ninterface LinkedErrorsOptions {\n key: string;\n limit: number;\n}\n\n/** Adds SDK info to an event. */\nexport class LinkedErrors implements Integration {\n /**\n * @inheritDoc\n */\n public static id: string = 'LinkedErrors';\n\n /**\n * @inheritDoc\n */\n public readonly name: string = LinkedErrors.id;\n\n /**\n * @inheritDoc\n */\n private readonly _key: LinkedErrorsOptions['key'];\n\n /**\n * @inheritDoc\n */\n private readonly _limit: LinkedErrorsOptions['limit'];\n\n /**\n * @inheritDoc\n */\n public constructor(options: Partial<LinkedErrorsOptions> = {}) {\n this._key = options.key || DEFAULT_KEY;\n this._limit = options.limit || DEFAULT_LIMIT;\n }\n\n /**\n * @inheritDoc\n */\n public setupOnce(): void {\n addGlobalEventProcessor((event: Event, hint?: EventHint) => {\n const self = getCurrentHub().getIntegration(LinkedErrors);\n return self ? _handler(self._key, self._limit, event, hint) : event;\n });\n }\n}\n\n/**\n * @inheritDoc\n */\nexport function _handler(key: string, limit: number, event: Event, hint?: EventHint): Event | null {\n if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {\n return event;\n }\n const linkedErrors = _walkErrorTree(limit, hint.originalException as ExtendedError, key);\n event.exception.values = [...linkedErrors, ...event.exception.values];\n return event;\n}\n\n/**\n * JSDOC\n */\nexport function _walkErrorTree(limit: number, error: ExtendedError, key: string, stack: Exception[] = []): Exception[] {\n if (!isInstanceOf(error[key], Error) || stack.length + 1 >= limit) {\n return stack;\n }\n const exception = exceptionFromError(error[key]);\n return _walkErrorTree(limit, error[key], key, [exception, ...stack]);\n}\n"]}
1
+ {"version":3,"file":"linkederrors.js","sources":["../../../../src/integrations/linkederrors.ts"],"sourcesContent":["import { addGlobalEventProcessor, getCurrentHub } from '@sentry/core';\nimport { Event, EventHint, Exception, ExtendedError, Integration, StackParser } from '@sentry/types';\nimport { isInstanceOf } from '@sentry/utils';\n\nimport { BrowserClient } from '../client';\nimport { exceptionFromError } from '../eventbuilder';\n\nconst DEFAULT_KEY = 'cause';\nconst DEFAULT_LIMIT = 5;\n\ninterface LinkedErrorsOptions {\n key: string;\n limit: number;\n}\n\n/** Adds SDK info to an event. */\nexport class LinkedErrors implements Integration {\n /**\n * @inheritDoc\n */\n public static id: string = 'LinkedErrors';\n\n /**\n * @inheritDoc\n */\n public readonly name: string = LinkedErrors.id;\n\n /**\n * @inheritDoc\n */\n private readonly _key: LinkedErrorsOptions['key'];\n\n /**\n * @inheritDoc\n */\n private readonly _limit: LinkedErrorsOptions['limit'];\n\n /**\n * @inheritDoc\n */\n public constructor(options: Partial<LinkedErrorsOptions> = {}) {\n this._key = options.key || DEFAULT_KEY;\n this._limit = options.limit || DEFAULT_LIMIT;\n }\n\n /**\n * @inheritDoc\n */\n public setupOnce(): void {\n const client = getCurrentHub().getClient<BrowserClient>();\n if (!client) {\n return;\n }\n addGlobalEventProcessor((event: Event, hint?: EventHint) => {\n const self = getCurrentHub().getIntegration(LinkedErrors);\n return self ? _handler(client.getOptions().stackParser, self._key, self._limit, event, hint) : event;\n });\n }\n}\n\n/**\n * @inheritDoc\n */\nexport function _handler(\n parser: StackParser,\n key: string,\n limit: number,\n event: Event,\n hint?: EventHint,\n): Event | null {\n if (!event.exception || !event.exception.values || !hint || !isInstanceOf(hint.originalException, Error)) {\n return event;\n }\n const linkedErrors = _walkErrorTree(parser, limit, hint.originalException as ExtendedError, key);\n event.exception.values = [...linkedErrors, ...event.exception.values];\n return event;\n}\n\n/**\n * JSDOC\n */\nexport function _walkErrorTree(\n parser: StackParser,\n limit: number,\n error: ExtendedError,\n key: string,\n stack: Exception[] = [],\n): Exception[] {\n if (!isInstanceOf(error[key], Error) || stack.length + 1 >= limit) {\n return stack;\n }\n const exception = exceptionFromError(parser, error[key]);\n return _walkErrorTree(parser, limit, error[key], key, [exception, ...stack]);\n}\n"],"names":[],"mappings":";;;;;;AAOA;AACA;;AAOA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;"}
@@ -1,237 +1,266 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });
2
- var tslib_1 = require("tslib");
3
- var utils_1 = require("@sentry/utils");
4
- var helpers_1 = require("../helpers");
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ var utils = require('@sentry/utils');
4
+ var helpers = require('../helpers.js');
5
+
5
6
  var DEFAULT_EVENT_TARGET = [
6
- 'EventTarget',
7
- 'Window',
8
- 'Node',
9
- 'ApplicationCache',
10
- 'AudioTrackList',
11
- 'ChannelMergerNode',
12
- 'CryptoOperation',
13
- 'EventSource',
14
- 'FileReader',
15
- 'HTMLUnknownElement',
16
- 'IDBDatabase',
17
- 'IDBRequest',
18
- 'IDBTransaction',
19
- 'KeyOperation',
20
- 'MediaController',
21
- 'MessagePort',
22
- 'ModalWindow',
23
- 'Notification',
24
- 'SVGElementInstance',
25
- 'Screen',
26
- 'TextTrack',
27
- 'TextTrackCue',
28
- 'TextTrackList',
29
- 'WebSocket',
30
- 'WebSocketWorker',
31
- 'Worker',
32
- 'XMLHttpRequest',
33
- 'XMLHttpRequestEventTarget',
34
- 'XMLHttpRequestUpload',
7
+ 'EventTarget',
8
+ 'Window',
9
+ 'Node',
10
+ 'ApplicationCache',
11
+ 'AudioTrackList',
12
+ 'ChannelMergerNode',
13
+ 'CryptoOperation',
14
+ 'EventSource',
15
+ 'FileReader',
16
+ 'HTMLUnknownElement',
17
+ 'IDBDatabase',
18
+ 'IDBRequest',
19
+ 'IDBTransaction',
20
+ 'KeyOperation',
21
+ 'MediaController',
22
+ 'MessagePort',
23
+ 'ModalWindow',
24
+ 'Notification',
25
+ 'SVGElementInstance',
26
+ 'Screen',
27
+ 'TextTrack',
28
+ 'TextTrackCue',
29
+ 'TextTrackList',
30
+ 'WebSocket',
31
+ 'WebSocketWorker',
32
+ 'Worker',
33
+ 'XMLHttpRequest',
34
+ 'XMLHttpRequestEventTarget',
35
+ 'XMLHttpRequestUpload',
35
36
  ];
37
+
36
38
  /** Wrap timer functions and event targets to catch errors and provide better meta data */
37
- var TryCatch = /** @class */ (function () {
38
- /**
39
- * @inheritDoc
40
- */
41
- function TryCatch(options) {
42
- /**
43
- * @inheritDoc
44
- */
45
- this.name = TryCatch.id;
46
- this._options = tslib_1.__assign({ XMLHttpRequest: true, eventTarget: true, requestAnimationFrame: true, setInterval: true, setTimeout: true }, options);
47
- }
48
- /**
49
- * Wrap timer functions and event targets to catch errors
50
- * and provide better metadata.
51
- */
52
- TryCatch.prototype.setupOnce = function () {
53
- var global = utils_1.getGlobalObject();
54
- if (this._options.setTimeout) {
55
- utils_1.fill(global, 'setTimeout', _wrapTimeFunction);
56
- }
57
- if (this._options.setInterval) {
58
- utils_1.fill(global, 'setInterval', _wrapTimeFunction);
59
- }
60
- if (this._options.requestAnimationFrame) {
61
- utils_1.fill(global, 'requestAnimationFrame', _wrapRAF);
62
- }
63
- if (this._options.XMLHttpRequest && 'XMLHttpRequest' in global) {
64
- utils_1.fill(XMLHttpRequest.prototype, 'send', _wrapXHR);
65
- }
66
- var eventTargetOption = this._options.eventTarget;
67
- if (eventTargetOption) {
68
- var eventTarget = Array.isArray(eventTargetOption) ? eventTargetOption : DEFAULT_EVENT_TARGET;
69
- eventTarget.forEach(_wrapEventTarget);
70
- }
39
+ class TryCatch {
40
+ /**
41
+ * @inheritDoc
42
+ */
43
+ static __initStatic() {this.id = 'TryCatch';}
44
+
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ __init() {this.name = TryCatch.id;}
49
+
50
+ /** JSDoc */
51
+
52
+
53
+ /**
54
+ * @inheritDoc
55
+ */
56
+ constructor(options) {;TryCatch.prototype.__init.call(this);
57
+ this._options = {
58
+ XMLHttpRequest: true,
59
+ eventTarget: true,
60
+ requestAnimationFrame: true,
61
+ setInterval: true,
62
+ setTimeout: true,
63
+ ...options,
71
64
  };
72
- /**
73
- * @inheritDoc
74
- */
75
- TryCatch.id = 'TryCatch';
76
- return TryCatch;
77
- }());
78
- exports.TryCatch = TryCatch;
65
+ }
66
+
67
+ /**
68
+ * Wrap timer functions and event targets to catch errors
69
+ * and provide better metadata.
70
+ */
71
+ setupOnce() {
72
+ var global = utils.getGlobalObject();
73
+
74
+ if (this._options.setTimeout) {
75
+ utils.fill(global, 'setTimeout', _wrapTimeFunction);
76
+ }
77
+
78
+ if (this._options.setInterval) {
79
+ utils.fill(global, 'setInterval', _wrapTimeFunction);
80
+ }
81
+
82
+ if (this._options.requestAnimationFrame) {
83
+ utils.fill(global, 'requestAnimationFrame', _wrapRAF);
84
+ }
85
+
86
+ if (this._options.XMLHttpRequest && 'XMLHttpRequest' in global) {
87
+ utils.fill(XMLHttpRequest.prototype, 'send', _wrapXHR);
88
+ }
89
+
90
+ var eventTargetOption = this._options.eventTarget;
91
+ if (eventTargetOption) {
92
+ var eventTarget = Array.isArray(eventTargetOption) ? eventTargetOption : DEFAULT_EVENT_TARGET;
93
+ eventTarget.forEach(_wrapEventTarget);
94
+ }
95
+ }
96
+ } TryCatch.__initStatic();
97
+
79
98
  /** JSDoc */
80
99
  function _wrapTimeFunction(original) {
81
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
- return function () {
83
- var args = [];
84
- for (var _i = 0; _i < arguments.length; _i++) {
85
- args[_i] = arguments[_i];
86
- }
87
- var originalCallback = args[0];
88
- args[0] = helpers_1.wrap(originalCallback, {
89
- mechanism: {
90
- data: { function: utils_1.getFunctionName(original) },
91
- handled: true,
92
- type: 'instrument',
93
- },
94
- });
95
- return original.apply(this, args);
96
- };
100
+ return function ( ...args) {
101
+ var originalCallback = args[0];
102
+ args[0] = helpers.wrap(originalCallback, {
103
+ mechanism: {
104
+ data: { function: utils.getFunctionName(original) },
105
+ handled: true,
106
+ type: 'instrument',
107
+ },
108
+ });
109
+ return original.apply(this, args);
110
+ };
97
111
  }
112
+
98
113
  /** JSDoc */
99
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
114
  function _wrapRAF(original) {
101
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
102
- return function (callback) {
103
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
115
+ return function ( callback) {
104
116
  return original.apply(this, [
105
- helpers_1.wrap(callback, {
106
- mechanism: {
107
- data: {
108
- function: 'requestAnimationFrame',
109
- handler: utils_1.getFunctionName(original),
110
- },
111
- handled: true,
112
- type: 'instrument',
113
- },
114
- }),
115
- ]);
116
- };
117
+ helpers.wrap(callback, {
118
+ mechanism: {
119
+ data: {
120
+ function: 'requestAnimationFrame',
121
+ handler: utils.getFunctionName(original),
122
+ },
123
+ handled: true,
124
+ type: 'instrument',
125
+ },
126
+ }),
127
+ ]);
128
+ };
117
129
  }
130
+
118
131
  /** JSDoc */
119
132
  function _wrapXHR(originalSend) {
120
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
121
- return function () {
122
- var args = [];
123
- for (var _i = 0; _i < arguments.length; _i++) {
124
- args[_i] = arguments[_i];
125
- }
126
- // eslint-disable-next-line @typescript-eslint/no-this-alias
133
+ return function ( ...args) {
127
134
  var xhr = this;
128
- var xmlHttpRequestProps = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];
129
- xmlHttpRequestProps.forEach(function (prop) {
130
- if (prop in xhr && typeof xhr[prop] === 'function') {
131
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
132
- utils_1.fill(xhr, prop, function (original) {
133
- var wrapOptions = {
134
- mechanism: {
135
- data: {
136
- function: prop,
137
- handler: utils_1.getFunctionName(original),
138
- },
139
- handled: true,
140
- type: 'instrument',
141
- },
142
- };
143
- // If Instrument integration has been called before TryCatch, get the name of original function
144
- var originalFunction = utils_1.getOriginalFunction(original);
145
- if (originalFunction) {
146
- wrapOptions.mechanism.data.handler = utils_1.getFunctionName(originalFunction);
147
- }
148
- // Otherwise wrap directly
149
- return helpers_1.wrap(original, wrapOptions);
150
- });
151
- }
135
+ var xmlHttpRequestProps = ['onload', 'onerror', 'onprogress', 'onreadystatechange'];
136
+
137
+ xmlHttpRequestProps.forEach(prop => {
138
+ if (prop in xhr && typeof xhr[prop] === 'function') {
139
+ utils.fill(xhr, prop, function (original) {
140
+ var wrapOptions = {
141
+ mechanism: {
142
+ data: {
143
+ function: prop,
144
+ handler: utils.getFunctionName(original),
145
+ },
146
+ handled: true,
147
+ type: 'instrument',
148
+ },
149
+ };
150
+
151
+ // If Instrument integration has been called before TryCatch, get the name of original function
152
+ var originalFunction = utils.getOriginalFunction(original);
153
+ if (originalFunction) {
154
+ wrapOptions.mechanism.data.handler = utils.getFunctionName(originalFunction);
155
+ }
156
+
157
+ // Otherwise wrap directly
158
+ return helpers.wrap(original, wrapOptions);
152
159
  });
153
- return originalSend.apply(this, args);
154
- };
160
+ }
161
+ });
162
+
163
+ return originalSend.apply(this, args);
164
+ };
155
165
  }
166
+
156
167
  /** JSDoc */
157
168
  function _wrapEventTarget(target) {
158
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
- var global = utils_1.getGlobalObject();
160
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
169
+ var global = utils.getGlobalObject() ;
161
170
  var proto = global[target] && global[target].prototype;
162
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins
171
+
163
172
  if (!proto || !proto.hasOwnProperty || !proto.hasOwnProperty('addEventListener')) {
164
- return;
165
- }
166
- utils_1.fill(proto, 'addEventListener', function (original) {
167
- return function (eventName, fn, options) {
168
- try {
169
- if (typeof fn.handleEvent === 'function') {
170
- fn.handleEvent = helpers_1.wrap(fn.handleEvent.bind(fn), {
171
- mechanism: {
172
- data: {
173
- function: 'handleEvent',
174
- handler: utils_1.getFunctionName(fn),
175
- target: target,
176
- },
177
- handled: true,
178
- type: 'instrument',
179
- },
180
- });
181
- }
182
- }
183
- catch (err) {
184
- // can sometimes get 'Permission denied to access property "handle Event'
185
- }
186
- return original.apply(this, [
187
- eventName,
188
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
189
- helpers_1.wrap(fn, {
190
- mechanism: {
191
- data: {
192
- function: 'addEventListener',
193
- handler: utils_1.getFunctionName(fn),
194
- target: target,
195
- },
196
- handled: true,
197
- type: 'instrument',
198
- },
199
- }),
200
- options,
201
- ]);
202
- };
203
- });
204
- utils_1.fill(proto, 'removeEventListener', function (originalRemoveEventListener) {
205
- return function (eventName, fn, options) {
206
- /**
207
- * There are 2 possible scenarios here:
208
- *
209
- * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
210
- * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
211
- * as a pass-through, and call original `removeEventListener` with it.
212
- *
213
- * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
214
- * our wrapped version of `addEventListener`, which internally calls `wrap` helper.
215
- * This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
216
- * in order for us to make a distinction between wrapped/non-wrapped functions possible.
217
- * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
218
- *
219
- * When someone adds a handler prior to initialization, and then do it again, but after,
220
- * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
221
- * to get rid of the initial handler and it'd stick there forever.
222
- */
223
- var wrappedEventHandler = fn;
224
- try {
225
- var originalEventHandler = wrappedEventHandler && wrappedEventHandler.__sentry_wrapped__;
226
- if (originalEventHandler) {
227
- originalRemoveEventListener.call(this, eventName, originalEventHandler, options);
228
- }
229
- }
230
- catch (e) {
231
- // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
232
- }
233
- return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);
234
- };
235
- });
173
+ return;
174
+ }
175
+
176
+ utils.fill(proto, 'addEventListener', function (original)
177
+
178
+ {
179
+ return function (
180
+
181
+ eventName,
182
+ fn,
183
+ options,
184
+ ) {
185
+ try {
186
+ if (typeof fn.handleEvent === 'function') {
187
+ fn.handleEvent = helpers.wrap(fn.handleEvent.bind(fn), {
188
+ mechanism: {
189
+ data: {
190
+ function: 'handleEvent',
191
+ handler: utils.getFunctionName(fn),
192
+ target,
193
+ },
194
+ handled: true,
195
+ type: 'instrument',
196
+ },
197
+ });
198
+ }
199
+ } catch (err) {
200
+ // can sometimes get 'Permission denied to access property "handle Event'
201
+ }
202
+
203
+ return original.apply(this, [
204
+ eventName,
205
+ helpers.wrap(fn , {
206
+ mechanism: {
207
+ data: {
208
+ function: 'addEventListener',
209
+ handler: utils.getFunctionName(fn),
210
+ target,
211
+ },
212
+ handled: true,
213
+ type: 'instrument',
214
+ },
215
+ }),
216
+ options,
217
+ ]);
218
+ };
219
+ });
220
+
221
+ utils.fill(
222
+ proto,
223
+ 'removeEventListener',
224
+ function (
225
+ originalRemoveEventListener,
226
+ ) {
227
+ return function (
228
+
229
+ eventName,
230
+ fn,
231
+ options,
232
+ ) {
233
+ /**
234
+ * There are 2 possible scenarios here:
235
+ *
236
+ * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
237
+ * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
238
+ * as a pass-through, and call original `removeEventListener` with it.
239
+ *
240
+ * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
241
+ * our wrapped version of `addEventListener`, which internally calls `wrap` helper.
242
+ * This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
243
+ * in order for us to make a distinction between wrapped/non-wrapped functions possible.
244
+ * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
245
+ *
246
+ * When someone adds a handler prior to initialization, and then do it again, but after,
247
+ * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
248
+ * to get rid of the initial handler and it'd stick there forever.
249
+ */
250
+ var wrappedEventHandler = fn ;
251
+ try {
252
+ var originalEventHandler = wrappedEventHandler && wrappedEventHandler.__sentry_wrapped__;
253
+ if (originalEventHandler) {
254
+ originalRemoveEventListener.call(this, eventName, originalEventHandler, options);
255
+ }
256
+ } catch (e) {
257
+ // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
258
+ }
259
+ return originalRemoveEventListener.call(this, eventName, wrappedEventHandler, options);
260
+ };
261
+ },
262
+ );
236
263
  }
237
- //# sourceMappingURL=trycatch.js.map
264
+
265
+ exports.TryCatch = TryCatch;
266
+ //# sourceMappingURL=trycatch.js.map