@allstak/react 0.3.1 → 0.3.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/CHANGELOG.md +57 -0
- package/README.md +101 -162
- package/dist/build/chunk-G6VPGDP6.mjs +214 -0
- package/dist/build/chunk-G6VPGDP6.mjs.map +1 -0
- package/dist/build/chunk-ZY4H5AN4.mjs +32 -0
- package/dist/build/chunk-ZY4H5AN4.mjs.map +1 -0
- package/dist/build/next.d.mts +33 -0
- package/dist/build/next.d.ts +33 -0
- package/dist/build/next.js +274 -0
- package/dist/build/next.js.map +1 -0
- package/dist/build/next.mjs +26 -0
- package/dist/build/next.mjs.map +1 -0
- package/dist/build/sourcemaps.d.mts +160 -0
- package/dist/build/sourcemaps.d.ts +160 -0
- package/dist/build/sourcemaps.js +248 -0
- package/dist/build/sourcemaps.js.map +1 -0
- package/dist/build/sourcemaps.mjs +23 -0
- package/dist/build/sourcemaps.mjs.map +1 -0
- package/dist/build/vite.d.mts +65 -0
- package/dist/build/vite.d.ts +65 -0
- package/dist/build/vite.js +269 -0
- package/dist/build/vite.js.map +1 -0
- package/dist/build/vite.mjs +43 -0
- package/dist/build/vite.mjs.map +1 -0
- package/dist/build/webpack.d.mts +58 -0
- package/dist/build/webpack.d.ts +58 -0
- package/dist/build/webpack.js +256 -0
- package/dist/build/webpack.js.map +1 -0
- package/dist/build/webpack.mjs +8 -0
- package/dist/build/webpack.mjs.map +1 -0
- package/dist/index.d.mts +196 -42
- package/dist/index.d.ts +196 -42
- package/dist/index.js +435 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +435 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +25 -2
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,41 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import * as
|
|
2
|
+
import * as React2 from "react";
|
|
3
3
|
|
|
4
4
|
// src/transport.ts
|
|
5
|
-
var REQUEST_TIMEOUT =
|
|
5
|
+
var REQUEST_TIMEOUT = 2e3;
|
|
6
6
|
var MAX_BUFFER = 100;
|
|
7
|
+
var FAILURE_THRESHOLD = 3;
|
|
8
|
+
var BACKOFF_BASE_MS = 500;
|
|
9
|
+
var BACKOFF_MAX_MS = 3e4;
|
|
7
10
|
var HttpTransport = class {
|
|
8
11
|
constructor(baseUrl, apiKey) {
|
|
9
12
|
this.baseUrl = baseUrl;
|
|
10
13
|
this.apiKey = apiKey;
|
|
11
14
|
this.buffer = [];
|
|
12
15
|
this.flushing = false;
|
|
16
|
+
this.consecutiveFailures = 0;
|
|
17
|
+
this.circuitOpenUntil = 0;
|
|
18
|
+
}
|
|
19
|
+
send(path, payload) {
|
|
20
|
+
this.enqueueOrDispatch({ path, payload });
|
|
21
|
+
return Promise.resolve();
|
|
22
|
+
}
|
|
23
|
+
enqueueOrDispatch(item) {
|
|
24
|
+
if (Date.now() < this.circuitOpenUntil) {
|
|
25
|
+
this.push(item);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
void this.dispatch(item).catch(() => void 0);
|
|
13
29
|
}
|
|
14
|
-
async
|
|
30
|
+
async dispatch(item) {
|
|
15
31
|
try {
|
|
16
|
-
await this.doFetch(path, payload);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
await this.doFetch(item.path, item.payload);
|
|
33
|
+
this.consecutiveFailures = 0;
|
|
34
|
+
this.circuitOpenUntil = 0;
|
|
35
|
+
this.scheduleFlush();
|
|
36
|
+
} catch (err) {
|
|
37
|
+
this.recordFailure(err);
|
|
38
|
+
this.push(item);
|
|
21
39
|
}
|
|
22
40
|
}
|
|
23
41
|
async doFetch(path, payload) {
|
|
@@ -39,21 +57,49 @@ var HttpTransport = class {
|
|
|
39
57
|
clearTimeout(timeoutId);
|
|
40
58
|
}
|
|
41
59
|
}
|
|
60
|
+
push(item) {
|
|
61
|
+
if (this.buffer.length >= MAX_BUFFER) this.buffer.shift();
|
|
62
|
+
this.buffer.push(item);
|
|
63
|
+
}
|
|
64
|
+
scheduleFlush() {
|
|
65
|
+
if (this.flushing || this.buffer.length === 0) return;
|
|
66
|
+
const delay = Math.max(0, this.circuitOpenUntil - Date.now());
|
|
67
|
+
const timer = setTimeout(() => {
|
|
68
|
+
void this.flushBuffer().catch(() => void 0);
|
|
69
|
+
}, delay);
|
|
70
|
+
if (typeof timer === "object" && typeof timer.unref === "function") timer.unref();
|
|
71
|
+
}
|
|
42
72
|
async flushBuffer() {
|
|
43
73
|
if (this.flushing || this.buffer.length === 0) return;
|
|
44
74
|
this.flushing = true;
|
|
45
75
|
try {
|
|
46
76
|
const items = this.buffer.splice(0, this.buffer.length);
|
|
47
77
|
for (const item of items) {
|
|
78
|
+
if (Date.now() < this.circuitOpenUntil) {
|
|
79
|
+
this.push(item);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
48
82
|
try {
|
|
49
83
|
await this.doFetch(item.path, item.payload);
|
|
50
|
-
|
|
84
|
+
this.consecutiveFailures = 0;
|
|
85
|
+
this.circuitOpenUntil = 0;
|
|
86
|
+
} catch (err) {
|
|
87
|
+
this.recordFailure(err);
|
|
88
|
+
this.push(item);
|
|
51
89
|
}
|
|
52
90
|
}
|
|
53
91
|
} finally {
|
|
54
92
|
this.flushing = false;
|
|
93
|
+
if (this.buffer.length > 0) this.scheduleFlush();
|
|
55
94
|
}
|
|
56
95
|
}
|
|
96
|
+
recordFailure(error) {
|
|
97
|
+
this.consecutiveFailures++;
|
|
98
|
+
if (this.consecutiveFailures < FAILURE_THRESHOLD) return;
|
|
99
|
+
const retryAfterMs = retryAfterFromError(error);
|
|
100
|
+
const backoff = retryAfterMs ?? jitteredBackoff(this.consecutiveFailures);
|
|
101
|
+
this.circuitOpenUntil = Date.now() + backoff;
|
|
102
|
+
}
|
|
57
103
|
getBufferSize() {
|
|
58
104
|
return this.buffer.length;
|
|
59
105
|
}
|
|
@@ -73,6 +119,14 @@ var HttpTransport = class {
|
|
|
73
119
|
return true;
|
|
74
120
|
}
|
|
75
121
|
};
|
|
122
|
+
function jitteredBackoff(failures) {
|
|
123
|
+
const exp = Math.min(BACKOFF_MAX_MS, BACKOFF_BASE_MS * 2 ** Math.min(8, failures - FAILURE_THRESHOLD));
|
|
124
|
+
return Math.floor(exp / 2 + Math.random() * (exp / 2));
|
|
125
|
+
}
|
|
126
|
+
function retryAfterFromError(error) {
|
|
127
|
+
const message = error instanceof Error ? error.message : "";
|
|
128
|
+
return /HTTP\s+(429|503)/.test(message) ? BACKOFF_MAX_MS : null;
|
|
129
|
+
}
|
|
76
130
|
|
|
77
131
|
// src/stack.ts
|
|
78
132
|
var V8_FRAME_RE = /^\s*at\s+(?:(.+?)\s+\()?((?:.+?):(\d+):(\d+))\)?\s*$/;
|
|
@@ -173,36 +227,92 @@ function instrumentFetch(addBreadcrumb, ownBaseUrl) {
|
|
|
173
227
|
wrapped[FETCH_FLAG] = true;
|
|
174
228
|
g.fetch = wrapped;
|
|
175
229
|
}
|
|
176
|
-
|
|
230
|
+
var CONSOLE_DEFAULTS = {
|
|
231
|
+
log: false,
|
|
232
|
+
info: false,
|
|
233
|
+
warn: true,
|
|
234
|
+
error: true
|
|
235
|
+
};
|
|
236
|
+
var CONSOLE_METHOD_TO_LEVEL = {
|
|
237
|
+
log: "info",
|
|
238
|
+
info: "info",
|
|
239
|
+
warn: "warn",
|
|
240
|
+
error: "error"
|
|
241
|
+
};
|
|
242
|
+
var MAX_ARG_BYTES = 5e3;
|
|
243
|
+
function instrumentConsole(addBreadcrumb, options = {}) {
|
|
177
244
|
if (typeof console === "undefined") return;
|
|
178
245
|
if (console[CONSOLE_FLAG]) return;
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
} catch {
|
|
185
|
-
}
|
|
186
|
-
return origWarn.apply(console, args);
|
|
246
|
+
const opts = {
|
|
247
|
+
log: options.log ?? CONSOLE_DEFAULTS.log,
|
|
248
|
+
info: options.info ?? CONSOLE_DEFAULTS.info,
|
|
249
|
+
warn: options.warn ?? CONSOLE_DEFAULTS.warn,
|
|
250
|
+
error: options.error ?? CONSOLE_DEFAULTS.error
|
|
187
251
|
};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
252
|
+
const wrap = (method) => {
|
|
253
|
+
const orig = console[method];
|
|
254
|
+
if (typeof orig !== "function") return;
|
|
255
|
+
const level = CONSOLE_METHOD_TO_LEVEL[method];
|
|
256
|
+
console[method] = function(...args) {
|
|
257
|
+
if (opts[method]) {
|
|
258
|
+
try {
|
|
259
|
+
const serialized = args.map(safeStringifyArg);
|
|
260
|
+
const message = truncate(serialized.join(" "));
|
|
261
|
+
addBreadcrumb("log", message, level, {
|
|
262
|
+
category: "console",
|
|
263
|
+
method,
|
|
264
|
+
args: serialized
|
|
265
|
+
});
|
|
266
|
+
} catch {
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return orig.apply(console, args);
|
|
270
|
+
};
|
|
194
271
|
};
|
|
272
|
+
if (opts.log) wrap("log");
|
|
273
|
+
if (opts.info) wrap("info");
|
|
274
|
+
if (opts.warn) wrap("warn");
|
|
275
|
+
if (opts.error) wrap("error");
|
|
195
276
|
console[CONSOLE_FLAG] = true;
|
|
196
277
|
}
|
|
197
|
-
function
|
|
198
|
-
if (
|
|
278
|
+
function __resetConsoleInstrumentationFlagForTest() {
|
|
279
|
+
if (typeof console !== "undefined") {
|
|
280
|
+
delete console[CONSOLE_FLAG];
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function safeStringifyArg(v) {
|
|
284
|
+
if (v === null || v === void 0) return String(v);
|
|
199
285
|
if (typeof v === "string") return v;
|
|
200
|
-
if (v
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return
|
|
286
|
+
if (typeof v === "number" || typeof v === "boolean" || typeof v === "bigint") return String(v);
|
|
287
|
+
if (typeof v === "symbol") return v.toString();
|
|
288
|
+
if (typeof v === "function") return `[Function${v.name ? ` ${v.name}` : ""}]`;
|
|
289
|
+
if (v instanceof Error) {
|
|
290
|
+
return `${v.name || "Error"}: ${v.message}${v.stack ? `
|
|
291
|
+
${v.stack}` : ""}`;
|
|
292
|
+
}
|
|
293
|
+
if (typeof v === "object") {
|
|
294
|
+
try {
|
|
295
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
296
|
+
const out = JSON.stringify(v, (_key, val) => {
|
|
297
|
+
if (typeof val === "object" && val !== null) {
|
|
298
|
+
if (seen.has(val)) return "[Circular]";
|
|
299
|
+
seen.add(val);
|
|
300
|
+
}
|
|
301
|
+
if (typeof val === "bigint") return val.toString();
|
|
302
|
+
if (typeof val === "function") return `[Function${val.name ? ` ${val.name}` : ""}]`;
|
|
303
|
+
if (typeof val === "symbol") return val.toString();
|
|
304
|
+
return val;
|
|
305
|
+
});
|
|
306
|
+
return out ?? Object.prototype.toString.call(v);
|
|
307
|
+
} catch {
|
|
308
|
+
return Object.prototype.toString.call(v);
|
|
309
|
+
}
|
|
205
310
|
}
|
|
311
|
+
return String(v);
|
|
312
|
+
}
|
|
313
|
+
function truncate(s) {
|
|
314
|
+
if (s.length <= MAX_ARG_BYTES) return s;
|
|
315
|
+
return s.slice(0, MAX_ARG_BYTES) + "\u2026[truncated]";
|
|
206
316
|
}
|
|
207
317
|
|
|
208
318
|
// src/navigation.ts
|
|
@@ -1219,10 +1329,115 @@ function installHttpInstrumentation(module, options, ownIngestHost) {
|
|
|
1219
1329
|
};
|
|
1220
1330
|
}
|
|
1221
1331
|
|
|
1332
|
+
// src/web-vitals.ts
|
|
1333
|
+
var FLAG3 = "__allstak_web_vitals_started__";
|
|
1334
|
+
function startWebVitals(report) {
|
|
1335
|
+
const noop = { destroy: () => {
|
|
1336
|
+
} };
|
|
1337
|
+
if (typeof window === "undefined") return noop;
|
|
1338
|
+
if (typeof PerformanceObserver === "undefined") return noop;
|
|
1339
|
+
if (window[FLAG3]) return noop;
|
|
1340
|
+
window[FLAG3] = true;
|
|
1341
|
+
const observers = [];
|
|
1342
|
+
let lastLcp = 0;
|
|
1343
|
+
try {
|
|
1344
|
+
const obs = new PerformanceObserver((list) => {
|
|
1345
|
+
const entries = list.getEntries();
|
|
1346
|
+
const last = entries[entries.length - 1];
|
|
1347
|
+
if (last && typeof last.startTime === "number") {
|
|
1348
|
+
lastLcp = last.startTime;
|
|
1349
|
+
}
|
|
1350
|
+
});
|
|
1351
|
+
obs.observe({ type: "largest-contentful-paint", buffered: true });
|
|
1352
|
+
observers.push(obs);
|
|
1353
|
+
} catch {
|
|
1354
|
+
}
|
|
1355
|
+
let cls = 0;
|
|
1356
|
+
try {
|
|
1357
|
+
const obs = new PerformanceObserver((list) => {
|
|
1358
|
+
for (const entry of list.getEntries()) {
|
|
1359
|
+
if (!entry.hadRecentInput && typeof entry.value === "number") {
|
|
1360
|
+
cls += entry.value;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
});
|
|
1364
|
+
obs.observe({ type: "layout-shift", buffered: true });
|
|
1365
|
+
observers.push(obs);
|
|
1366
|
+
} catch {
|
|
1367
|
+
}
|
|
1368
|
+
let maxInteraction = 0;
|
|
1369
|
+
try {
|
|
1370
|
+
const obs = new PerformanceObserver((list) => {
|
|
1371
|
+
for (const entry of list.getEntries()) {
|
|
1372
|
+
if (typeof entry.duration === "number" && entry.duration > maxInteraction) {
|
|
1373
|
+
maxInteraction = entry.duration;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
});
|
|
1377
|
+
obs.observe({ type: "event", buffered: true, durationThreshold: 40 });
|
|
1378
|
+
observers.push(obs);
|
|
1379
|
+
} catch {
|
|
1380
|
+
}
|
|
1381
|
+
let fcp = 0;
|
|
1382
|
+
try {
|
|
1383
|
+
const obs = new PerformanceObserver((list) => {
|
|
1384
|
+
for (const entry of list.getEntries()) {
|
|
1385
|
+
if (entry.name === "first-contentful-paint") {
|
|
1386
|
+
fcp = entry.startTime;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
});
|
|
1390
|
+
obs.observe({ type: "paint", buffered: true });
|
|
1391
|
+
observers.push(obs);
|
|
1392
|
+
} catch {
|
|
1393
|
+
}
|
|
1394
|
+
const reportTtfb = () => {
|
|
1395
|
+
try {
|
|
1396
|
+
const navEntry = performance.getEntriesByType("navigation")[0];
|
|
1397
|
+
if (navEntry && typeof navEntry.responseStart === "number" && typeof navEntry.requestStart === "number") {
|
|
1398
|
+
const ttfb = Math.max(0, navEntry.responseStart - navEntry.requestStart);
|
|
1399
|
+
report({ name: "TTFB", value: ttfb });
|
|
1400
|
+
}
|
|
1401
|
+
} catch {
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
const finalize = () => {
|
|
1405
|
+
if (lastLcp > 0) report({ name: "LCP", value: lastLcp });
|
|
1406
|
+
report({ name: "CLS", value: cls });
|
|
1407
|
+
if (maxInteraction > 0) report({ name: "INP", value: maxInteraction });
|
|
1408
|
+
if (fcp > 0) report({ name: "FCP", value: fcp });
|
|
1409
|
+
reportTtfb();
|
|
1410
|
+
};
|
|
1411
|
+
const onVisibility = () => {
|
|
1412
|
+
if (document.visibilityState === "hidden") finalize();
|
|
1413
|
+
};
|
|
1414
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
1415
|
+
const onPagehide = () => finalize();
|
|
1416
|
+
window.addEventListener("pagehide", onPagehide);
|
|
1417
|
+
return {
|
|
1418
|
+
destroy: () => {
|
|
1419
|
+
for (const o of observers) {
|
|
1420
|
+
try {
|
|
1421
|
+
o.disconnect();
|
|
1422
|
+
} catch {
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
1426
|
+
window.removeEventListener("pagehide", onPagehide);
|
|
1427
|
+
window[FLAG3] = false;
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1431
|
+
function __resetWebVitalsFlagForTest() {
|
|
1432
|
+
if (typeof window !== "undefined") {
|
|
1433
|
+
window[FLAG3] = false;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1222
1437
|
// src/client.ts
|
|
1223
1438
|
var INGEST_HOST = "https://api.allstak.sa";
|
|
1224
1439
|
var SDK_NAME = "allstak-react";
|
|
1225
|
-
var SDK_VERSION = "0.3.
|
|
1440
|
+
var SDK_VERSION = "0.3.3";
|
|
1226
1441
|
var ERRORS_PATH = "/ingest/v1/errors";
|
|
1227
1442
|
var LOGS_PATH = "/ingest/v1/logs";
|
|
1228
1443
|
var VALID_BREADCRUMB_TYPES = /* @__PURE__ */ new Set(["http", "log", "ui", "navigation", "query", "default"]);
|
|
@@ -1256,6 +1471,7 @@ var AllStakClient = class {
|
|
|
1256
1471
|
this._instrumentAxios = null;
|
|
1257
1472
|
this.onErrorHandler = null;
|
|
1258
1473
|
this.onRejectionHandler = null;
|
|
1474
|
+
this.webVitals = null;
|
|
1259
1475
|
if (!config.apiKey) throw new Error("AllStak: config.apiKey is required");
|
|
1260
1476
|
this.config = { ...config };
|
|
1261
1477
|
if (!this.config.environment) this.config.environment = "production";
|
|
@@ -1282,7 +1498,7 @@ var AllStakClient = class {
|
|
|
1282
1498
|
}
|
|
1283
1499
|
if (config.autoBreadcrumbsConsole !== false) {
|
|
1284
1500
|
try {
|
|
1285
|
-
instrumentConsole(safeAddBreadcrumb);
|
|
1501
|
+
instrumentConsole(safeAddBreadcrumb, config.captureConsole);
|
|
1286
1502
|
} catch {
|
|
1287
1503
|
}
|
|
1288
1504
|
}
|
|
@@ -1292,6 +1508,32 @@ var AllStakClient = class {
|
|
|
1292
1508
|
} catch {
|
|
1293
1509
|
}
|
|
1294
1510
|
}
|
|
1511
|
+
if (config.autoWebVitals !== false) {
|
|
1512
|
+
try {
|
|
1513
|
+
const send = (m) => {
|
|
1514
|
+
this.transport.send(LOGS_PATH, {
|
|
1515
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1516
|
+
level: "info",
|
|
1517
|
+
message: `web-vital:${m.name}=${m.value.toFixed(2)}`,
|
|
1518
|
+
sessionId: this.sessionId,
|
|
1519
|
+
environment: this.config.environment,
|
|
1520
|
+
release: this.config.release,
|
|
1521
|
+
platform: this.config.platform,
|
|
1522
|
+
sdkName: this.config.sdkName,
|
|
1523
|
+
sdkVersion: this.config.sdkVersion,
|
|
1524
|
+
metadata: {
|
|
1525
|
+
category: "web-vital",
|
|
1526
|
+
name: m.name,
|
|
1527
|
+
value: m.value,
|
|
1528
|
+
...m.id ? { id: m.id } : {},
|
|
1529
|
+
...this.releaseTags()
|
|
1530
|
+
}
|
|
1531
|
+
});
|
|
1532
|
+
};
|
|
1533
|
+
this.webVitals = startWebVitals(send);
|
|
1534
|
+
} catch {
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1295
1537
|
if (config.replay && (config.replay.enabled ?? true)) {
|
|
1296
1538
|
try {
|
|
1297
1539
|
this.replay = new ReplayRecorder(this.transport, this.sessionId, safeAddBreadcrumb, config.replay);
|
|
@@ -1516,6 +1758,10 @@ var AllStakClient = class {
|
|
|
1516
1758
|
this.httpRequests.destroy();
|
|
1517
1759
|
this.httpRequests = null;
|
|
1518
1760
|
}
|
|
1761
|
+
if (this.webVitals) {
|
|
1762
|
+
this.webVitals.destroy();
|
|
1763
|
+
this.webVitals = null;
|
|
1764
|
+
}
|
|
1519
1765
|
this._instrumentAxios = null;
|
|
1520
1766
|
this.breadcrumbs = [];
|
|
1521
1767
|
}
|
|
@@ -1745,8 +1991,154 @@ var AllStak = {
|
|
|
1745
1991
|
}
|
|
1746
1992
|
};
|
|
1747
1993
|
|
|
1994
|
+
// src/provider.tsx
|
|
1995
|
+
import * as React from "react";
|
|
1996
|
+
var AllStakContext = React.createContext(null);
|
|
1997
|
+
var __providerOwnedInstance = null;
|
|
1998
|
+
var AllStakErrorBoundaryInner = class extends React.Component {
|
|
1999
|
+
constructor() {
|
|
2000
|
+
super(...arguments);
|
|
2001
|
+
this.state = { error: null };
|
|
2002
|
+
this.resetError = () => this.setState({ error: null });
|
|
2003
|
+
}
|
|
2004
|
+
static getDerivedStateFromError(error) {
|
|
2005
|
+
return { error };
|
|
2006
|
+
}
|
|
2007
|
+
componentDidCatch(error, info) {
|
|
2008
|
+
try {
|
|
2009
|
+
AllStak.addBreadcrumb("ui", "React error boundary caught error", "error", {
|
|
2010
|
+
componentStack: info.componentStack ?? ""
|
|
2011
|
+
});
|
|
2012
|
+
AllStak.captureException(error, {
|
|
2013
|
+
componentStack: info.componentStack ?? "",
|
|
2014
|
+
source: "AllStakProvider.ErrorBoundary"
|
|
2015
|
+
});
|
|
2016
|
+
if (this.props.debug) {
|
|
2017
|
+
console.log(`[AllStak] Captured render error: ${error.message}`);
|
|
2018
|
+
}
|
|
2019
|
+
} catch {
|
|
2020
|
+
}
|
|
2021
|
+
try {
|
|
2022
|
+
this.props.onError?.(error, info.componentStack ?? void 0);
|
|
2023
|
+
} catch {
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
render() {
|
|
2027
|
+
if (this.state.error) {
|
|
2028
|
+
const { fallback } = this.props;
|
|
2029
|
+
if (typeof fallback === "function") {
|
|
2030
|
+
return fallback({ error: this.state.error, resetError: this.resetError });
|
|
2031
|
+
}
|
|
2032
|
+
if (fallback !== void 0) return fallback;
|
|
2033
|
+
return null;
|
|
2034
|
+
}
|
|
2035
|
+
return this.props.children;
|
|
2036
|
+
}
|
|
2037
|
+
};
|
|
2038
|
+
function AllStakProvider({
|
|
2039
|
+
children,
|
|
2040
|
+
apiKey,
|
|
2041
|
+
environment,
|
|
2042
|
+
release,
|
|
2043
|
+
host,
|
|
2044
|
+
user,
|
|
2045
|
+
tags,
|
|
2046
|
+
debug,
|
|
2047
|
+
enableHttpTracking,
|
|
2048
|
+
httpTracking,
|
|
2049
|
+
captureConsole,
|
|
2050
|
+
sampleRate,
|
|
2051
|
+
beforeSend,
|
|
2052
|
+
replay,
|
|
2053
|
+
tracesSampleRate,
|
|
2054
|
+
service,
|
|
2055
|
+
dist,
|
|
2056
|
+
autoCaptureBrowserErrors,
|
|
2057
|
+
autoBreadcrumbsFetch,
|
|
2058
|
+
autoBreadcrumbsConsole,
|
|
2059
|
+
autoBreadcrumbsNavigation,
|
|
2060
|
+
autoWebVitals,
|
|
2061
|
+
destroyOnUnmount = false,
|
|
2062
|
+
fallback,
|
|
2063
|
+
onError
|
|
2064
|
+
}) {
|
|
2065
|
+
const clientRef = React.useRef(null);
|
|
2066
|
+
if (!clientRef.current) {
|
|
2067
|
+
const existing = AllStak._getInstance();
|
|
2068
|
+
if (existing && __providerOwnedInstance === existing) {
|
|
2069
|
+
clientRef.current = existing;
|
|
2070
|
+
if (debug) {
|
|
2071
|
+
console.log(`[AllStak] Reusing session ${AllStak.getSessionId()}`);
|
|
2072
|
+
}
|
|
2073
|
+
} else {
|
|
2074
|
+
const config = {
|
|
2075
|
+
apiKey,
|
|
2076
|
+
environment,
|
|
2077
|
+
release,
|
|
2078
|
+
host,
|
|
2079
|
+
user,
|
|
2080
|
+
tags,
|
|
2081
|
+
enableHttpTracking,
|
|
2082
|
+
httpTracking,
|
|
2083
|
+
captureConsole,
|
|
2084
|
+
sampleRate,
|
|
2085
|
+
beforeSend,
|
|
2086
|
+
replay,
|
|
2087
|
+
tracesSampleRate,
|
|
2088
|
+
service,
|
|
2089
|
+
dist,
|
|
2090
|
+
autoCaptureBrowserErrors,
|
|
2091
|
+
autoBreadcrumbsFetch,
|
|
2092
|
+
autoBreadcrumbsConsole,
|
|
2093
|
+
autoBreadcrumbsNavigation,
|
|
2094
|
+
autoWebVitals
|
|
2095
|
+
};
|
|
2096
|
+
clientRef.current = AllStak.init(config);
|
|
2097
|
+
__providerOwnedInstance = clientRef.current;
|
|
2098
|
+
if (debug) {
|
|
2099
|
+
console.log(`[AllStak] Initialized \u2014 session ${AllStak.getSessionId()}`);
|
|
2100
|
+
if (autoBreadcrumbsNavigation !== false) {
|
|
2101
|
+
console.log("[AllStak] Navigation auto-instrumentation enabled");
|
|
2102
|
+
} else {
|
|
2103
|
+
console.log("[AllStak] Navigation auto-instrumentation not applied; use manual fallback");
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
React.useEffect(() => {
|
|
2109
|
+
return () => {
|
|
2110
|
+
if (destroyOnUnmount) {
|
|
2111
|
+
AllStak.destroy();
|
|
2112
|
+
__providerOwnedInstance = null;
|
|
2113
|
+
clientRef.current = null;
|
|
2114
|
+
if (debug) {
|
|
2115
|
+
console.log("[AllStak] Destroyed on unmount");
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
};
|
|
2119
|
+
}, [destroyOnUnmount, debug]);
|
|
2120
|
+
return /* @__PURE__ */ React.createElement(AllStakContext.Provider, { value: clientRef.current }, /* @__PURE__ */ React.createElement(AllStakErrorBoundaryInner, { fallback, onError, debug }, children));
|
|
2121
|
+
}
|
|
2122
|
+
function useAllStak() {
|
|
2123
|
+
return React.useMemo(
|
|
2124
|
+
() => ({
|
|
2125
|
+
captureException: (error, ctx) => AllStak.captureException(error, ctx),
|
|
2126
|
+
captureMessage: (msg, level = "info") => AllStak.captureMessage(msg, level),
|
|
2127
|
+
setUser: (user) => AllStak.setUser(user),
|
|
2128
|
+
setTag: (key, value) => AllStak.setTag(key, value),
|
|
2129
|
+
setContext: (name, ctx) => AllStak.setContext(name, ctx),
|
|
2130
|
+
addBreadcrumb: (type, message, level, data) => AllStak.addBreadcrumb(type, message, level, data),
|
|
2131
|
+
flush: (timeoutMs) => AllStak.flush(timeoutMs)
|
|
2132
|
+
}),
|
|
2133
|
+
[]
|
|
2134
|
+
);
|
|
2135
|
+
}
|
|
2136
|
+
function __resetProviderInstanceForTest() {
|
|
2137
|
+
__providerOwnedInstance = null;
|
|
2138
|
+
}
|
|
2139
|
+
|
|
1748
2140
|
// src/index.ts
|
|
1749
|
-
var AllStakErrorBoundary = class extends
|
|
2141
|
+
var AllStakErrorBoundary = class extends React2.Component {
|
|
1750
2142
|
constructor() {
|
|
1751
2143
|
super(...arguments);
|
|
1752
2144
|
this.state = { error: null };
|
|
@@ -1789,25 +2181,13 @@ var AllStakErrorBoundary = class extends React.Component {
|
|
|
1789
2181
|
return this.props.children;
|
|
1790
2182
|
}
|
|
1791
2183
|
};
|
|
1792
|
-
function
|
|
1793
|
-
|
|
1794
|
-
() => ({
|
|
1795
|
-
captureException: (error, ctx) => AllStak.captureException(error, ctx),
|
|
1796
|
-
captureMessage: (msg, level = "info") => AllStak.captureMessage(msg, level),
|
|
1797
|
-
setUser: (user) => AllStak.setUser(user),
|
|
1798
|
-
setTag: (key, value) => AllStak.setTag(key, value),
|
|
1799
|
-
addBreadcrumb: (type, message, level, data) => AllStak.addBreadcrumb(type, message, level, data)
|
|
1800
|
-
}),
|
|
1801
|
-
[]
|
|
1802
|
-
);
|
|
1803
|
-
}
|
|
1804
|
-
function withAllStakProfiler(Component2, name) {
|
|
1805
|
-
const displayName = name ?? Component2.displayName ?? Component2.name ?? "AnonymousComponent";
|
|
2184
|
+
function withAllStakProfiler(Component3, name) {
|
|
2185
|
+
const displayName = name ?? Component3.displayName ?? Component3.name ?? "AnonymousComponent";
|
|
1806
2186
|
const Wrapped = (props) => {
|
|
1807
|
-
|
|
2187
|
+
React2.useEffect(() => {
|
|
1808
2188
|
AllStak.addBreadcrumb("navigation", `Mounted <${displayName}>`, "info");
|
|
1809
2189
|
}, []);
|
|
1810
|
-
return
|
|
2190
|
+
return React2.createElement(Component3, props);
|
|
1811
2191
|
};
|
|
1812
2192
|
Wrapped.displayName = `withAllStakProfiler(${displayName})`;
|
|
1813
2193
|
return Wrapped;
|
|
@@ -1816,17 +2196,22 @@ export {
|
|
|
1816
2196
|
AllStak,
|
|
1817
2197
|
AllStakClient,
|
|
1818
2198
|
AllStakErrorBoundary,
|
|
2199
|
+
AllStakProvider,
|
|
1819
2200
|
HttpRequestModule,
|
|
1820
2201
|
INGEST_HOST,
|
|
1821
2202
|
ReplayRecorder,
|
|
1822
2203
|
SDK_NAME,
|
|
1823
2204
|
SDK_VERSION,
|
|
1824
2205
|
Scope,
|
|
2206
|
+
__resetConsoleInstrumentationFlagForTest,
|
|
2207
|
+
__resetProviderInstanceForTest,
|
|
2208
|
+
__resetWebVitalsFlagForTest,
|
|
1825
2209
|
instrumentBrowserNavigation,
|
|
1826
2210
|
instrumentConsole,
|
|
1827
2211
|
instrumentFetch,
|
|
1828
2212
|
instrumentNextRouter,
|
|
1829
2213
|
instrumentReactRouter,
|
|
2214
|
+
startWebVitals,
|
|
1830
2215
|
useAllStak,
|
|
1831
2216
|
withAllStakProfiler
|
|
1832
2217
|
};
|