@juo/blocks 1.4.1 → 1.4.3
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.
- package/dist/{ExtensionRoot-M8g3HxCp.js → ExtensionRoot-B27vHVGI.js} +24 -10
- package/dist/block.d.ts +3 -1
- package/dist/block.d.ts.map +1 -1
- package/dist/core.js +22 -7
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor.js +1 -3
- package/dist/{juo-workflow-BJUBbrar.js → juo-workflow-BXGQS82N.js} +1 -1
- package/dist/observability.d.ts +21 -0
- package/dist/observability.d.ts.map +1 -0
- package/dist/observability.js +1381 -0
- package/dist/observability.test.d.ts +2 -0
- package/dist/observability.test.d.ts.map +1 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.test.d.ts +2 -0
- package/dist/registry.test.d.ts.map +1 -0
- package/dist/{theme-state-wwW6UU3i.js → theme-state-BpmgtjdC.js} +77 -21
- package/dist/theme-state.d.ts.map +1 -1
- package/dist/theme-state.resolve.test.d.ts +2 -0
- package/dist/theme-state.resolve.test.d.ts.map +1 -0
- package/dist/vue/block.d.ts +4 -2
- package/dist/vue/block.d.ts.map +1 -1
- package/dist/vue/block.test.d.ts +2 -0
- package/dist/vue/block.test.d.ts.map +1 -0
- package/dist/vue.js +60 -16
- package/dist/web-components/Block.d.ts.map +1 -1
- package/dist/web-components/ExtensionRoot.d.ts +1 -0
- package/dist/web-components/ExtensionRoot.d.ts.map +1 -1
- package/dist/web-components/ExtensionRoot.test.d.ts +2 -0
- package/dist/web-components/ExtensionRoot.test.d.ts.map +1 -0
- package/dist/web-components-editor.js +3 -3
- package/dist/web-components-runtime.js +3 -3
- package/package.json +7 -2
|
@@ -0,0 +1,1381 @@
|
|
|
1
|
+
const objectToString = Object.prototype.toString;
|
|
2
|
+
function isBuiltin(wat, className) {
|
|
3
|
+
return objectToString.call(wat) === `[object ${className}]`;
|
|
4
|
+
}
|
|
5
|
+
function isPlainObject(wat) {
|
|
6
|
+
return isBuiltin(wat, "Object");
|
|
7
|
+
}
|
|
8
|
+
function isThenable(wat) {
|
|
9
|
+
return Boolean(wat && wat.then && typeof wat.then === "function");
|
|
10
|
+
}
|
|
11
|
+
function isGlobalObj(obj) {
|
|
12
|
+
return obj && obj.Math == Math ? obj : void 0;
|
|
13
|
+
}
|
|
14
|
+
const GLOBAL_OBJ = typeof globalThis == "object" && isGlobalObj(globalThis) || // eslint-disable-next-line no-restricted-globals
|
|
15
|
+
typeof window == "object" && isGlobalObj(window) || typeof self == "object" && isGlobalObj(self) || typeof global == "object" && isGlobalObj(global) || /* @__PURE__ */ function() {
|
|
16
|
+
return this;
|
|
17
|
+
}() || {};
|
|
18
|
+
function getGlobalObject() {
|
|
19
|
+
return GLOBAL_OBJ;
|
|
20
|
+
}
|
|
21
|
+
function getGlobalSingleton(name, creator, obj) {
|
|
22
|
+
const gbl = obj || GLOBAL_OBJ;
|
|
23
|
+
const __SENTRY__ = gbl.__SENTRY__ = gbl.__SENTRY__ || {};
|
|
24
|
+
const singleton = __SENTRY__[name] || (__SENTRY__[name] = creator());
|
|
25
|
+
return singleton;
|
|
26
|
+
}
|
|
27
|
+
const PREFIX = "Sentry Logger ";
|
|
28
|
+
const CONSOLE_LEVELS = ["debug", "info", "warn", "error", "log", "assert", "trace"];
|
|
29
|
+
const originalConsoleMethods = {};
|
|
30
|
+
function consoleSandbox(callback) {
|
|
31
|
+
if (!("console" in GLOBAL_OBJ)) {
|
|
32
|
+
return callback();
|
|
33
|
+
}
|
|
34
|
+
const console2 = GLOBAL_OBJ.console;
|
|
35
|
+
const wrappedFuncs = {};
|
|
36
|
+
const wrappedLevels = Object.keys(originalConsoleMethods);
|
|
37
|
+
wrappedLevels.forEach((level) => {
|
|
38
|
+
const originalConsoleMethod = originalConsoleMethods[level];
|
|
39
|
+
wrappedFuncs[level] = console2[level];
|
|
40
|
+
console2[level] = originalConsoleMethod;
|
|
41
|
+
});
|
|
42
|
+
try {
|
|
43
|
+
return callback();
|
|
44
|
+
} finally {
|
|
45
|
+
wrappedLevels.forEach((level) => {
|
|
46
|
+
console2[level] = wrappedFuncs[level];
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function makeLogger() {
|
|
51
|
+
let enabled = false;
|
|
52
|
+
const logger2 = {
|
|
53
|
+
enable: () => {
|
|
54
|
+
enabled = true;
|
|
55
|
+
},
|
|
56
|
+
disable: () => {
|
|
57
|
+
enabled = false;
|
|
58
|
+
},
|
|
59
|
+
isEnabled: () => enabled
|
|
60
|
+
};
|
|
61
|
+
if (typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) {
|
|
62
|
+
CONSOLE_LEVELS.forEach((name) => {
|
|
63
|
+
logger2[name] = (...args) => {
|
|
64
|
+
if (enabled) {
|
|
65
|
+
consoleSandbox(() => {
|
|
66
|
+
GLOBAL_OBJ.console[name](`${PREFIX}[${name}]:`, ...args);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
CONSOLE_LEVELS.forEach((name) => {
|
|
73
|
+
logger2[name] = () => void 0;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return logger2;
|
|
77
|
+
}
|
|
78
|
+
const logger = makeLogger();
|
|
79
|
+
function dropUndefinedKeys(inputValue) {
|
|
80
|
+
const memoizationMap = /* @__PURE__ */ new Map();
|
|
81
|
+
return _dropUndefinedKeys(inputValue, memoizationMap);
|
|
82
|
+
}
|
|
83
|
+
function _dropUndefinedKeys(inputValue, memoizationMap) {
|
|
84
|
+
if (isPlainObject(inputValue)) {
|
|
85
|
+
const memoVal = memoizationMap.get(inputValue);
|
|
86
|
+
if (memoVal !== void 0) {
|
|
87
|
+
return memoVal;
|
|
88
|
+
}
|
|
89
|
+
const returnValue = {};
|
|
90
|
+
memoizationMap.set(inputValue, returnValue);
|
|
91
|
+
for (const key of Object.keys(inputValue)) {
|
|
92
|
+
if (typeof inputValue[key] !== "undefined") {
|
|
93
|
+
returnValue[key] = _dropUndefinedKeys(inputValue[key], memoizationMap);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return returnValue;
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(inputValue)) {
|
|
99
|
+
const memoVal = memoizationMap.get(inputValue);
|
|
100
|
+
if (memoVal !== void 0) {
|
|
101
|
+
return memoVal;
|
|
102
|
+
}
|
|
103
|
+
const returnValue = [];
|
|
104
|
+
memoizationMap.set(inputValue, returnValue);
|
|
105
|
+
inputValue.forEach((item) => {
|
|
106
|
+
returnValue.push(_dropUndefinedKeys(item, memoizationMap));
|
|
107
|
+
});
|
|
108
|
+
return returnValue;
|
|
109
|
+
}
|
|
110
|
+
return inputValue;
|
|
111
|
+
}
|
|
112
|
+
function uuid4() {
|
|
113
|
+
const gbl = GLOBAL_OBJ;
|
|
114
|
+
const crypto = gbl.crypto || gbl.msCrypto;
|
|
115
|
+
let getRandomByte = () => Math.random() * 16;
|
|
116
|
+
try {
|
|
117
|
+
if (crypto && crypto.randomUUID) {
|
|
118
|
+
return crypto.randomUUID().replace(/-/g, "");
|
|
119
|
+
}
|
|
120
|
+
if (crypto && crypto.getRandomValues) {
|
|
121
|
+
getRandomByte = () => crypto.getRandomValues(new Uint8Array(1))[0];
|
|
122
|
+
}
|
|
123
|
+
} catch (_) {
|
|
124
|
+
}
|
|
125
|
+
return ("10000000100040008000" + 1e11).replace(
|
|
126
|
+
/[018]/g,
|
|
127
|
+
(c) => (
|
|
128
|
+
// eslint-disable-next-line no-bitwise
|
|
129
|
+
(c ^ (getRandomByte() & 15) >> c / 4).toString(16)
|
|
130
|
+
)
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
function arrayify(maybeArray) {
|
|
134
|
+
return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
135
|
+
}
|
|
136
|
+
function isBrowserBundle() {
|
|
137
|
+
return typeof __SENTRY_BROWSER_BUNDLE__ !== "undefined" && !!__SENTRY_BROWSER_BUNDLE__;
|
|
138
|
+
}
|
|
139
|
+
function isNodeEnv() {
|
|
140
|
+
return !isBrowserBundle() && Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
|
|
141
|
+
}
|
|
142
|
+
function dynamicRequire(mod, request) {
|
|
143
|
+
return mod.require(request);
|
|
144
|
+
}
|
|
145
|
+
var States;
|
|
146
|
+
(function(States2) {
|
|
147
|
+
const PENDING = 0;
|
|
148
|
+
States2[States2["PENDING"] = PENDING] = "PENDING";
|
|
149
|
+
const RESOLVED = 1;
|
|
150
|
+
States2[States2["RESOLVED"] = RESOLVED] = "RESOLVED";
|
|
151
|
+
const REJECTED = 2;
|
|
152
|
+
States2[States2["REJECTED"] = REJECTED] = "REJECTED";
|
|
153
|
+
})(States || (States = {}));
|
|
154
|
+
class SyncPromise {
|
|
155
|
+
constructor(executor) {
|
|
156
|
+
SyncPromise.prototype.__init.call(this);
|
|
157
|
+
SyncPromise.prototype.__init2.call(this);
|
|
158
|
+
SyncPromise.prototype.__init3.call(this);
|
|
159
|
+
SyncPromise.prototype.__init4.call(this);
|
|
160
|
+
this._state = States.PENDING;
|
|
161
|
+
this._handlers = [];
|
|
162
|
+
try {
|
|
163
|
+
executor(this._resolve, this._reject);
|
|
164
|
+
} catch (e) {
|
|
165
|
+
this._reject(e);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** JSDoc */
|
|
169
|
+
then(onfulfilled, onrejected) {
|
|
170
|
+
return new SyncPromise((resolve, reject) => {
|
|
171
|
+
this._handlers.push([
|
|
172
|
+
false,
|
|
173
|
+
(result) => {
|
|
174
|
+
if (!onfulfilled) {
|
|
175
|
+
resolve(result);
|
|
176
|
+
} else {
|
|
177
|
+
try {
|
|
178
|
+
resolve(onfulfilled(result));
|
|
179
|
+
} catch (e) {
|
|
180
|
+
reject(e);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
(reason) => {
|
|
185
|
+
if (!onrejected) {
|
|
186
|
+
reject(reason);
|
|
187
|
+
} else {
|
|
188
|
+
try {
|
|
189
|
+
resolve(onrejected(reason));
|
|
190
|
+
} catch (e) {
|
|
191
|
+
reject(e);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
]);
|
|
196
|
+
this._executeHandlers();
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/** JSDoc */
|
|
200
|
+
catch(onrejected) {
|
|
201
|
+
return this.then((val) => val, onrejected);
|
|
202
|
+
}
|
|
203
|
+
/** JSDoc */
|
|
204
|
+
finally(onfinally) {
|
|
205
|
+
return new SyncPromise((resolve, reject) => {
|
|
206
|
+
let val;
|
|
207
|
+
let isRejected;
|
|
208
|
+
return this.then(
|
|
209
|
+
(value) => {
|
|
210
|
+
isRejected = false;
|
|
211
|
+
val = value;
|
|
212
|
+
if (onfinally) {
|
|
213
|
+
onfinally();
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
(reason) => {
|
|
217
|
+
isRejected = true;
|
|
218
|
+
val = reason;
|
|
219
|
+
if (onfinally) {
|
|
220
|
+
onfinally();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
).then(() => {
|
|
224
|
+
if (isRejected) {
|
|
225
|
+
reject(val);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
resolve(val);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/** JSDoc */
|
|
233
|
+
__init() {
|
|
234
|
+
this._resolve = (value) => {
|
|
235
|
+
this._setResult(States.RESOLVED, value);
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/** JSDoc */
|
|
239
|
+
__init2() {
|
|
240
|
+
this._reject = (reason) => {
|
|
241
|
+
this._setResult(States.REJECTED, reason);
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/** JSDoc */
|
|
245
|
+
__init3() {
|
|
246
|
+
this._setResult = (state, value) => {
|
|
247
|
+
if (this._state !== States.PENDING) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (isThenable(value)) {
|
|
251
|
+
void value.then(this._resolve, this._reject);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
this._state = state;
|
|
255
|
+
this._value = value;
|
|
256
|
+
this._executeHandlers();
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/** JSDoc */
|
|
260
|
+
__init4() {
|
|
261
|
+
this._executeHandlers = () => {
|
|
262
|
+
if (this._state === States.PENDING) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const cachedHandlers = this._handlers.slice();
|
|
266
|
+
this._handlers = [];
|
|
267
|
+
cachedHandlers.forEach((handler) => {
|
|
268
|
+
if (handler[0]) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (this._state === States.RESOLVED) {
|
|
272
|
+
handler[1](this._value);
|
|
273
|
+
}
|
|
274
|
+
if (this._state === States.REJECTED) {
|
|
275
|
+
handler[2](this._value);
|
|
276
|
+
}
|
|
277
|
+
handler[0] = true;
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const WINDOW = getGlobalObject();
|
|
283
|
+
const dateTimestampSource = {
|
|
284
|
+
nowSeconds: () => Date.now() / 1e3
|
|
285
|
+
};
|
|
286
|
+
function getBrowserPerformance() {
|
|
287
|
+
const { performance } = WINDOW;
|
|
288
|
+
if (!performance || !performance.now) {
|
|
289
|
+
return void 0;
|
|
290
|
+
}
|
|
291
|
+
const timeOrigin = Date.now() - performance.now();
|
|
292
|
+
return {
|
|
293
|
+
now: () => performance.now(),
|
|
294
|
+
timeOrigin
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function getNodePerformance() {
|
|
298
|
+
try {
|
|
299
|
+
const perfHooks = dynamicRequire(module, "perf_hooks");
|
|
300
|
+
return perfHooks.performance;
|
|
301
|
+
} catch (_) {
|
|
302
|
+
return void 0;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const platformPerformance = isNodeEnv() ? getNodePerformance() : getBrowserPerformance();
|
|
306
|
+
const timestampSource = platformPerformance === void 0 ? dateTimestampSource : {
|
|
307
|
+
nowSeconds: () => (platformPerformance.timeOrigin + platformPerformance.now()) / 1e3
|
|
308
|
+
};
|
|
309
|
+
const dateTimestampInSeconds = dateTimestampSource.nowSeconds.bind(dateTimestampSource);
|
|
310
|
+
const timestampInSeconds = timestampSource.nowSeconds.bind(timestampSource);
|
|
311
|
+
(() => {
|
|
312
|
+
const { performance } = WINDOW;
|
|
313
|
+
if (!performance || !performance.now) {
|
|
314
|
+
return void 0;
|
|
315
|
+
}
|
|
316
|
+
const threshold = 3600 * 1e3;
|
|
317
|
+
const performanceNow = performance.now();
|
|
318
|
+
const dateNow = Date.now();
|
|
319
|
+
const timeOriginDelta = performance.timeOrigin ? Math.abs(performance.timeOrigin + performanceNow - dateNow) : threshold;
|
|
320
|
+
const timeOriginIsReliable = timeOriginDelta < threshold;
|
|
321
|
+
const navigationStart = performance.timing && performance.timing.navigationStart;
|
|
322
|
+
const hasNavigationStart = typeof navigationStart === "number";
|
|
323
|
+
const navigationStartDelta = hasNavigationStart ? Math.abs(navigationStart + performanceNow - dateNow) : threshold;
|
|
324
|
+
const navigationStartIsReliable = navigationStartDelta < threshold;
|
|
325
|
+
if (timeOriginIsReliable || navigationStartIsReliable) {
|
|
326
|
+
if (timeOriginDelta <= navigationStartDelta) {
|
|
327
|
+
return performance.timeOrigin;
|
|
328
|
+
} else {
|
|
329
|
+
return navigationStart;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return dateNow;
|
|
333
|
+
})();
|
|
334
|
+
const DEFAULT_ENVIRONMENT = "production";
|
|
335
|
+
function getGlobalEventProcessors() {
|
|
336
|
+
return getGlobalSingleton("globalEventProcessors", () => []);
|
|
337
|
+
}
|
|
338
|
+
function notifyEventProcessors(processors, event, hint, index = 0) {
|
|
339
|
+
return new SyncPromise((resolve, reject) => {
|
|
340
|
+
const processor = processors[index];
|
|
341
|
+
if (event === null || typeof processor !== "function") {
|
|
342
|
+
resolve(event);
|
|
343
|
+
} else {
|
|
344
|
+
const result = processor({ ...event }, hint);
|
|
345
|
+
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && processor.id && result === null && logger.log(`Event processor "${processor.id}" dropped event`);
|
|
346
|
+
if (isThenable(result)) {
|
|
347
|
+
void result.then((final) => notifyEventProcessors(processors, final, hint, index + 1).then(resolve)).then(null, reject);
|
|
348
|
+
} else {
|
|
349
|
+
void notifyEventProcessors(processors, result, hint, index + 1).then(resolve).then(null, reject);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
function makeSession(context) {
|
|
355
|
+
const startingTime = timestampInSeconds();
|
|
356
|
+
const session = {
|
|
357
|
+
sid: uuid4(),
|
|
358
|
+
init: true,
|
|
359
|
+
timestamp: startingTime,
|
|
360
|
+
started: startingTime,
|
|
361
|
+
duration: 0,
|
|
362
|
+
status: "ok",
|
|
363
|
+
errors: 0,
|
|
364
|
+
ignoreDuration: false,
|
|
365
|
+
toJSON: () => sessionToJSON(session)
|
|
366
|
+
};
|
|
367
|
+
if (context) {
|
|
368
|
+
updateSession(session, context);
|
|
369
|
+
}
|
|
370
|
+
return session;
|
|
371
|
+
}
|
|
372
|
+
function updateSession(session, context = {}) {
|
|
373
|
+
if (context.user) {
|
|
374
|
+
if (!session.ipAddress && context.user.ip_address) {
|
|
375
|
+
session.ipAddress = context.user.ip_address;
|
|
376
|
+
}
|
|
377
|
+
if (!session.did && !context.did) {
|
|
378
|
+
session.did = context.user.id || context.user.email || context.user.username;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
session.timestamp = context.timestamp || timestampInSeconds();
|
|
382
|
+
if (context.abnormal_mechanism) {
|
|
383
|
+
session.abnormal_mechanism = context.abnormal_mechanism;
|
|
384
|
+
}
|
|
385
|
+
if (context.ignoreDuration) {
|
|
386
|
+
session.ignoreDuration = context.ignoreDuration;
|
|
387
|
+
}
|
|
388
|
+
if (context.sid) {
|
|
389
|
+
session.sid = context.sid.length === 32 ? context.sid : uuid4();
|
|
390
|
+
}
|
|
391
|
+
if (context.init !== void 0) {
|
|
392
|
+
session.init = context.init;
|
|
393
|
+
}
|
|
394
|
+
if (!session.did && context.did) {
|
|
395
|
+
session.did = `${context.did}`;
|
|
396
|
+
}
|
|
397
|
+
if (typeof context.started === "number") {
|
|
398
|
+
session.started = context.started;
|
|
399
|
+
}
|
|
400
|
+
if (session.ignoreDuration) {
|
|
401
|
+
session.duration = void 0;
|
|
402
|
+
} else if (typeof context.duration === "number") {
|
|
403
|
+
session.duration = context.duration;
|
|
404
|
+
} else {
|
|
405
|
+
const duration = session.timestamp - session.started;
|
|
406
|
+
session.duration = duration >= 0 ? duration : 0;
|
|
407
|
+
}
|
|
408
|
+
if (context.release) {
|
|
409
|
+
session.release = context.release;
|
|
410
|
+
}
|
|
411
|
+
if (context.environment) {
|
|
412
|
+
session.environment = context.environment;
|
|
413
|
+
}
|
|
414
|
+
if (!session.ipAddress && context.ipAddress) {
|
|
415
|
+
session.ipAddress = context.ipAddress;
|
|
416
|
+
}
|
|
417
|
+
if (!session.userAgent && context.userAgent) {
|
|
418
|
+
session.userAgent = context.userAgent;
|
|
419
|
+
}
|
|
420
|
+
if (typeof context.errors === "number") {
|
|
421
|
+
session.errors = context.errors;
|
|
422
|
+
}
|
|
423
|
+
if (context.status) {
|
|
424
|
+
session.status = context.status;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
function closeSession(session, status) {
|
|
428
|
+
let context = {};
|
|
429
|
+
if (session.status === "ok") {
|
|
430
|
+
context = { status: "exited" };
|
|
431
|
+
}
|
|
432
|
+
updateSession(session, context);
|
|
433
|
+
}
|
|
434
|
+
function sessionToJSON(session) {
|
|
435
|
+
return dropUndefinedKeys({
|
|
436
|
+
sid: `${session.sid}`,
|
|
437
|
+
init: session.init,
|
|
438
|
+
// Make sure that sec is converted to ms for date constructor
|
|
439
|
+
started: new Date(session.started * 1e3).toISOString(),
|
|
440
|
+
timestamp: new Date(session.timestamp * 1e3).toISOString(),
|
|
441
|
+
status: session.status,
|
|
442
|
+
errors: session.errors,
|
|
443
|
+
did: typeof session.did === "number" || typeof session.did === "string" ? `${session.did}` : void 0,
|
|
444
|
+
duration: session.duration,
|
|
445
|
+
abnormal_mechanism: session.abnormal_mechanism,
|
|
446
|
+
attrs: {
|
|
447
|
+
release: session.release,
|
|
448
|
+
environment: session.environment,
|
|
449
|
+
ip_address: session.ipAddress,
|
|
450
|
+
user_agent: session.userAgent
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
const DEFAULT_MAX_BREADCRUMBS = 100;
|
|
455
|
+
class Scope {
|
|
456
|
+
/** Flag if notifying is happening. */
|
|
457
|
+
/** Callback for client to receive scope changes. */
|
|
458
|
+
/** Callback list that will be called after {@link applyToEvent}. */
|
|
459
|
+
/** Array of breadcrumbs. */
|
|
460
|
+
/** User */
|
|
461
|
+
/** Tags */
|
|
462
|
+
/** Extra */
|
|
463
|
+
/** Contexts */
|
|
464
|
+
/** Attachments */
|
|
465
|
+
/** Propagation Context for distributed tracing */
|
|
466
|
+
/**
|
|
467
|
+
* A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get
|
|
468
|
+
* sent to Sentry
|
|
469
|
+
*/
|
|
470
|
+
/** Fingerprint */
|
|
471
|
+
/** Severity */
|
|
472
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
473
|
+
/** Transaction Name */
|
|
474
|
+
/** Span */
|
|
475
|
+
/** Session */
|
|
476
|
+
/** Request Mode Session Status */
|
|
477
|
+
// NOTE: Any field which gets added here should get added not only to the constructor but also to the `clone` method.
|
|
478
|
+
constructor() {
|
|
479
|
+
this._notifyingListeners = false;
|
|
480
|
+
this._scopeListeners = [];
|
|
481
|
+
this._eventProcessors = [];
|
|
482
|
+
this._breadcrumbs = [];
|
|
483
|
+
this._attachments = [];
|
|
484
|
+
this._user = {};
|
|
485
|
+
this._tags = {};
|
|
486
|
+
this._extra = {};
|
|
487
|
+
this._contexts = {};
|
|
488
|
+
this._sdkProcessingMetadata = {};
|
|
489
|
+
this._propagationContext = generatePropagationContext();
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Inherit values from the parent scope.
|
|
493
|
+
* @param scope to clone.
|
|
494
|
+
*/
|
|
495
|
+
static clone(scope) {
|
|
496
|
+
const newScope = new Scope();
|
|
497
|
+
if (scope) {
|
|
498
|
+
newScope._breadcrumbs = [...scope._breadcrumbs];
|
|
499
|
+
newScope._tags = { ...scope._tags };
|
|
500
|
+
newScope._extra = { ...scope._extra };
|
|
501
|
+
newScope._contexts = { ...scope._contexts };
|
|
502
|
+
newScope._user = scope._user;
|
|
503
|
+
newScope._level = scope._level;
|
|
504
|
+
newScope._span = scope._span;
|
|
505
|
+
newScope._session = scope._session;
|
|
506
|
+
newScope._transactionName = scope._transactionName;
|
|
507
|
+
newScope._fingerprint = scope._fingerprint;
|
|
508
|
+
newScope._eventProcessors = [...scope._eventProcessors];
|
|
509
|
+
newScope._requestSession = scope._requestSession;
|
|
510
|
+
newScope._attachments = [...scope._attachments];
|
|
511
|
+
newScope._sdkProcessingMetadata = { ...scope._sdkProcessingMetadata };
|
|
512
|
+
newScope._propagationContext = { ...scope._propagationContext };
|
|
513
|
+
}
|
|
514
|
+
return newScope;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Add internal on change listener. Used for sub SDKs that need to store the scope.
|
|
518
|
+
* @hidden
|
|
519
|
+
*/
|
|
520
|
+
addScopeListener(callback) {
|
|
521
|
+
this._scopeListeners.push(callback);
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* @inheritDoc
|
|
525
|
+
*/
|
|
526
|
+
addEventProcessor(callback) {
|
|
527
|
+
this._eventProcessors.push(callback);
|
|
528
|
+
return this;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* @inheritDoc
|
|
532
|
+
*/
|
|
533
|
+
setUser(user) {
|
|
534
|
+
this._user = user || {};
|
|
535
|
+
if (this._session) {
|
|
536
|
+
updateSession(this._session, { user });
|
|
537
|
+
}
|
|
538
|
+
this._notifyScopeListeners();
|
|
539
|
+
return this;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* @inheritDoc
|
|
543
|
+
*/
|
|
544
|
+
getUser() {
|
|
545
|
+
return this._user;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* @inheritDoc
|
|
549
|
+
*/
|
|
550
|
+
getRequestSession() {
|
|
551
|
+
return this._requestSession;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* @inheritDoc
|
|
555
|
+
*/
|
|
556
|
+
setRequestSession(requestSession) {
|
|
557
|
+
this._requestSession = requestSession;
|
|
558
|
+
return this;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* @inheritDoc
|
|
562
|
+
*/
|
|
563
|
+
setTags(tags) {
|
|
564
|
+
this._tags = {
|
|
565
|
+
...this._tags,
|
|
566
|
+
...tags
|
|
567
|
+
};
|
|
568
|
+
this._notifyScopeListeners();
|
|
569
|
+
return this;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* @inheritDoc
|
|
573
|
+
*/
|
|
574
|
+
setTag(key, value) {
|
|
575
|
+
this._tags = { ...this._tags, [key]: value };
|
|
576
|
+
this._notifyScopeListeners();
|
|
577
|
+
return this;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* @inheritDoc
|
|
581
|
+
*/
|
|
582
|
+
setExtras(extras) {
|
|
583
|
+
this._extra = {
|
|
584
|
+
...this._extra,
|
|
585
|
+
...extras
|
|
586
|
+
};
|
|
587
|
+
this._notifyScopeListeners();
|
|
588
|
+
return this;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* @inheritDoc
|
|
592
|
+
*/
|
|
593
|
+
setExtra(key, extra) {
|
|
594
|
+
this._extra = { ...this._extra, [key]: extra };
|
|
595
|
+
this._notifyScopeListeners();
|
|
596
|
+
return this;
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* @inheritDoc
|
|
600
|
+
*/
|
|
601
|
+
setFingerprint(fingerprint) {
|
|
602
|
+
this._fingerprint = fingerprint;
|
|
603
|
+
this._notifyScopeListeners();
|
|
604
|
+
return this;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* @inheritDoc
|
|
608
|
+
*/
|
|
609
|
+
setLevel(level) {
|
|
610
|
+
this._level = level;
|
|
611
|
+
this._notifyScopeListeners();
|
|
612
|
+
return this;
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* @inheritDoc
|
|
616
|
+
*/
|
|
617
|
+
setTransactionName(name) {
|
|
618
|
+
this._transactionName = name;
|
|
619
|
+
this._notifyScopeListeners();
|
|
620
|
+
return this;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* @inheritDoc
|
|
624
|
+
*/
|
|
625
|
+
setContext(key, context) {
|
|
626
|
+
if (context === null) {
|
|
627
|
+
delete this._contexts[key];
|
|
628
|
+
} else {
|
|
629
|
+
this._contexts[key] = context;
|
|
630
|
+
}
|
|
631
|
+
this._notifyScopeListeners();
|
|
632
|
+
return this;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* @inheritDoc
|
|
636
|
+
*/
|
|
637
|
+
setSpan(span) {
|
|
638
|
+
this._span = span;
|
|
639
|
+
this._notifyScopeListeners();
|
|
640
|
+
return this;
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* @inheritDoc
|
|
644
|
+
*/
|
|
645
|
+
getSpan() {
|
|
646
|
+
return this._span;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* @inheritDoc
|
|
650
|
+
*/
|
|
651
|
+
getTransaction() {
|
|
652
|
+
const span = this.getSpan();
|
|
653
|
+
return span && span.transaction;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* @inheritDoc
|
|
657
|
+
*/
|
|
658
|
+
setSession(session) {
|
|
659
|
+
if (!session) {
|
|
660
|
+
delete this._session;
|
|
661
|
+
} else {
|
|
662
|
+
this._session = session;
|
|
663
|
+
}
|
|
664
|
+
this._notifyScopeListeners();
|
|
665
|
+
return this;
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* @inheritDoc
|
|
669
|
+
*/
|
|
670
|
+
getSession() {
|
|
671
|
+
return this._session;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* @inheritDoc
|
|
675
|
+
*/
|
|
676
|
+
update(captureContext) {
|
|
677
|
+
if (!captureContext) {
|
|
678
|
+
return this;
|
|
679
|
+
}
|
|
680
|
+
if (typeof captureContext === "function") {
|
|
681
|
+
const updatedScope = captureContext(this);
|
|
682
|
+
return updatedScope instanceof Scope ? updatedScope : this;
|
|
683
|
+
}
|
|
684
|
+
if (captureContext instanceof Scope) {
|
|
685
|
+
this._tags = { ...this._tags, ...captureContext._tags };
|
|
686
|
+
this._extra = { ...this._extra, ...captureContext._extra };
|
|
687
|
+
this._contexts = { ...this._contexts, ...captureContext._contexts };
|
|
688
|
+
if (captureContext._user && Object.keys(captureContext._user).length) {
|
|
689
|
+
this._user = captureContext._user;
|
|
690
|
+
}
|
|
691
|
+
if (captureContext._level) {
|
|
692
|
+
this._level = captureContext._level;
|
|
693
|
+
}
|
|
694
|
+
if (captureContext._fingerprint) {
|
|
695
|
+
this._fingerprint = captureContext._fingerprint;
|
|
696
|
+
}
|
|
697
|
+
if (captureContext._requestSession) {
|
|
698
|
+
this._requestSession = captureContext._requestSession;
|
|
699
|
+
}
|
|
700
|
+
if (captureContext._propagationContext) {
|
|
701
|
+
this._propagationContext = captureContext._propagationContext;
|
|
702
|
+
}
|
|
703
|
+
} else if (isPlainObject(captureContext)) {
|
|
704
|
+
captureContext = captureContext;
|
|
705
|
+
this._tags = { ...this._tags, ...captureContext.tags };
|
|
706
|
+
this._extra = { ...this._extra, ...captureContext.extra };
|
|
707
|
+
this._contexts = { ...this._contexts, ...captureContext.contexts };
|
|
708
|
+
if (captureContext.user) {
|
|
709
|
+
this._user = captureContext.user;
|
|
710
|
+
}
|
|
711
|
+
if (captureContext.level) {
|
|
712
|
+
this._level = captureContext.level;
|
|
713
|
+
}
|
|
714
|
+
if (captureContext.fingerprint) {
|
|
715
|
+
this._fingerprint = captureContext.fingerprint;
|
|
716
|
+
}
|
|
717
|
+
if (captureContext.requestSession) {
|
|
718
|
+
this._requestSession = captureContext.requestSession;
|
|
719
|
+
}
|
|
720
|
+
if (captureContext.propagationContext) {
|
|
721
|
+
this._propagationContext = captureContext.propagationContext;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
return this;
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* @inheritDoc
|
|
728
|
+
*/
|
|
729
|
+
clear() {
|
|
730
|
+
this._breadcrumbs = [];
|
|
731
|
+
this._tags = {};
|
|
732
|
+
this._extra = {};
|
|
733
|
+
this._user = {};
|
|
734
|
+
this._contexts = {};
|
|
735
|
+
this._level = void 0;
|
|
736
|
+
this._transactionName = void 0;
|
|
737
|
+
this._fingerprint = void 0;
|
|
738
|
+
this._requestSession = void 0;
|
|
739
|
+
this._span = void 0;
|
|
740
|
+
this._session = void 0;
|
|
741
|
+
this._notifyScopeListeners();
|
|
742
|
+
this._attachments = [];
|
|
743
|
+
this._propagationContext = generatePropagationContext();
|
|
744
|
+
return this;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* @inheritDoc
|
|
748
|
+
*/
|
|
749
|
+
addBreadcrumb(breadcrumb, maxBreadcrumbs) {
|
|
750
|
+
const maxCrumbs = typeof maxBreadcrumbs === "number" ? maxBreadcrumbs : DEFAULT_MAX_BREADCRUMBS;
|
|
751
|
+
if (maxCrumbs <= 0) {
|
|
752
|
+
return this;
|
|
753
|
+
}
|
|
754
|
+
const mergedBreadcrumb = {
|
|
755
|
+
timestamp: dateTimestampInSeconds(),
|
|
756
|
+
...breadcrumb
|
|
757
|
+
};
|
|
758
|
+
const breadcrumbs = this._breadcrumbs;
|
|
759
|
+
breadcrumbs.push(mergedBreadcrumb);
|
|
760
|
+
this._breadcrumbs = breadcrumbs.length > maxCrumbs ? breadcrumbs.slice(-maxCrumbs) : breadcrumbs;
|
|
761
|
+
this._notifyScopeListeners();
|
|
762
|
+
return this;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* @inheritDoc
|
|
766
|
+
*/
|
|
767
|
+
getLastBreadcrumb() {
|
|
768
|
+
return this._breadcrumbs[this._breadcrumbs.length - 1];
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* @inheritDoc
|
|
772
|
+
*/
|
|
773
|
+
clearBreadcrumbs() {
|
|
774
|
+
this._breadcrumbs = [];
|
|
775
|
+
this._notifyScopeListeners();
|
|
776
|
+
return this;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* @inheritDoc
|
|
780
|
+
*/
|
|
781
|
+
addAttachment(attachment) {
|
|
782
|
+
this._attachments.push(attachment);
|
|
783
|
+
return this;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* @inheritDoc
|
|
787
|
+
*/
|
|
788
|
+
getAttachments() {
|
|
789
|
+
return this._attachments;
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* @inheritDoc
|
|
793
|
+
*/
|
|
794
|
+
clearAttachments() {
|
|
795
|
+
this._attachments = [];
|
|
796
|
+
return this;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Applies data from the scope to the event and runs all event processors on it.
|
|
800
|
+
*
|
|
801
|
+
* @param event Event
|
|
802
|
+
* @param hint Object containing additional information about the original exception, for use by the event processors.
|
|
803
|
+
* @hidden
|
|
804
|
+
*/
|
|
805
|
+
applyToEvent(event, hint = {}, additionalEventProcessors) {
|
|
806
|
+
if (this._extra && Object.keys(this._extra).length) {
|
|
807
|
+
event.extra = { ...this._extra, ...event.extra };
|
|
808
|
+
}
|
|
809
|
+
if (this._tags && Object.keys(this._tags).length) {
|
|
810
|
+
event.tags = { ...this._tags, ...event.tags };
|
|
811
|
+
}
|
|
812
|
+
if (this._user && Object.keys(this._user).length) {
|
|
813
|
+
event.user = { ...this._user, ...event.user };
|
|
814
|
+
}
|
|
815
|
+
if (this._contexts && Object.keys(this._contexts).length) {
|
|
816
|
+
event.contexts = { ...this._contexts, ...event.contexts };
|
|
817
|
+
}
|
|
818
|
+
if (this._level) {
|
|
819
|
+
event.level = this._level;
|
|
820
|
+
}
|
|
821
|
+
if (this._transactionName) {
|
|
822
|
+
event.transaction = this._transactionName;
|
|
823
|
+
}
|
|
824
|
+
if (this._span) {
|
|
825
|
+
event.contexts = { trace: this._span.getTraceContext(), ...event.contexts };
|
|
826
|
+
const transaction = this._span.transaction;
|
|
827
|
+
if (transaction) {
|
|
828
|
+
event.sdkProcessingMetadata = {
|
|
829
|
+
dynamicSamplingContext: transaction.getDynamicSamplingContext(),
|
|
830
|
+
...event.sdkProcessingMetadata
|
|
831
|
+
};
|
|
832
|
+
const transactionName = transaction.name;
|
|
833
|
+
if (transactionName) {
|
|
834
|
+
event.tags = { transaction: transactionName, ...event.tags };
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
this._applyFingerprint(event);
|
|
839
|
+
const scopeBreadcrumbs = this._getBreadcrumbs();
|
|
840
|
+
const breadcrumbs = [...event.breadcrumbs || [], ...scopeBreadcrumbs];
|
|
841
|
+
event.breadcrumbs = breadcrumbs.length > 0 ? breadcrumbs : void 0;
|
|
842
|
+
event.sdkProcessingMetadata = {
|
|
843
|
+
...event.sdkProcessingMetadata,
|
|
844
|
+
...this._sdkProcessingMetadata,
|
|
845
|
+
propagationContext: this._propagationContext
|
|
846
|
+
};
|
|
847
|
+
return notifyEventProcessors(
|
|
848
|
+
[...additionalEventProcessors || [], ...getGlobalEventProcessors(), ...this._eventProcessors],
|
|
849
|
+
event,
|
|
850
|
+
hint
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Add data which will be accessible during event processing but won't get sent to Sentry
|
|
855
|
+
*/
|
|
856
|
+
setSDKProcessingMetadata(newData) {
|
|
857
|
+
this._sdkProcessingMetadata = { ...this._sdkProcessingMetadata, ...newData };
|
|
858
|
+
return this;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* @inheritDoc
|
|
862
|
+
*/
|
|
863
|
+
setPropagationContext(context) {
|
|
864
|
+
this._propagationContext = context;
|
|
865
|
+
return this;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* @inheritDoc
|
|
869
|
+
*/
|
|
870
|
+
getPropagationContext() {
|
|
871
|
+
return this._propagationContext;
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Get the breadcrumbs for this scope.
|
|
875
|
+
*/
|
|
876
|
+
_getBreadcrumbs() {
|
|
877
|
+
return this._breadcrumbs;
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* This will be called on every set call.
|
|
881
|
+
*/
|
|
882
|
+
_notifyScopeListeners() {
|
|
883
|
+
if (!this._notifyingListeners) {
|
|
884
|
+
this._notifyingListeners = true;
|
|
885
|
+
this._scopeListeners.forEach((callback) => {
|
|
886
|
+
callback(this);
|
|
887
|
+
});
|
|
888
|
+
this._notifyingListeners = false;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Applies fingerprint from the scope to the event if there's one,
|
|
893
|
+
* uses message if there's one instead or get rid of empty fingerprint
|
|
894
|
+
*/
|
|
895
|
+
_applyFingerprint(event) {
|
|
896
|
+
event.fingerprint = event.fingerprint ? arrayify(event.fingerprint) : [];
|
|
897
|
+
if (this._fingerprint) {
|
|
898
|
+
event.fingerprint = event.fingerprint.concat(this._fingerprint);
|
|
899
|
+
}
|
|
900
|
+
if (event.fingerprint && !event.fingerprint.length) {
|
|
901
|
+
delete event.fingerprint;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
function generatePropagationContext() {
|
|
906
|
+
return {
|
|
907
|
+
traceId: uuid4(),
|
|
908
|
+
spanId: uuid4().substring(16)
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
const API_VERSION = 4;
|
|
912
|
+
const DEFAULT_BREADCRUMBS = 100;
|
|
913
|
+
class Hub {
|
|
914
|
+
/** Is a {@link Layer}[] containing the client and scope */
|
|
915
|
+
/** Contains the last event id of a captured event. */
|
|
916
|
+
/**
|
|
917
|
+
* Creates a new instance of the hub, will push one {@link Layer} into the
|
|
918
|
+
* internal stack on creation.
|
|
919
|
+
*
|
|
920
|
+
* @param client bound to the hub.
|
|
921
|
+
* @param scope bound to the hub.
|
|
922
|
+
* @param version number, higher number means higher priority.
|
|
923
|
+
*/
|
|
924
|
+
constructor(client, scope = new Scope(), _version = API_VERSION) {
|
|
925
|
+
this._version = _version;
|
|
926
|
+
this._stack = [{ scope }];
|
|
927
|
+
if (client) {
|
|
928
|
+
this.bindClient(client);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* @inheritDoc
|
|
933
|
+
*/
|
|
934
|
+
isOlderThan(version) {
|
|
935
|
+
return this._version < version;
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* @inheritDoc
|
|
939
|
+
*/
|
|
940
|
+
bindClient(client) {
|
|
941
|
+
const top = this.getStackTop();
|
|
942
|
+
top.client = client;
|
|
943
|
+
if (client && client.setupIntegrations) {
|
|
944
|
+
client.setupIntegrations();
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* @inheritDoc
|
|
949
|
+
*/
|
|
950
|
+
pushScope() {
|
|
951
|
+
const scope = Scope.clone(this.getScope());
|
|
952
|
+
this.getStack().push({
|
|
953
|
+
client: this.getClient(),
|
|
954
|
+
scope
|
|
955
|
+
});
|
|
956
|
+
return scope;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* @inheritDoc
|
|
960
|
+
*/
|
|
961
|
+
popScope() {
|
|
962
|
+
if (this.getStack().length <= 1) return false;
|
|
963
|
+
return !!this.getStack().pop();
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* @inheritDoc
|
|
967
|
+
*/
|
|
968
|
+
withScope(callback) {
|
|
969
|
+
const scope = this.pushScope();
|
|
970
|
+
try {
|
|
971
|
+
callback(scope);
|
|
972
|
+
} finally {
|
|
973
|
+
this.popScope();
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* @inheritDoc
|
|
978
|
+
*/
|
|
979
|
+
getClient() {
|
|
980
|
+
return this.getStackTop().client;
|
|
981
|
+
}
|
|
982
|
+
/** Returns the scope of the top stack. */
|
|
983
|
+
getScope() {
|
|
984
|
+
return this.getStackTop().scope;
|
|
985
|
+
}
|
|
986
|
+
/** Returns the scope stack for domains or the process. */
|
|
987
|
+
getStack() {
|
|
988
|
+
return this._stack;
|
|
989
|
+
}
|
|
990
|
+
/** Returns the topmost scope layer in the order domain > local > process. */
|
|
991
|
+
getStackTop() {
|
|
992
|
+
return this._stack[this._stack.length - 1];
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* @inheritDoc
|
|
996
|
+
*/
|
|
997
|
+
captureException(exception, hint) {
|
|
998
|
+
const eventId = this._lastEventId = hint && hint.event_id ? hint.event_id : uuid4();
|
|
999
|
+
const syntheticException = new Error("Sentry syntheticException");
|
|
1000
|
+
this._withClient((client, scope) => {
|
|
1001
|
+
client.captureException(
|
|
1002
|
+
exception,
|
|
1003
|
+
{
|
|
1004
|
+
originalException: exception,
|
|
1005
|
+
syntheticException,
|
|
1006
|
+
...hint,
|
|
1007
|
+
event_id: eventId
|
|
1008
|
+
},
|
|
1009
|
+
scope
|
|
1010
|
+
);
|
|
1011
|
+
});
|
|
1012
|
+
return eventId;
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* @inheritDoc
|
|
1016
|
+
*/
|
|
1017
|
+
captureMessage(message, level, hint) {
|
|
1018
|
+
const eventId = this._lastEventId = hint && hint.event_id ? hint.event_id : uuid4();
|
|
1019
|
+
const syntheticException = new Error(message);
|
|
1020
|
+
this._withClient((client, scope) => {
|
|
1021
|
+
client.captureMessage(
|
|
1022
|
+
message,
|
|
1023
|
+
level,
|
|
1024
|
+
{
|
|
1025
|
+
originalException: message,
|
|
1026
|
+
syntheticException,
|
|
1027
|
+
...hint,
|
|
1028
|
+
event_id: eventId
|
|
1029
|
+
},
|
|
1030
|
+
scope
|
|
1031
|
+
);
|
|
1032
|
+
});
|
|
1033
|
+
return eventId;
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* @inheritDoc
|
|
1037
|
+
*/
|
|
1038
|
+
captureEvent(event, hint) {
|
|
1039
|
+
const eventId = hint && hint.event_id ? hint.event_id : uuid4();
|
|
1040
|
+
if (!event.type) {
|
|
1041
|
+
this._lastEventId = eventId;
|
|
1042
|
+
}
|
|
1043
|
+
this._withClient((client, scope) => {
|
|
1044
|
+
client.captureEvent(event, { ...hint, event_id: eventId }, scope);
|
|
1045
|
+
});
|
|
1046
|
+
return eventId;
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* @inheritDoc
|
|
1050
|
+
*/
|
|
1051
|
+
lastEventId() {
|
|
1052
|
+
return this._lastEventId;
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* @inheritDoc
|
|
1056
|
+
*/
|
|
1057
|
+
addBreadcrumb(breadcrumb, hint) {
|
|
1058
|
+
const { scope, client } = this.getStackTop();
|
|
1059
|
+
if (!client) return;
|
|
1060
|
+
const { beforeBreadcrumb = null, maxBreadcrumbs = DEFAULT_BREADCRUMBS } = client.getOptions && client.getOptions() || {};
|
|
1061
|
+
if (maxBreadcrumbs <= 0) return;
|
|
1062
|
+
const timestamp = dateTimestampInSeconds();
|
|
1063
|
+
const mergedBreadcrumb = { timestamp, ...breadcrumb };
|
|
1064
|
+
const finalBreadcrumb = beforeBreadcrumb ? consoleSandbox(() => beforeBreadcrumb(mergedBreadcrumb, hint)) : mergedBreadcrumb;
|
|
1065
|
+
if (finalBreadcrumb === null) return;
|
|
1066
|
+
if (client.emit) {
|
|
1067
|
+
client.emit("beforeAddBreadcrumb", finalBreadcrumb, hint);
|
|
1068
|
+
}
|
|
1069
|
+
scope.addBreadcrumb(finalBreadcrumb, maxBreadcrumbs);
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* @inheritDoc
|
|
1073
|
+
*/
|
|
1074
|
+
setUser(user) {
|
|
1075
|
+
this.getScope().setUser(user);
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* @inheritDoc
|
|
1079
|
+
*/
|
|
1080
|
+
setTags(tags) {
|
|
1081
|
+
this.getScope().setTags(tags);
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* @inheritDoc
|
|
1085
|
+
*/
|
|
1086
|
+
setExtras(extras) {
|
|
1087
|
+
this.getScope().setExtras(extras);
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* @inheritDoc
|
|
1091
|
+
*/
|
|
1092
|
+
setTag(key, value) {
|
|
1093
|
+
this.getScope().setTag(key, value);
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* @inheritDoc
|
|
1097
|
+
*/
|
|
1098
|
+
setExtra(key, extra) {
|
|
1099
|
+
this.getScope().setExtra(key, extra);
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* @inheritDoc
|
|
1103
|
+
*/
|
|
1104
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1105
|
+
setContext(name, context) {
|
|
1106
|
+
this.getScope().setContext(name, context);
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* @inheritDoc
|
|
1110
|
+
*/
|
|
1111
|
+
configureScope(callback) {
|
|
1112
|
+
const { scope, client } = this.getStackTop();
|
|
1113
|
+
if (client) {
|
|
1114
|
+
callback(scope);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* @inheritDoc
|
|
1119
|
+
*/
|
|
1120
|
+
run(callback) {
|
|
1121
|
+
const oldHub = makeMain(this);
|
|
1122
|
+
try {
|
|
1123
|
+
callback(this);
|
|
1124
|
+
} finally {
|
|
1125
|
+
makeMain(oldHub);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* @inheritDoc
|
|
1130
|
+
*/
|
|
1131
|
+
getIntegration(integration) {
|
|
1132
|
+
const client = this.getClient();
|
|
1133
|
+
if (!client) return null;
|
|
1134
|
+
try {
|
|
1135
|
+
return client.getIntegration(integration);
|
|
1136
|
+
} catch (_oO) {
|
|
1137
|
+
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.warn(`Cannot retrieve integration ${integration.id} from the current Hub`);
|
|
1138
|
+
return null;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* @inheritDoc
|
|
1143
|
+
*/
|
|
1144
|
+
startTransaction(context, customSamplingContext) {
|
|
1145
|
+
const result = this._callExtensionMethod("startTransaction", context, customSamplingContext);
|
|
1146
|
+
if ((typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && !result) {
|
|
1147
|
+
const client = this.getClient();
|
|
1148
|
+
if (!client) {
|
|
1149
|
+
console.warn(
|
|
1150
|
+
"Tracing extension 'startTransaction' is missing. You should 'init' the SDK before calling 'startTransaction'"
|
|
1151
|
+
);
|
|
1152
|
+
} else {
|
|
1153
|
+
console.warn(`Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init':
|
|
1154
|
+
Sentry.addTracingExtensions();
|
|
1155
|
+
Sentry.init({...});
|
|
1156
|
+
`);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
return result;
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* @inheritDoc
|
|
1163
|
+
*/
|
|
1164
|
+
traceHeaders() {
|
|
1165
|
+
return this._callExtensionMethod("traceHeaders");
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* @inheritDoc
|
|
1169
|
+
*/
|
|
1170
|
+
captureSession(endSession = false) {
|
|
1171
|
+
if (endSession) {
|
|
1172
|
+
return this.endSession();
|
|
1173
|
+
}
|
|
1174
|
+
this._sendSessionUpdate();
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* @inheritDoc
|
|
1178
|
+
*/
|
|
1179
|
+
endSession() {
|
|
1180
|
+
const layer = this.getStackTop();
|
|
1181
|
+
const scope = layer.scope;
|
|
1182
|
+
const session = scope.getSession();
|
|
1183
|
+
if (session) {
|
|
1184
|
+
closeSession(session);
|
|
1185
|
+
}
|
|
1186
|
+
this._sendSessionUpdate();
|
|
1187
|
+
scope.setSession();
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* @inheritDoc
|
|
1191
|
+
*/
|
|
1192
|
+
startSession(context) {
|
|
1193
|
+
const { scope, client } = this.getStackTop();
|
|
1194
|
+
const { release, environment = DEFAULT_ENVIRONMENT } = client && client.getOptions() || {};
|
|
1195
|
+
const { userAgent } = GLOBAL_OBJ.navigator || {};
|
|
1196
|
+
const session = makeSession({
|
|
1197
|
+
release,
|
|
1198
|
+
environment,
|
|
1199
|
+
user: scope.getUser(),
|
|
1200
|
+
...userAgent && { userAgent },
|
|
1201
|
+
...context
|
|
1202
|
+
});
|
|
1203
|
+
const currentSession = scope.getSession && scope.getSession();
|
|
1204
|
+
if (currentSession && currentSession.status === "ok") {
|
|
1205
|
+
updateSession(currentSession, { status: "exited" });
|
|
1206
|
+
}
|
|
1207
|
+
this.endSession();
|
|
1208
|
+
scope.setSession(session);
|
|
1209
|
+
return session;
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Returns if default PII should be sent to Sentry and propagated in ourgoing requests
|
|
1213
|
+
* when Tracing is used.
|
|
1214
|
+
*/
|
|
1215
|
+
shouldSendDefaultPii() {
|
|
1216
|
+
const client = this.getClient();
|
|
1217
|
+
const options = client && client.getOptions();
|
|
1218
|
+
return Boolean(options && options.sendDefaultPii);
|
|
1219
|
+
}
|
|
1220
|
+
/**
|
|
1221
|
+
* Sends the current Session on the scope
|
|
1222
|
+
*/
|
|
1223
|
+
_sendSessionUpdate() {
|
|
1224
|
+
const { scope, client } = this.getStackTop();
|
|
1225
|
+
const session = scope.getSession();
|
|
1226
|
+
if (session && client && client.captureSession) {
|
|
1227
|
+
client.captureSession(session);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* Internal helper function to call a method on the top client if it exists.
|
|
1232
|
+
*
|
|
1233
|
+
* @param method The method to call on the client.
|
|
1234
|
+
* @param args Arguments to pass to the client function.
|
|
1235
|
+
*/
|
|
1236
|
+
_withClient(callback) {
|
|
1237
|
+
const { scope, client } = this.getStackTop();
|
|
1238
|
+
if (client) {
|
|
1239
|
+
callback(client, scope);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Calls global extension method and binding current instance to the function call
|
|
1244
|
+
*/
|
|
1245
|
+
// @ts-expect-error Function lacks ending return statement and return type does not include 'undefined'. ts(2366)
|
|
1246
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1247
|
+
_callExtensionMethod(method, ...args) {
|
|
1248
|
+
const carrier = getMainCarrier();
|
|
1249
|
+
const sentry = carrier.__SENTRY__;
|
|
1250
|
+
if (sentry && sentry.extensions && typeof sentry.extensions[method] === "function") {
|
|
1251
|
+
return sentry.extensions[method].apply(this, args);
|
|
1252
|
+
}
|
|
1253
|
+
(typeof __SENTRY_DEBUG__ === "undefined" || __SENTRY_DEBUG__) && logger.warn(`Extension method ${method} couldn't be found, doing nothing.`);
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
function getMainCarrier() {
|
|
1257
|
+
GLOBAL_OBJ.__SENTRY__ = GLOBAL_OBJ.__SENTRY__ || {
|
|
1258
|
+
extensions: {},
|
|
1259
|
+
hub: void 0
|
|
1260
|
+
};
|
|
1261
|
+
return GLOBAL_OBJ;
|
|
1262
|
+
}
|
|
1263
|
+
function makeMain(hub) {
|
|
1264
|
+
const registry = getMainCarrier();
|
|
1265
|
+
const oldHub = getHubFromCarrier(registry);
|
|
1266
|
+
setHubOnCarrier(registry, hub);
|
|
1267
|
+
return oldHub;
|
|
1268
|
+
}
|
|
1269
|
+
function getCurrentHub() {
|
|
1270
|
+
const registry = getMainCarrier();
|
|
1271
|
+
if (registry.__SENTRY__ && registry.__SENTRY__.acs) {
|
|
1272
|
+
const hub = registry.__SENTRY__.acs.getCurrentHub();
|
|
1273
|
+
if (hub) {
|
|
1274
|
+
return hub;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
return getGlobalHub(registry);
|
|
1278
|
+
}
|
|
1279
|
+
function getGlobalHub(registry = getMainCarrier()) {
|
|
1280
|
+
if (!hasHubOnCarrier(registry) || getHubFromCarrier(registry).isOlderThan(API_VERSION)) {
|
|
1281
|
+
setHubOnCarrier(registry, new Hub());
|
|
1282
|
+
}
|
|
1283
|
+
return getHubFromCarrier(registry);
|
|
1284
|
+
}
|
|
1285
|
+
function hasHubOnCarrier(carrier) {
|
|
1286
|
+
return !!(carrier && carrier.__SENTRY__ && carrier.__SENTRY__.hub);
|
|
1287
|
+
}
|
|
1288
|
+
function getHubFromCarrier(carrier) {
|
|
1289
|
+
return getGlobalSingleton("hub", () => new Hub(), carrier);
|
|
1290
|
+
}
|
|
1291
|
+
function setHubOnCarrier(carrier, hub) {
|
|
1292
|
+
if (!carrier) return false;
|
|
1293
|
+
const __SENTRY__ = carrier.__SENTRY__ = carrier.__SENTRY__ || {};
|
|
1294
|
+
__SENTRY__.hub = hub;
|
|
1295
|
+
return true;
|
|
1296
|
+
}
|
|
1297
|
+
function captureException(exception, captureContext) {
|
|
1298
|
+
return getCurrentHub().captureException(exception, { captureContext });
|
|
1299
|
+
}
|
|
1300
|
+
function captureMessage(message, captureContext) {
|
|
1301
|
+
const level = captureContext;
|
|
1302
|
+
const context = void 0;
|
|
1303
|
+
return getCurrentHub().captureMessage(message, level, context);
|
|
1304
|
+
}
|
|
1305
|
+
function addBreadcrumb(breadcrumb) {
|
|
1306
|
+
getCurrentHub().addBreadcrumb(breadcrumb);
|
|
1307
|
+
}
|
|
1308
|
+
function withScope(callback) {
|
|
1309
|
+
getCurrentHub().withScope(callback);
|
|
1310
|
+
}
|
|
1311
|
+
const SDK_TAG = "juo.blocks";
|
|
1312
|
+
function applyScope(scope, ctx) {
|
|
1313
|
+
var _a, _b, _c, _d;
|
|
1314
|
+
scope.setTag(`${SDK_TAG}.site`, ctx.site);
|
|
1315
|
+
if (ctx.block) {
|
|
1316
|
+
scope.setTag(`${SDK_TAG}.block_id`, ctx.block.id);
|
|
1317
|
+
scope.setTag(`${SDK_TAG}.block_type`, ctx.block.type);
|
|
1318
|
+
if ((_a = ctx.block.definition) == null ? void 0 : _a.name) {
|
|
1319
|
+
scope.setTag(`${SDK_TAG}.block_name`, ctx.block.definition.name);
|
|
1320
|
+
} else {
|
|
1321
|
+
scope.setTag(`${SDK_TAG}.block_name`, ctx.block.type);
|
|
1322
|
+
}
|
|
1323
|
+
if ((_b = ctx.block.definition) == null ? void 0 : _b.group) {
|
|
1324
|
+
scope.setTag(`${SDK_TAG}.block_group`, ctx.block.definition.group);
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
if ((_c = ctx.keys) == null ? void 0 : _c.props) {
|
|
1328
|
+
scope.setExtra("props_keys", ctx.keys.props);
|
|
1329
|
+
}
|
|
1330
|
+
if ((_d = ctx.keys) == null ? void 0 : _d.slots) {
|
|
1331
|
+
scope.setExtra("slots_keys", ctx.keys.slots);
|
|
1332
|
+
}
|
|
1333
|
+
if (ctx.extra) {
|
|
1334
|
+
for (const [key, value] of Object.entries(ctx.extra)) {
|
|
1335
|
+
if (value !== void 0) {
|
|
1336
|
+
scope.setExtra(key, value);
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
function reportBlockError(error, ctx) {
|
|
1342
|
+
console.error(`[${SDK_TAG}] ${ctx.site}`, error, ctx);
|
|
1343
|
+
try {
|
|
1344
|
+
withScope((scope) => {
|
|
1345
|
+
applyScope(scope, ctx);
|
|
1346
|
+
captureException(error);
|
|
1347
|
+
});
|
|
1348
|
+
} catch {
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
function reportBlockWarning(message, ctx) {
|
|
1352
|
+
console.warn(`[${SDK_TAG}] ${ctx.site}: ${message}`, ctx);
|
|
1353
|
+
try {
|
|
1354
|
+
withScope((scope) => {
|
|
1355
|
+
applyScope(scope, ctx);
|
|
1356
|
+
captureMessage(message, "warning");
|
|
1357
|
+
});
|
|
1358
|
+
} catch {
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
function blockBreadcrumb(message, ctx) {
|
|
1362
|
+
var _a, _b;
|
|
1363
|
+
try {
|
|
1364
|
+
addBreadcrumb({
|
|
1365
|
+
category: SDK_TAG,
|
|
1366
|
+
level: "info",
|
|
1367
|
+
message,
|
|
1368
|
+
data: {
|
|
1369
|
+
site: ctx.site,
|
|
1370
|
+
block_id: (_a = ctx.block) == null ? void 0 : _a.id,
|
|
1371
|
+
block_type: (_b = ctx.block) == null ? void 0 : _b.type
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
} catch {
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
export {
|
|
1378
|
+
blockBreadcrumb,
|
|
1379
|
+
reportBlockError,
|
|
1380
|
+
reportBlockWarning
|
|
1381
|
+
};
|