@logspace/sdk 1.1.8 → 1.1.9
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/logspace.esm.js +69 -1
- package/logspace.esm.js.map +1 -1
- package/logspace.iife.js +1 -1
- package/logspace.iife.js.map +1 -1
- package/logspace.umd.js +1 -1
- package/logspace.umd.js.map +1 -1
- package/package.json +1 -1
- package/sdk/storage/indexed-db.d.ts +10 -0
package/logspace.esm.js
CHANGED
|
@@ -14490,7 +14490,7 @@ async function updatePendingSessionRetry(sessionId) {
|
|
|
14490
14490
|
async function cleanupOldPendingSessions() {
|
|
14491
14491
|
if (!isIndexedDBAvailable()) return;
|
|
14492
14492
|
const MAX_AGE_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
14493
|
-
const MAX_RETRIES =
|
|
14493
|
+
const MAX_RETRIES = 10;
|
|
14494
14494
|
const now = Date.now();
|
|
14495
14495
|
try {
|
|
14496
14496
|
const sessions = await getPendingSessions();
|
|
@@ -14505,6 +14505,18 @@ async function cleanupOldPendingSessions() {
|
|
|
14505
14505
|
console.warn("[LogSpace] Failed to cleanup old sessions:", error);
|
|
14506
14506
|
}
|
|
14507
14507
|
}
|
|
14508
|
+
function getBackoffInterval(retryCount) {
|
|
14509
|
+
const baseMs = 60 * 1e3;
|
|
14510
|
+
const maxMs = 60 * 60 * 1e3;
|
|
14511
|
+
const backoff = Math.min(baseMs * Math.pow(2, retryCount), maxMs);
|
|
14512
|
+
return backoff;
|
|
14513
|
+
}
|
|
14514
|
+
function isReadyForRetry(session2) {
|
|
14515
|
+
if (!session2.lastRetryAt) return true;
|
|
14516
|
+
const backoffMs = getBackoffInterval(session2.retryCount);
|
|
14517
|
+
const timeSinceLastRetry = Date.now() - session2.lastRetryAt;
|
|
14518
|
+
return timeSinceLastRetry >= backoffMs;
|
|
14519
|
+
}
|
|
14508
14520
|
function closeDB() {
|
|
14509
14521
|
if (db) {
|
|
14510
14522
|
db.close();
|
|
@@ -14532,7 +14544,9 @@ let idleTimer = null;
|
|
|
14532
14544
|
let durationTimer = null;
|
|
14533
14545
|
let checkpointTimer = null;
|
|
14534
14546
|
let visibilityTimer = null;
|
|
14547
|
+
let pendingRetryTimer = null;
|
|
14535
14548
|
let lastMouseMoveTime = 0;
|
|
14549
|
+
const PENDING_RETRY_INTERVAL = 2 * 60 * 1e3;
|
|
14536
14550
|
let samplingTriggered = false;
|
|
14537
14551
|
let samplingTriggerType = null;
|
|
14538
14552
|
let samplingFirstTriggerTime = null;
|
|
@@ -15192,6 +15206,48 @@ function stopCheckpointTimer() {
|
|
|
15192
15206
|
checkpointTimer = null;
|
|
15193
15207
|
}
|
|
15194
15208
|
}
|
|
15209
|
+
function startPendingRetryTimer() {
|
|
15210
|
+
if (pendingRetryTimer || !isIndexedDBAvailable()) return;
|
|
15211
|
+
pendingRetryTimer = setInterval(async () => {
|
|
15212
|
+
if (!config?.serverUrl) return;
|
|
15213
|
+
try {
|
|
15214
|
+
const pendingSessions = await getPendingSessions();
|
|
15215
|
+
if (pendingSessions.length === 0) return;
|
|
15216
|
+
const readySessions = pendingSessions.filter(isReadyForRetry);
|
|
15217
|
+
if (readySessions.length === 0) return;
|
|
15218
|
+
if (config.debug) {
|
|
15219
|
+
console.log(
|
|
15220
|
+
`[LogSpace] Periodic retry: ${readySessions.length} of ${pendingSessions.length} pending sessions ready`
|
|
15221
|
+
);
|
|
15222
|
+
}
|
|
15223
|
+
for (const stored of readySessions) {
|
|
15224
|
+
try {
|
|
15225
|
+
await sendPayloadToServer(stored.data);
|
|
15226
|
+
await removePendingSession(stored.id);
|
|
15227
|
+
if (config.debug) {
|
|
15228
|
+
console.log("[LogSpace] Pending session sent:", stored.id);
|
|
15229
|
+
}
|
|
15230
|
+
} catch (error) {
|
|
15231
|
+
await updatePendingSessionRetry(stored.id);
|
|
15232
|
+
if (config.debug) {
|
|
15233
|
+
const nextBackoff = Math.ceil(getBackoffInterval(stored.retryCount + 1) / 1e3);
|
|
15234
|
+
console.warn(`[LogSpace] Retry failed for ${stored.id}, next retry in ${nextBackoff}s`);
|
|
15235
|
+
}
|
|
15236
|
+
}
|
|
15237
|
+
}
|
|
15238
|
+
} catch (error) {
|
|
15239
|
+
if (config?.debug) {
|
|
15240
|
+
console.warn("[LogSpace] Periodic retry check failed:", error);
|
|
15241
|
+
}
|
|
15242
|
+
}
|
|
15243
|
+
}, PENDING_RETRY_INTERVAL);
|
|
15244
|
+
}
|
|
15245
|
+
function stopPendingRetryTimer() {
|
|
15246
|
+
if (pendingRetryTimer) {
|
|
15247
|
+
clearInterval(pendingRetryTimer);
|
|
15248
|
+
pendingRetryTimer = null;
|
|
15249
|
+
}
|
|
15250
|
+
}
|
|
15195
15251
|
const EMERGENCY_BACKUP_KEY = "__logspace_emergency_backup";
|
|
15196
15252
|
const SAMPLING_STATE_KEY = "__logspace_sampling_state";
|
|
15197
15253
|
function saveSamplingState(sessionId) {
|
|
@@ -15842,6 +15898,16 @@ async function recoverPendingSessions() {
|
|
|
15842
15898
|
await removePendingSession(stored.id);
|
|
15843
15899
|
continue;
|
|
15844
15900
|
}
|
|
15901
|
+
if (!isReadyForRetry(stored)) {
|
|
15902
|
+
if (config.debug) {
|
|
15903
|
+
const backoffMs = getBackoffInterval(stored.retryCount);
|
|
15904
|
+
const waitTime = Math.ceil((backoffMs - (Date.now() - (stored.lastRetryAt || 0))) / 1e3);
|
|
15905
|
+
console.log(
|
|
15906
|
+
`[LogSpace] Pending session ${stored.id} waiting for backoff (${waitTime}s remaining, retry #${stored.retryCount})`
|
|
15907
|
+
);
|
|
15908
|
+
}
|
|
15909
|
+
continue;
|
|
15910
|
+
}
|
|
15845
15911
|
try {
|
|
15846
15912
|
await sendPayloadToServer(stored.data);
|
|
15847
15913
|
processedRecoverySessionIds.add(stored.id);
|
|
@@ -15934,6 +16000,7 @@ const LogSpace = {
|
|
|
15934
16000
|
}
|
|
15935
16001
|
unloadHandled = false;
|
|
15936
16002
|
isNavigatingAway = false;
|
|
16003
|
+
startPendingRetryTimer();
|
|
15937
16004
|
this.startSession();
|
|
15938
16005
|
recoverPendingSessions().catch(() => {
|
|
15939
16006
|
});
|
|
@@ -16305,6 +16372,7 @@ const LogSpace = {
|
|
|
16305
16372
|
visibilityTimer = null;
|
|
16306
16373
|
}
|
|
16307
16374
|
stopCheckpointTimer();
|
|
16375
|
+
stopPendingRetryTimer();
|
|
16308
16376
|
stopSamplingTrimTimer();
|
|
16309
16377
|
if (config?.capture.rrweb) {
|
|
16310
16378
|
stopRRWebRecording();
|