@sentry/browser 7.0.0-beta.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 (186) hide show
  1. package/README.md +2 -3
  2. package/cjs/client.js +125 -102
  3. package/cjs/client.js.map +1 -1
  4. package/cjs/eventbuilder.js +225 -165
  5. package/cjs/eventbuilder.js.map +1 -1
  6. package/cjs/exports.js +55 -59
  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 -96
  11. package/cjs/helpers.js.map +1 -1
  12. package/cjs/index.js +77 -10
  13. package/cjs/index.js.map +1 -1
  14. package/cjs/integrations/breadcrumbs.js +222 -174
  15. package/cjs/integrations/breadcrumbs.js.map +1 -1
  16. package/cjs/integrations/dedupe.js +184 -142
  17. package/cjs/integrations/dedupe.js.map +1 -1
  18. package/cjs/integrations/globalhandlers.js +211 -170
  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 +81 -50
  25. package/cjs/integrations/linkederrors.js.map +1 -1
  26. package/cjs/integrations/trycatch.js +247 -208
  27. package/cjs/integrations/trycatch.js.map +1 -1
  28. package/cjs/sdk.js +166 -125
  29. package/cjs/sdk.js.map +1 -1
  30. package/cjs/stack-parsers.js +143 -93
  31. package/cjs/stack-parsers.js.map +1 -1
  32. package/cjs/transports/fetch.js +30 -15
  33. package/cjs/transports/fetch.js.map +1 -1
  34. package/cjs/transports/index.js +10 -6
  35. package/cjs/transports/index.js.map +1 -1
  36. package/cjs/transports/utils.js +56 -51
  37. package/cjs/transports/utils.js.map +1 -1
  38. package/cjs/transports/xhr.js +40 -30
  39. package/cjs/transports/xhr.js.map +1 -1
  40. package/esm/client.js +124 -101
  41. package/esm/client.js.map +1 -1
  42. package/esm/eventbuilder.js +218 -158
  43. package/esm/eventbuilder.js.map +1 -1
  44. package/esm/exports.js +12 -8
  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 +122 -95
  49. package/esm/helpers.js.map +1 -1
  50. package/esm/index.js +27 -7
  51. package/esm/index.js.map +1 -1
  52. package/esm/integrations/breadcrumbs.js +218 -171
  53. package/esm/integrations/breadcrumbs.js.map +1 -1
  54. package/esm/integrations/dedupe.js +181 -139
  55. package/esm/integrations/dedupe.js.map +1 -1
  56. package/esm/integrations/globalhandlers.js +208 -167
  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 +77 -46
  63. package/esm/integrations/linkederrors.js.map +1 -1
  64. package/esm/integrations/trycatch.js +244 -205
  65. package/esm/integrations/trycatch.js.map +1 -1
  66. package/esm/sdk.js +163 -123
  67. package/esm/sdk.js.map +1 -1
  68. package/esm/stack-parsers.js +134 -91
  69. package/esm/stack-parsers.js.map +1 -1
  70. package/esm/transports/fetch.js +28 -13
  71. package/esm/transports/fetch.js.map +1 -1
  72. package/esm/transports/index.js +3 -3
  73. package/esm/transports/index.js.map +1 -1
  74. package/esm/transports/utils.js +55 -50
  75. package/esm/transports/utils.js.map +1 -1
  76. package/esm/transports/xhr.js +38 -28
  77. package/esm/transports/xhr.js.map +1 -1
  78. package/package.json +4 -4
  79. package/types/client.d.ts +3 -2
  80. package/types/client.d.ts.map +1 -1
  81. package/types/exports.d.ts +3 -4
  82. package/types/exports.d.ts.map +1 -1
  83. package/types/index.d.ts +1 -1
  84. package/types/integrations/{useragent.d.ts → httpcontext.d.ts} +3 -3
  85. package/types/integrations/httpcontext.d.ts.map +1 -0
  86. package/types/integrations/index.d.ts +1 -1
  87. package/types/integrations/index.d.ts.map +1 -1
  88. package/types/sdk.d.ts +2 -2
  89. package/types/sdk.d.ts.map +1 -1
  90. package/types/transports/fetch.d.ts +3 -5
  91. package/types/transports/fetch.d.ts.map +1 -1
  92. package/types/transports/types.d.ts +10 -0
  93. package/types/transports/types.d.ts.map +1 -0
  94. package/types/transports/xhr.d.ts +3 -7
  95. package/types/transports/xhr.d.ts.map +1 -1
  96. package/cjs/client.d.ts +0 -63
  97. package/cjs/client.d.ts.map +0 -1
  98. package/cjs/eventbuilder.d.ts +0 -37
  99. package/cjs/eventbuilder.d.ts.map +0 -1
  100. package/cjs/exports.d.ts +0 -11
  101. package/cjs/exports.d.ts.map +0 -1
  102. package/cjs/flags.d.ts +0 -3
  103. package/cjs/flags.d.ts.map +0 -1
  104. package/cjs/helpers.d.ts +0 -47
  105. package/cjs/helpers.d.ts.map +0 -1
  106. package/cjs/index.d.ts +0 -15
  107. package/cjs/index.d.ts.map +0 -1
  108. package/cjs/integrations/breadcrumbs.d.ts +0 -46
  109. package/cjs/integrations/breadcrumbs.d.ts.map +0 -1
  110. package/cjs/integrations/dedupe.d.ts +0 -21
  111. package/cjs/integrations/dedupe.d.ts.map +0 -1
  112. package/cjs/integrations/globalhandlers.d.ts +0 -30
  113. package/cjs/integrations/globalhandlers.d.ts.map +0 -1
  114. package/cjs/integrations/index.d.ts +0 -7
  115. package/cjs/integrations/index.d.ts.map +0 -1
  116. package/cjs/integrations/linkederrors.d.ts +0 -42
  117. package/cjs/integrations/linkederrors.d.ts.map +0 -1
  118. package/cjs/integrations/trycatch.d.ts +0 -33
  119. package/cjs/integrations/trycatch.d.ts.map +0 -1
  120. package/cjs/integrations/useragent.d.ts +0 -17
  121. package/cjs/integrations/useragent.d.ts.map +0 -1
  122. package/cjs/integrations/useragent.js +0 -40
  123. package/cjs/integrations/useragent.js.map +0 -1
  124. package/cjs/sdk.d.ts +0 -112
  125. package/cjs/sdk.d.ts.map +0 -1
  126. package/cjs/stack-parsers.d.ts +0 -9
  127. package/cjs/stack-parsers.d.ts.map +0 -1
  128. package/cjs/transports/fetch.d.ts +0 -10
  129. package/cjs/transports/fetch.d.ts.map +0 -1
  130. package/cjs/transports/index.d.ts +0 -3
  131. package/cjs/transports/index.d.ts.map +0 -1
  132. package/cjs/transports/utils.d.ts +0 -48
  133. package/cjs/transports/utils.d.ts.map +0 -1
  134. package/cjs/transports/xhr.d.ts +0 -11
  135. package/cjs/transports/xhr.d.ts.map +0 -1
  136. package/cjs/version.d.ts +0 -2
  137. package/cjs/version.d.ts.map +0 -1
  138. package/cjs/version.js +0 -4
  139. package/cjs/version.js.map +0 -1
  140. package/esm/client.d.ts +0 -63
  141. package/esm/client.d.ts.map +0 -1
  142. package/esm/eventbuilder.d.ts +0 -37
  143. package/esm/eventbuilder.d.ts.map +0 -1
  144. package/esm/exports.d.ts +0 -11
  145. package/esm/exports.d.ts.map +0 -1
  146. package/esm/flags.d.ts +0 -3
  147. package/esm/flags.d.ts.map +0 -1
  148. package/esm/helpers.d.ts +0 -47
  149. package/esm/helpers.d.ts.map +0 -1
  150. package/esm/index.d.ts +0 -15
  151. package/esm/index.d.ts.map +0 -1
  152. package/esm/integrations/breadcrumbs.d.ts +0 -46
  153. package/esm/integrations/breadcrumbs.d.ts.map +0 -1
  154. package/esm/integrations/dedupe.d.ts +0 -21
  155. package/esm/integrations/dedupe.d.ts.map +0 -1
  156. package/esm/integrations/globalhandlers.d.ts +0 -30
  157. package/esm/integrations/globalhandlers.d.ts.map +0 -1
  158. package/esm/integrations/index.d.ts +0 -7
  159. package/esm/integrations/index.d.ts.map +0 -1
  160. package/esm/integrations/linkederrors.d.ts +0 -42
  161. package/esm/integrations/linkederrors.d.ts.map +0 -1
  162. package/esm/integrations/trycatch.d.ts +0 -33
  163. package/esm/integrations/trycatch.d.ts.map +0 -1
  164. package/esm/integrations/useragent.d.ts +0 -17
  165. package/esm/integrations/useragent.d.ts.map +0 -1
  166. package/esm/integrations/useragent.js +0 -38
  167. package/esm/integrations/useragent.js.map +0 -1
  168. package/esm/sdk.d.ts +0 -112
  169. package/esm/sdk.d.ts.map +0 -1
  170. package/esm/stack-parsers.d.ts +0 -9
  171. package/esm/stack-parsers.d.ts.map +0 -1
  172. package/esm/transports/fetch.d.ts +0 -10
  173. package/esm/transports/fetch.d.ts.map +0 -1
  174. package/esm/transports/index.d.ts +0 -3
  175. package/esm/transports/index.d.ts.map +0 -1
  176. package/esm/transports/utils.d.ts +0 -48
  177. package/esm/transports/utils.d.ts.map +0 -1
  178. package/esm/transports/xhr.d.ts +0 -11
  179. package/esm/transports/xhr.d.ts.map +0 -1
  180. package/esm/version.d.ts +0 -2
  181. package/esm/version.d.ts.map +0 -1
  182. package/esm/version.js +0 -3
  183. package/esm/version.js.map +0 -1
  184. package/types/integrations/useragent.d.ts.map +0 -1
  185. package/types/version.d.ts +0 -2
  186. package/types/version.d.ts.map +0 -1
@@ -1,209 +1,269 @@
1
- import { addExceptionMechanism, addExceptionTypeValue, extractExceptionKeysForMessage, isDOMError, isDOMException, isError, isErrorEvent, isEvent, isPlainObject, normalizeToSize, resolvedSyncPromise, } from '@sentry/utils';
1
+ import { isEvent, extractExceptionKeysForMessage, normalizeToSize, addExceptionMechanism, resolvedSyncPromise, isErrorEvent, isDOMError, isDOMException, addExceptionTypeValue, isError, isPlainObject } from '@sentry/utils';
2
+
2
3
  /**
3
4
  * This function creates an exception from a JavaScript Error
4
5
  */
5
- export function exceptionFromError(stackParser, ex) {
6
- // Get the frames first since Opera can lose the stack if we touch anything else first
7
- const frames = parseStackFrames(stackParser, ex);
8
- const exception = {
9
- type: ex && ex.name,
10
- value: extractMessage(ex),
11
- };
12
- if (frames.length) {
13
- exception.stacktrace = { frames };
14
- }
15
- if (exception.type === undefined && exception.value === '') {
16
- exception.value = 'Unrecoverable error caught';
17
- }
18
- return exception;
6
+ function exceptionFromError(stackParser, ex) {
7
+ // Get the frames first since Opera can lose the stack if we touch anything else first
8
+ var frames = parseStackFrames(stackParser, ex);
9
+
10
+ var exception = {
11
+ type: ex && ex.name,
12
+ value: extractMessage(ex),
13
+ };
14
+
15
+ if (frames.length) {
16
+ exception.stacktrace = { frames };
17
+ }
18
+
19
+ if (exception.type === undefined && exception.value === '') {
20
+ exception.value = 'Unrecoverable error caught';
21
+ }
22
+
23
+ return exception;
19
24
  }
25
+
20
26
  /**
21
27
  * @hidden
22
28
  */
23
- export function eventFromPlainObject(stackParser, exception, syntheticException, isUnhandledRejection) {
24
- const event = {
25
- exception: {
26
- values: [
27
- {
28
- type: isEvent(exception) ? exception.constructor.name : isUnhandledRejection ? 'UnhandledRejection' : 'Error',
29
- value: `Non-Error ${isUnhandledRejection ? 'promise rejection' : 'exception'} captured with keys: ${extractExceptionKeysForMessage(exception)}`,
30
- },
31
- ],
29
+ function eventFromPlainObject(
30
+ stackParser,
31
+ exception,
32
+ syntheticException,
33
+ isUnhandledRejection,
34
+ ) {
35
+ var event = {
36
+ exception: {
37
+ values: [
38
+ {
39
+ type: isEvent(exception) ? exception.constructor.name : isUnhandledRejection ? 'UnhandledRejection' : 'Error',
40
+ value: `Non-Error ${
41
+ isUnhandledRejection ? 'promise rejection' : 'exception'
42
+ } captured with keys: ${extractExceptionKeysForMessage(exception)}`,
32
43
  },
33
- extra: {
34
- __serialized__: normalizeToSize(exception),
35
- },
36
- };
37
- if (syntheticException) {
38
- const frames = parseStackFrames(stackParser, syntheticException);
39
- if (frames.length) {
40
- // event.exception.values[0] has been set above
41
- event.exception.values[0].stacktrace = { frames };
42
- }
44
+ ],
45
+ },
46
+ extra: {
47
+ __serialized__: normalizeToSize(exception),
48
+ },
49
+ };
50
+
51
+ if (syntheticException) {
52
+ var frames = parseStackFrames(stackParser, syntheticException);
53
+ if (frames.length) {
54
+ // event.exception.values[0] has been set above
55
+ (event.exception ).values[0].stacktrace = { frames };
43
56
  }
44
- return event;
57
+ }
58
+
59
+ return event;
45
60
  }
61
+
46
62
  /**
47
63
  * @hidden
48
64
  */
49
- export function eventFromError(stackParser, ex) {
50
- return {
51
- exception: {
52
- values: [exceptionFromError(stackParser, ex)],
53
- },
54
- };
65
+ function eventFromError(stackParser, ex) {
66
+ return {
67
+ exception: {
68
+ values: [exceptionFromError(stackParser, ex)],
69
+ },
70
+ };
55
71
  }
72
+
56
73
  /** Parses stack frames from an error */
57
- export function parseStackFrames(stackParser, ex) {
58
- // Access and store the stacktrace property before doing ANYTHING
59
- // else to it because Opera is not very good at providing it
60
- // reliably in other circumstances.
61
- const stacktrace = ex.stacktrace || ex.stack || '';
62
- const popSize = getPopSize(ex);
63
- try {
64
- return stackParser(stacktrace, popSize);
65
- }
66
- catch (e) {
67
- // no-empty
68
- }
69
- return [];
74
+ function parseStackFrames(
75
+ stackParser,
76
+ ex,
77
+ ) {
78
+ // Access and store the stacktrace property before doing ANYTHING
79
+ // else to it because Opera is not very good at providing it
80
+ // reliably in other circumstances.
81
+ var stacktrace = ex.stacktrace || ex.stack || '';
82
+
83
+ var popSize = getPopSize(ex);
84
+
85
+ try {
86
+ return stackParser(stacktrace, popSize);
87
+ } catch (e) {
88
+ // no-empty
89
+ }
90
+
91
+ return [];
70
92
  }
93
+
71
94
  // Based on our own mapping pattern - https://github.com/getsentry/sentry/blob/9f08305e09866c8bd6d0c24f5b0aabdd7dd6c59c/src/sentry/lang/javascript/errormapping.py#L83-L108
72
- const reactMinifiedRegexp = /Minified React error #\d+;/i;
95
+ var reactMinifiedRegexp = /Minified React error #\d+;/i;
96
+
73
97
  function getPopSize(ex) {
74
- if (ex) {
75
- if (typeof ex.framesToPop === 'number') {
76
- return ex.framesToPop;
77
- }
78
- if (reactMinifiedRegexp.test(ex.message)) {
79
- return 1;
80
- }
98
+ if (ex) {
99
+ if (typeof ex.framesToPop === 'number') {
100
+ return ex.framesToPop;
101
+ }
102
+
103
+ if (reactMinifiedRegexp.test(ex.message)) {
104
+ return 1;
81
105
  }
82
- return 0;
106
+ }
107
+
108
+ return 0;
83
109
  }
110
+
84
111
  /**
85
112
  * There are cases where stacktrace.message is an Event object
86
113
  * https://github.com/getsentry/sentry-javascript/issues/1949
87
114
  * In this specific case we try to extract stacktrace.message.error.message
88
115
  */
89
116
  function extractMessage(ex) {
90
- const message = ex && ex.message;
91
- if (!message) {
92
- return 'No error message';
93
- }
94
- if (message.error && typeof message.error.message === 'string') {
95
- return message.error.message;
96
- }
97
- return message;
117
+ var message = ex && ex.message;
118
+ if (!message) {
119
+ return 'No error message';
120
+ }
121
+ if (message.error && typeof message.error.message === 'string') {
122
+ return message.error.message;
123
+ }
124
+ return message;
98
125
  }
126
+
99
127
  /**
100
128
  * Creates an {@link Event} from all inputs to `captureException` and non-primitive inputs to `captureMessage`.
101
129
  * @hidden
102
130
  */
103
- export function eventFromException(stackParser, exception, hint, attachStacktrace) {
104
- const syntheticException = (hint && hint.syntheticException) || undefined;
105
- const event = eventFromUnknownInput(stackParser, exception, syntheticException, attachStacktrace);
106
- addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
107
- event.level = 'error';
108
- if (hint && hint.event_id) {
109
- event.event_id = hint.event_id;
110
- }
111
- return resolvedSyncPromise(event);
131
+ function eventFromException(
132
+ stackParser,
133
+ exception,
134
+ hint,
135
+ attachStacktrace,
136
+ ) {
137
+ var syntheticException = (hint && hint.syntheticException) || undefined;
138
+ var event = eventFromUnknownInput(stackParser, exception, syntheticException, attachStacktrace);
139
+ addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }
140
+ event.level = 'error';
141
+ if (hint && hint.event_id) {
142
+ event.event_id = hint.event_id;
143
+ }
144
+ return resolvedSyncPromise(event);
112
145
  }
146
+
113
147
  /**
114
148
  * Builds and Event from a Message
115
149
  * @hidden
116
150
  */
117
- export function eventFromMessage(stackParser, message,
118
- // eslint-disable-next-line deprecation/deprecation
119
- level = 'info', hint, attachStacktrace) {
120
- const syntheticException = (hint && hint.syntheticException) || undefined;
121
- const event = eventFromString(stackParser, message, syntheticException, attachStacktrace);
122
- event.level = level;
123
- if (hint && hint.event_id) {
124
- event.event_id = hint.event_id;
125
- }
126
- return resolvedSyncPromise(event);
151
+ function eventFromMessage(
152
+ stackParser,
153
+ message,
154
+ level = 'info',
155
+ hint,
156
+ attachStacktrace,
157
+ ) {
158
+ var syntheticException = (hint && hint.syntheticException) || undefined;
159
+ var event = eventFromString(stackParser, message, syntheticException, attachStacktrace);
160
+ event.level = level;
161
+ if (hint && hint.event_id) {
162
+ event.event_id = hint.event_id;
163
+ }
164
+ return resolvedSyncPromise(event);
127
165
  }
166
+
128
167
  /**
129
168
  * @hidden
130
169
  */
131
- export function eventFromUnknownInput(stackParser, exception, syntheticException, attachStacktrace, isUnhandledRejection) {
132
- let event;
133
- if (isErrorEvent(exception) && exception.error) {
134
- // If it is an ErrorEvent with `error` property, extract it to get actual Error
135
- const errorEvent = exception;
136
- return eventFromError(stackParser, errorEvent.error);
137
- }
138
- // If it is a `DOMError` (which is a legacy API, but still supported in some browsers) then we just extract the name
139
- // and message, as it doesn't provide anything else. According to the spec, all `DOMExceptions` should also be
140
- // `Error`s, but that's not the case in IE11, so in that case we treat it the same as we do a `DOMError`.
141
- //
142
- // https://developer.mozilla.org/en-US/docs/Web/API/DOMError
143
- // https://developer.mozilla.org/en-US/docs/Web/API/DOMException
144
- // https://webidl.spec.whatwg.org/#es-DOMException-specialness
145
- if (isDOMError(exception) || isDOMException(exception)) {
146
- const domException = exception;
147
- if ('stack' in exception) {
148
- event = eventFromError(stackParser, exception);
149
- }
150
- else {
151
- const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException');
152
- const message = domException.message ? `${name}: ${domException.message}` : name;
153
- event = eventFromString(stackParser, message, syntheticException, attachStacktrace);
154
- addExceptionTypeValue(event, message);
155
- }
156
- if ('code' in domException) {
157
- event.tags = Object.assign(Object.assign({}, event.tags), { 'DOMException.code': `${domException.code}` });
158
- }
159
- return event;
170
+ function eventFromUnknownInput(
171
+ stackParser,
172
+ exception,
173
+ syntheticException,
174
+ attachStacktrace,
175
+ isUnhandledRejection,
176
+ ) {
177
+ let event;
178
+
179
+ if (isErrorEvent(exception ) && (exception ).error) {
180
+ // If it is an ErrorEvent with `error` property, extract it to get actual Error
181
+ var errorEvent = exception ;
182
+ return eventFromError(stackParser, errorEvent.error );
183
+ }
184
+
185
+ // If it is a `DOMError` (which is a legacy API, but still supported in some browsers) then we just extract the name
186
+ // and message, as it doesn't provide anything else. According to the spec, all `DOMExceptions` should also be
187
+ // `Error`s, but that's not the case in IE11, so in that case we treat it the same as we do a `DOMError`.
188
+ //
189
+ // https://developer.mozilla.org/en-US/docs/Web/API/DOMError
190
+ // https://developer.mozilla.org/en-US/docs/Web/API/DOMException
191
+ // https://webidl.spec.whatwg.org/#es-DOMException-specialness
192
+ if (isDOMError(exception ) || isDOMException(exception )) {
193
+ var domException = exception ;
194
+
195
+ if ('stack' in (exception )) {
196
+ event = eventFromError(stackParser, exception );
197
+ } else {
198
+ var name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException');
199
+ var message = domException.message ? `${name}: ${domException.message}` : name;
200
+ event = eventFromString(stackParser, message, syntheticException, attachStacktrace);
201
+ addExceptionTypeValue(event, message);
160
202
  }
161
- if (isError(exception)) {
162
- // we have a real Error object, do nothing
163
- return eventFromError(stackParser, exception);
203
+ if ('code' in domException) {
204
+ event.tags = { ...event.tags, 'DOMException.code': `${domException.code}` };
164
205
  }
165
- if (isPlainObject(exception) || isEvent(exception)) {
166
- // If it's a plain object or an instance of `Event` (the built-in JS kind, not this SDK's `Event` type), serialize
167
- // it manually. This will allow us to group events based on top-level keys which is much better than creating a new
168
- // group on any key/value change.
169
- const objectException = exception;
170
- event = eventFromPlainObject(stackParser, objectException, syntheticException, isUnhandledRejection);
171
- addExceptionMechanism(event, {
172
- synthetic: true,
173
- });
174
- return event;
175
- }
176
- // If none of previous checks were valid, then it means that it's not:
177
- // - an instance of DOMError
178
- // - an instance of DOMException
179
- // - an instance of Event
180
- // - an instance of Error
181
- // - a valid ErrorEvent (one with an error property)
182
- // - a plain Object
183
- //
184
- // So bail out and capture it as a simple message:
185
- event = eventFromString(stackParser, exception, syntheticException, attachStacktrace);
186
- addExceptionTypeValue(event, `${exception}`, undefined);
206
+
207
+ return event;
208
+ }
209
+ if (isError(exception)) {
210
+ // we have a real Error object, do nothing
211
+ return eventFromError(stackParser, exception);
212
+ }
213
+ if (isPlainObject(exception) || isEvent(exception)) {
214
+ // If it's a plain object or an instance of `Event` (the built-in JS kind, not this SDK's `Event` type), serialize
215
+ // it manually. This will allow us to group events based on top-level keys which is much better than creating a new
216
+ // group on any key/value change.
217
+ var objectException = exception ;
218
+ event = eventFromPlainObject(stackParser, objectException, syntheticException, isUnhandledRejection);
187
219
  addExceptionMechanism(event, {
188
- synthetic: true,
220
+ synthetic: true,
189
221
  });
190
222
  return event;
223
+ }
224
+
225
+ // If none of previous checks were valid, then it means that it's not:
226
+ // - an instance of DOMError
227
+ // - an instance of DOMException
228
+ // - an instance of Event
229
+ // - an instance of Error
230
+ // - a valid ErrorEvent (one with an error property)
231
+ // - a plain Object
232
+ //
233
+ // So bail out and capture it as a simple message:
234
+ event = eventFromString(stackParser, exception , syntheticException, attachStacktrace);
235
+ addExceptionTypeValue(event, `${exception}`, undefined);
236
+ addExceptionMechanism(event, {
237
+ synthetic: true,
238
+ });
239
+
240
+ return event;
191
241
  }
242
+
192
243
  /**
193
244
  * @hidden
194
245
  */
195
- export function eventFromString(stackParser, input, syntheticException, attachStacktrace) {
196
- const event = {
197
- message: input,
198
- };
199
- if (attachStacktrace && syntheticException) {
200
- const frames = parseStackFrames(stackParser, syntheticException);
201
- if (frames.length) {
202
- event.exception = {
203
- values: [{ value: input, stacktrace: { frames } }],
204
- };
205
- }
246
+ function eventFromString(
247
+ stackParser,
248
+ input,
249
+ syntheticException,
250
+ attachStacktrace,
251
+ ) {
252
+ var event = {
253
+ message: input,
254
+ };
255
+
256
+ if (attachStacktrace && syntheticException) {
257
+ var frames = parseStackFrames(stackParser, syntheticException);
258
+ if (frames.length) {
259
+ event.exception = {
260
+ values: [{ value: input, stacktrace: { frames } }],
261
+ };
206
262
  }
207
- return event;
263
+ }
264
+
265
+ return event;
208
266
  }
209
- //# sourceMappingURL=eventbuilder.js.map
267
+
268
+ export { eventFromError, eventFromException, eventFromMessage, eventFromPlainObject, eventFromString, eventFromUnknownInput, exceptionFromError, parseStackFrames };
269
+ //# sourceMappingURL=eventbuilder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"eventbuilder.js","sourceRoot":"","sources":["../../../src/eventbuilder.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,8BAA8B,EAC9B,UAAU,EACV,cAAc,EACd,OAAO,EACP,YAAY,EACZ,OAAO,EACP,aAAa,EACb,eAAe,EACf,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAEvB;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAwB,EAAE,EAAS;IACpE,sFAAsF;IACtF,MAAM,MAAM,GAAG,gBAAgB,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAEjD,MAAM,SAAS,GAAc;QAC3B,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,IAAI;QACnB,KAAK,EAAE,cAAc,CAAC,EAAE,CAAC;KAC1B,CAAC;IAEF,IAAI,MAAM,CAAC,MAAM,EAAE;QACjB,SAAS,CAAC,UAAU,GAAG,EAAE,MAAM,EAAE,CAAC;KACnC;IAED,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,IAAI,SAAS,CAAC,KAAK,KAAK,EAAE,EAAE;QAC1D,SAAS,CAAC,KAAK,GAAG,4BAA4B,CAAC;KAChD;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,WAAwB,EACxB,SAAkC,EAClC,kBAA0B,EAC1B,oBAA8B;IAE9B,MAAM,KAAK,GAAU;QACnB,SAAS,EAAE;YACT,MAAM,EAAE;gBACN;oBACE,IAAI,EAAE,O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AgB,CAAC,CAAC;IAChG,qBAAqB,CAAC,KAAK,EAAE,GAAG,SAAS,EAAE,EAAE,SAAS,CAAC,CAAC;IACxD,qBAAqB,CAAC,KAAK,EAAE;QAC3B,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAC7B,WAAwB,EACxB,KAAa,EACb,kBAA0B,EAC1B,gBAA0B;IAE1B,MAAM,KAAK,GAAU;QACnB,OAAO,EAAE,KAAK;KACf,CAAC;IAEF,IAAI,gBAAgB,IAAI,kBAAkB,EAAE;QAC1C,MAAM,MAAM,GAAG,gBAAgB,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;QACjE,IAAI,MAAM,CAAC,MAAM,EAAE;YACjB,KAAK,CAAC,SAAS,GAAG;gBAChB,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC;aACnD,CAAC;SACH;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { Event, EventHint, Exception, Severity, SeverityLevel, StackFrame, StackParser } from '@sentry/types';\nimport {\n addExceptionMechanism,\n addExceptionTypeValue,\n extractExceptionKeysForMessage,\n isDOMError,\n isDOMException,\n isError,\n isErrorEvent,\n isEvent,\n isPlainObject,\n normalizeToSize,\n resolvedSyncPromise,\n} from '@sentry/utils';\n\n/**\n * This function creates an exception from a JavaScript Error\n */\nexport function exceptionFromError(stackParser: StackParser, ex: Error): Exception {\n // Get the frames first since Opera can lose the stack if we touch anything else first\n const frames = parseStackFrames(stackParser, ex);\n\n const exception: Exception = {\n type: ex && ex.name,\n value: extractMessage(ex),\n };\n\n if (frames.length) {\n exception.stacktrace = { frames };\n }\n\n if (exception.type === undefined && exception.value === '') {\n exception.value = 'Unrecoverable error caught';\n }\n\n return exception;\n}\n\n/**\n * @hidden\n */\nexport function eventFromPlainObject(\n stackParser: StackParser,\n exception: Record<string, unknown>,\n syntheticException?: Error,\n isUnhandledRejection?: boolean,\n): Event {\n const event: Event = {\n exception: {\n values: [\n {\n type: isEvent(exception) ? exception.constructor.name : isUnhandledRejection ? 'UnhandledRejection' : 'Error',\n value: `Non-Error ${\n isUnhandledRejection ? 'promise rejection' : 'exception'\n } captured with keys: ${extractExceptionKeysForMessage(exception)}`,\n },\n ],\n },\n extra: {\n __serialized__: normalizeToSize(exception),\n },\n };\n\n if (syntheticException) {\n const frames = parseStackFrames(stackParser, syntheticException);\n if (frames.length) {\n // event.exception.values[0] has been set above\n (event.exception as { values: Exception[] }).values[0].stacktrace = { frames };\n }\n }\n\n return event;\n}\n\n/**\n * @hidden\n */\nexport function eventFromError(stackParser: StackParser, ex: Error): Event {\n return {\n exception: {\n values: [exceptionFromError(stackParser, ex)],\n },\n };\n}\n\n/** Parses stack frames from an error */\nexport function parseStackFrames(\n stackParser: StackParser,\n ex: Error & { framesToPop?: number; stacktrace?: string },\n): StackFrame[] {\n // Access and store the stacktrace property before doing ANYTHING\n // else to it because Opera is not very good at providing it\n // reliably in other circumstances.\n const stacktrace = ex.stacktrace || ex.stack || '';\n\n const popSize = getPopSize(ex);\n\n try {\n return stackParser(stacktrace, popSize);\n } catch (e) {\n // no-empty\n }\n\n return [];\n}\n\n// Based on our own mapping pattern - https://github.com/getsentry/sentry/blob/9f08305e09866c8bd6d0c24f5b0aabdd7dd6c59c/src/sentry/lang/javascript/errormapping.py#L83-L108\nconst reactMinifiedRegexp = /Minified React error #\\d+;/i;\n\nfunction getPopSize(ex: Error & { framesToPop?: number }): number {\n if (ex) {\n if (typeof ex.framesToPop === 'number') {\n return ex.framesToPop;\n }\n\n if (reactMinifiedRegexp.test(ex.message)) {\n return 1;\n }\n }\n\n return 0;\n}\n\n/**\n * There are cases where stacktrace.message is an Event object\n * https://github.com/getsentry/sentry-javascript/issues/1949\n * In this specific case we try to extract stacktrace.message.error.message\n */\nfunction extractMessage(ex: Error & { message: { error?: Error } }): string {\n const message = ex && ex.message;\n if (!message) {\n return 'No error message';\n }\n if (message.error && typeof message.error.message === 'string') {\n return message.error.message;\n }\n return message;\n}\n\n/**\n * Creates an {@link Event} from all inputs to `captureException` and non-primitive inputs to `captureMessage`.\n * @hidden\n */\nexport function eventFromException(\n stackParser: StackParser,\n exception: unknown,\n hint?: EventHint,\n attachStacktrace?: boolean,\n): PromiseLike<Event> {\n const syntheticException = (hint && hint.syntheticException) || undefined;\n const event = eventFromUnknownInput(stackParser, exception, syntheticException, attachStacktrace);\n addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }\n event.level = 'error';\n if (hint && hint.event_id) {\n event.event_id = hint.event_id;\n }\n return resolvedSyncPromise(event);\n}\n\n/**\n * Builds and Event from a Message\n * @hidden\n */\nexport function eventFromMessage(\n stackParser: StackParser,\n message: string,\n // eslint-disable-next-line deprecation/deprecation\n level: Severity | SeverityLevel = 'info',\n hint?: EventHint,\n attachStacktrace?: boolean,\n): PromiseLike<Event> {\n const syntheticException = (hint && hint.syntheticException) || undefined;\n const event = eventFromString(stackParser, message, syntheticException, attachStacktrace);\n event.level = level;\n if (hint && hint.event_id) {\n event.event_id = hint.event_id;\n }\n return resolvedSyncPromise(event);\n}\n\n/**\n * @hidden\n */\nexport function eventFromUnknownInput(\n stackParser: StackParser,\n exception: unknown,\n syntheticException?: Error,\n attachStacktrace?: boolean,\n isUnhandledRejection?: boolean,\n): Event {\n let event: Event;\n\n if (isErrorEvent(exception as ErrorEvent) && (exception as ErrorEvent).error) {\n // If it is an ErrorEvent with `error` property, extract it to get actual Error\n const errorEvent = exception as ErrorEvent;\n return eventFromError(stackParser, errorEvent.error as Error);\n }\n\n // If it is a `DOMError` (which is a legacy API, but still supported in some browsers) then we just extract the name\n // and message, as it doesn't provide anything else. According to the spec, all `DOMExceptions` should also be\n // `Error`s, but that's not the case in IE11, so in that case we treat it the same as we do a `DOMError`.\n //\n // https://developer.mozilla.org/en-US/docs/Web/API/DOMError\n // https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n // https://webidl.spec.whatwg.org/#es-DOMException-specialness\n if (isDOMError(exception as DOMError) || isDOMException(exception as DOMException)) {\n const domException = exception as DOMException;\n\n if ('stack' in (exception as Error)) {\n event = eventFromError(stackParser, exception as Error);\n } else {\n const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException');\n const message = domException.message ? `${name}: ${domException.message}` : name;\n event = eventFromString(stackParser, message, syntheticException, attachStacktrace);\n addExceptionTypeValue(event, message);\n }\n if ('code' in domException) {\n event.tags = { ...event.tags, 'DOMException.code': `${domException.code}` };\n }\n\n return event;\n }\n if (isError(exception)) {\n // we have a real Error object, do nothing\n return eventFromError(stackParser, exception);\n }\n if (isPlainObject(exception) || isEvent(exception)) {\n // If it's a plain object or an instance of `Event` (the built-in JS kind, not this SDK's `Event` type), serialize\n // it manually. This will allow us to group events based on top-level keys which is much better than creating a new\n // group on any key/value change.\n const objectException = exception as Record<string, unknown>;\n event = eventFromPlainObject(stackParser, objectException, syntheticException, isUnhandledRejection);\n addExceptionMechanism(event, {\n synthetic: true,\n });\n return event;\n }\n\n // If none of previous checks were valid, then it means that it's not:\n // - an instance of DOMError\n // - an instance of DOMException\n // - an instance of Event\n // - an instance of Error\n // - a valid ErrorEvent (one with an error property)\n // - a plain Object\n //\n // So bail out and capture it as a simple message:\n event = eventFromString(stackParser, exception as string, syntheticException, attachStacktrace);\n addExceptionTypeValue(event, `${exception}`, undefined);\n addExceptionMechanism(event, {\n synthetic: true,\n });\n\n return event;\n}\n\n/**\n * @hidden\n */\nexport function eventFromString(\n stackParser: StackParser,\n input: string,\n syntheticException?: Error,\n attachStacktrace?: boolean,\n): Event {\n const event: Event = {\n message: input,\n };\n\n if (attachStacktrace && syntheticException) {\n const frames = parseStackFrames(stackParser, syntheticException);\n if (frames.length) {\n event.exception = {\n values: [{ value: input, stacktrace: { frames } }],\n };\n }\n }\n\n return event;\n}\n"]}
1
+ {"version":3,"file":"eventbuilder.js","sources":["../../../src/eventbuilder.ts"],"sourcesContent":["import { Event, EventHint, Exception, Severity, SeverityLevel, StackFrame, StackParser } from '@sentry/types';\nimport {\n addExceptionMechanism,\n addExceptionTypeValue,\n extractExceptionKeysForMessage,\n isDOMError,\n isDOMException,\n isError,\n isErrorEvent,\n isEvent,\n isPlainObject,\n normalizeToSize,\n resolvedSyncPromise,\n} from '@sentry/utils';\n\n/**\n * This function creates an exception from a JavaScript Error\n */\nexport function exceptionFromError(stackParser: StackParser, ex: Error): Exception {\n // Get the frames first since Opera can lose the stack if we touch anything else first\n const frames = parseStackFrames(stackParser, ex);\n\n const exception: Exception = {\n type: ex && ex.name,\n value: extractMessage(ex),\n };\n\n if (frames.length) {\n exception.stacktrace = { frames };\n }\n\n if (exception.type === undefined && exception.value === '') {\n exception.value = 'Unrecoverable error caught';\n }\n\n return exception;\n}\n\n/**\n * @hidden\n */\nexport function eventFromPlainObject(\n stackParser: StackParser,\n exception: Record<string, unknown>,\n syntheticException?: Error,\n isUnhandledRejection?: boolean,\n): Event {\n const event: Event = {\n exception: {\n values: [\n {\n type: isEvent(exception) ? exception.constructor.name : isUnhandledRejection ? 'UnhandledRejection' : 'Error',\n value: `Non-Error ${\n isUnhandledRejection ? 'promise rejection' : 'exception'\n } captured with keys: ${extractExceptionKeysForMessage(exception)}`,\n },\n ],\n },\n extra: {\n __serialized__: normalizeToSize(exception),\n },\n };\n\n if (syntheticException) {\n const frames = parseStackFrames(stackParser, syntheticException);\n if (frames.length) {\n // event.exception.values[0] has been set above\n (event.exception as { values: Exception[] }).values[0].stacktrace = { frames };\n }\n }\n\n return event;\n}\n\n/**\n * @hidden\n */\nexport function eventFromError(stackParser: StackParser, ex: Error): Event {\n return {\n exception: {\n values: [exceptionFromError(stackParser, ex)],\n },\n };\n}\n\n/** Parses stack frames from an error */\nexport function parseStackFrames(\n stackParser: StackParser,\n ex: Error & { framesToPop?: number; stacktrace?: string },\n): StackFrame[] {\n // Access and store the stacktrace property before doing ANYTHING\n // else to it because Opera is not very good at providing it\n // reliably in other circumstances.\n const stacktrace = ex.stacktrace || ex.stack || '';\n\n const popSize = getPopSize(ex);\n\n try {\n return stackParser(stacktrace, popSize);\n } catch (e) {\n // no-empty\n }\n\n return [];\n}\n\n// Based on our own mapping pattern - https://github.com/getsentry/sentry/blob/9f08305e09866c8bd6d0c24f5b0aabdd7dd6c59c/src/sentry/lang/javascript/errormapping.py#L83-L108\nconst reactMinifiedRegexp = /Minified React error #\\d+;/i;\n\nfunction getPopSize(ex: Error & { framesToPop?: number }): number {\n if (ex) {\n if (typeof ex.framesToPop === 'number') {\n return ex.framesToPop;\n }\n\n if (reactMinifiedRegexp.test(ex.message)) {\n return 1;\n }\n }\n\n return 0;\n}\n\n/**\n * There are cases where stacktrace.message is an Event object\n * https://github.com/getsentry/sentry-javascript/issues/1949\n * In this specific case we try to extract stacktrace.message.error.message\n */\nfunction extractMessage(ex: Error & { message: { error?: Error } }): string {\n const message = ex && ex.message;\n if (!message) {\n return 'No error message';\n }\n if (message.error && typeof message.error.message === 'string') {\n return message.error.message;\n }\n return message;\n}\n\n/**\n * Creates an {@link Event} from all inputs to `captureException` and non-primitive inputs to `captureMessage`.\n * @hidden\n */\nexport function eventFromException(\n stackParser: StackParser,\n exception: unknown,\n hint?: EventHint,\n attachStacktrace?: boolean,\n): PromiseLike<Event> {\n const syntheticException = (hint && hint.syntheticException) || undefined;\n const event = eventFromUnknownInput(stackParser, exception, syntheticException, attachStacktrace);\n addExceptionMechanism(event); // defaults to { type: 'generic', handled: true }\n event.level = 'error';\n if (hint && hint.event_id) {\n event.event_id = hint.event_id;\n }\n return resolvedSyncPromise(event);\n}\n\n/**\n * Builds and Event from a Message\n * @hidden\n */\nexport function eventFromMessage(\n stackParser: StackParser,\n message: string,\n // eslint-disable-next-line deprecation/deprecation\n level: Severity | SeverityLevel = 'info',\n hint?: EventHint,\n attachStacktrace?: boolean,\n): PromiseLike<Event> {\n const syntheticException = (hint && hint.syntheticException) || undefined;\n const event = eventFromString(stackParser, message, syntheticException, attachStacktrace);\n event.level = level;\n if (hint && hint.event_id) {\n event.event_id = hint.event_id;\n }\n return resolvedSyncPromise(event);\n}\n\n/**\n * @hidden\n */\nexport function eventFromUnknownInput(\n stackParser: StackParser,\n exception: unknown,\n syntheticException?: Error,\n attachStacktrace?: boolean,\n isUnhandledRejection?: boolean,\n): Event {\n let event: Event;\n\n if (isErrorEvent(exception as ErrorEvent) && (exception as ErrorEvent).error) {\n // If it is an ErrorEvent with `error` property, extract it to get actual Error\n const errorEvent = exception as ErrorEvent;\n return eventFromError(stackParser, errorEvent.error as Error);\n }\n\n // If it is a `DOMError` (which is a legacy API, but still supported in some browsers) then we just extract the name\n // and message, as it doesn't provide anything else. According to the spec, all `DOMExceptions` should also be\n // `Error`s, but that's not the case in IE11, so in that case we treat it the same as we do a `DOMError`.\n //\n // https://developer.mozilla.org/en-US/docs/Web/API/DOMError\n // https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n // https://webidl.spec.whatwg.org/#es-DOMException-specialness\n if (isDOMError(exception as DOMError) || isDOMException(exception as DOMException)) {\n const domException = exception as DOMException;\n\n if ('stack' in (exception as Error)) {\n event = eventFromError(stackParser, exception as Error);\n } else {\n const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException');\n const message = domException.message ? `${name}: ${domException.message}` : name;\n event = eventFromString(stackParser, message, syntheticException, attachStacktrace);\n addExceptionTypeValue(event, message);\n }\n if ('code' in domException) {\n event.tags = { ...event.tags, 'DOMException.code': `${domException.code}` };\n }\n\n return event;\n }\n if (isError(exception)) {\n // we have a real Error object, do nothing\n return eventFromError(stackParser, exception);\n }\n if (isPlainObject(exception) || isEvent(exception)) {\n // If it's a plain object or an instance of `Event` (the built-in JS kind, not this SDK's `Event` type), serialize\n // it manually. This will allow us to group events based on top-level keys which is much better than creating a new\n // group on any key/value change.\n const objectException = exception as Record<string, unknown>;\n event = eventFromPlainObject(stackParser, objectException, syntheticException, isUnhandledRejection);\n addExceptionMechanism(event, {\n synthetic: true,\n });\n return event;\n }\n\n // If none of previous checks were valid, then it means that it's not:\n // - an instance of DOMError\n // - an instance of DOMException\n // - an instance of Event\n // - an instance of Error\n // - a valid ErrorEvent (one with an error property)\n // - a plain Object\n //\n // So bail out and capture it as a simple message:\n event = eventFromString(stackParser, exception as string, syntheticException, attachStacktrace);\n addExceptionTypeValue(event, `${exception}`, undefined);\n addExceptionMechanism(event, {\n synthetic: true,\n });\n\n return event;\n}\n\n/**\n * @hidden\n */\nexport function eventFromString(\n stackParser: StackParser,\n input: string,\n syntheticException?: Error,\n attachStacktrace?: boolean,\n): Event {\n const event: Event = {\n message: input,\n };\n\n if (attachStacktrace && syntheticException) {\n const frames = parseStackFrames(stackParser, syntheticException);\n if (frames.length) {\n event.exception = {\n values: [{ value: input, stacktrace: { frames } }],\n };\n }\n }\n\n return event;\n}\n"],"names":[],"mappings":";;AAeA;AACA;AACA;;AAEA;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;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;;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;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;AACA;AACA;;AAEA;AACA;AACA;AAEA;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;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;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;AACA;AACA;AACA;;;;"}
package/esm/exports.js CHANGED
@@ -1,8 +1,12 @@
1
- export { addGlobalEventProcessor, addBreadcrumb, captureException, captureEvent, captureMessage, configureScope, createTransport, getHubFromCarrier, getCurrentHub, Hub, makeMain, Scope, Session, startTransaction, SDK_VERSION, setContext, setExtra, setExtras, setTag, setTags, setUser, withScope, FunctionToString, InboundFilters, } from '@sentry/core';
2
- export { BrowserClient } from './client';
3
- export { makeFetchTransport, makeXHRTransport } from './transports';
4
- export { defaultStackParser, defaultStackLineParsers, chromeStackLineParser, geckoStackLineParser, opera10StackLineParser, opera11StackLineParser, winjsStackLineParser, } from './stack-parsers';
5
- export { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk';
6
- export { SDK_NAME } from './version';
7
- export { GlobalHandlers, TryCatch, Breadcrumbs, LinkedErrors, UserAgent, Dedupe } from './integrations';
8
- //# sourceMappingURL=exports.js.map
1
+ export { FunctionToString, Hub, InboundFilters, SDK_VERSION, Scope, addBreadcrumb, addGlobalEventProcessor, captureEvent, captureException, captureMessage, configureScope, createTransport, getCurrentHub, getHubFromCarrier, makeMain, setContext, setExtra, setExtras, setTag, setTags, setUser, startTransaction, withScope } from '@sentry/core';
2
+ export { BrowserClient } from './client.js';
3
+ import './transports/index.js';
4
+ export { chromeStackLineParser, defaultStackLineParsers, defaultStackParser, geckoStackLineParser, opera10StackLineParser, opera11StackLineParser, winjsStackLineParser } from './stack-parsers.js';
5
+ export { close, defaultIntegrations, flush, forceLoad, init, lastEventId, onLoad, showReportDialog, wrap } from './sdk.js';
6
+ import './integrations/index.js';
7
+
8
+ ;
9
+
10
+ ;
11
+ ;
12
+ //# sourceMappingURL=exports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"exports.js","sourceRoot":"","sources":["../../../src/exports.ts"],"names":[],"mappings":"AAoBA,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,GAAG,EACH,QAAQ,EACR,KAAK,EACL,OAAO,EACP,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,SAAS,EACT,MAAM,EACN,OAAO,EACP,OAAO,EACP,SAAS,EACT,gBAAgB,EAChB,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AACxH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export type {\n Breadcrumb,\n BreadcrumbHint,\n Request,\n SdkInfo,\n Event,\n EventHint,\n Exception,\n // eslint-disable-next-line deprecation/deprecation\n Severity,\n SeverityLevel,\n StackFrame,\n Stacktrace,\n Thread,\n User,\n} from '@sentry/types';\n\nexport type { BrowserOptions } from './client';\nexport type { ReportDialogOptions } from './helpers';\n\nexport {\n addGlobalEventProcessor,\n addBreadcrumb,\n captureException,\n captureEvent,\n captureMessage,\n configureScope,\n createTransport,\n getHubFromCarrier,\n getCurrentHub,\n Hub,\n makeMain,\n Scope,\n Session,\n startTransaction,\n SDK_VERSION,\n setContext,\n setExtra,\n setExtras,\n setTag,\n setTags,\n setUser,\n withScope,\n FunctionToString,\n InboundFilters,\n} from '@sentry/core';\n\nexport { BrowserClient } from './client';\nexport { makeFetchTransport, makeXHRTransport } from './transports';\nexport {\n defaultStackParser,\n defaultStackLineParsers,\n chromeStackLineParser,\n geckoStackLineParser,\n opera10StackLineParser,\n opera11StackLineParser,\n winjsStackLineParser,\n} from './stack-parsers';\nexport { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk';\nexport { SDK_NAME } from './version';\nexport { GlobalHandlers, TryCatch, Breadcrumbs, LinkedErrors, UserAgent, Dedupe } from './integrations';\n"]}
1
+ {"version":3,"file":"exports.js","sources":["../../../src/exports.ts"],"sourcesContent":["export type {\n Breadcrumb,\n BreadcrumbHint,\n Request,\n SdkInfo,\n Event,\n EventHint,\n Exception,\n // eslint-disable-next-line deprecation/deprecation\n Severity,\n SeverityLevel,\n StackFrame,\n Stacktrace,\n Thread,\n User,\n Session,\n} from '@sentry/types';\n\nexport type { BrowserOptions } from './client';\nexport type { ReportDialogOptions } from './helpers';\n\nexport {\n addGlobalEventProcessor,\n addBreadcrumb,\n captureException,\n captureEvent,\n captureMessage,\n configureScope,\n createTransport,\n getHubFromCarrier,\n getCurrentHub,\n Hub,\n makeMain,\n Scope,\n startTransaction,\n SDK_VERSION,\n setContext,\n setExtra,\n setExtras,\n setTag,\n setTags,\n setUser,\n withScope,\n FunctionToString,\n InboundFilters,\n} from '@sentry/core';\n\nexport { BrowserClient } from './client';\nexport { makeFetchTransport, makeXHRTransport } from './transports';\nexport {\n defaultStackParser,\n defaultStackLineParsers,\n chromeStackLineParser,\n geckoStackLineParser,\n opera10StackLineParser,\n opera11StackLineParser,\n winjsStackLineParser,\n} from './stack-parsers';\nexport { defaultIntegrations, forceLoad, init, lastEventId, onLoad, showReportDialog, flush, close, wrap } from './sdk';\nexport { GlobalHandlers, TryCatch, Breadcrumbs, LinkedErrors, HttpContext, Dedupe } from './integrations';\n"],"names":[],"mappings":";;;;;;;AAgBA;AACA;AACA;AACA"}
package/esm/flags.js CHANGED
@@ -11,6 +11,9 @@
11
11
  * our, or the user's build process. Take care when introducing new flags - they must not throw if they are not
12
12
  * replaced.
13
13
  */
14
+
14
15
  /** Flag that is true for debug builds, false otherwise. */
15
- export const IS_DEBUG_BUILD = typeof __SENTRY_DEBUG__ === 'undefined' ? true : __SENTRY_DEBUG__;
16
- //# sourceMappingURL=flags.js.map
16
+ var IS_DEBUG_BUILD = typeof __SENTRY_DEBUG__ === 'undefined' ? true : __SENTRY_DEBUG__;
17
+
18
+ export { IS_DEBUG_BUILD };
19
+ //# sourceMappingURL=flags.js.map
package/esm/flags.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"flags.js","sourceRoot":"","sources":["../../../src/flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,2DAA2D;AAC3D,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,gBAAgB,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC","sourcesContent":["/*\n * This file defines flags and constants that can be modified during compile time in order to facilitate tree shaking\n * for users.\n *\n * Debug flags need to be declared in each package individually and must not be imported across package boundaries,\n * because some build tools have trouble tree-shaking imported guards.\n *\n * As a convention, we define debug flags in a `flags.ts` file in the root of a package's `src` folder.\n *\n * Debug flag files will contain \"magic strings\" like `__SENTRY_DEBUG__` that may get replaced with actual values during\n * our, or the user's build process. Take care when introducing new flags - they must not throw if they are not\n * replaced.\n */\n\ndeclare const __SENTRY_DEBUG__: boolean;\n\n/** Flag that is true for debug builds, false otherwise. */\nexport const IS_DEBUG_BUILD = typeof __SENTRY_DEBUG__ === 'undefined' ? true : __SENTRY_DEBUG__;\n"]}
1
+ {"version":3,"file":"flags.js","sources":["../../../src/flags.ts"],"sourcesContent":["/*\n * This file defines flags and constants that can be modified during compile time in order to facilitate tree shaking\n * for users.\n *\n * Debug flags need to be declared in each package individually and must not be imported across package boundaries,\n * because some build tools have trouble tree-shaking imported guards.\n *\n * As a convention, we define debug flags in a `flags.ts` file in the root of a package's `src` folder.\n *\n * Debug flag files will contain \"magic strings\" like `__SENTRY_DEBUG__` that may get replaced with actual values during\n * our, or the user's build process. Take care when introducing new flags - they must not throw if they are not\n * replaced.\n */\n\ndeclare const __SENTRY_DEBUG__: boolean;\n\n/** Flag that is true for debug builds, false otherwise. */\nexport const IS_DEBUG_BUILD = typeof __SENTRY_DEBUG__ === 'undefined' ? true : __SENTRY_DEBUG__;\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;;;;;"}