@tracelog/lib 2.3.1 → 2.4.0

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.
@@ -66,7 +66,7 @@ type MetadataType = MetadataPrimitive | string[] | MetadataNestedObject | Metada
66
66
  * Result returned by tracelog.init()
67
67
  *
68
68
  * Contains the session identifier generated during initialization.
69
- * The sessionId is empty string in edge cases (SSR, disabled, race condition).
69
+ * The sessionId is empty string in edge cases (SSR, disabled).
70
70
  *
71
71
  * @example
72
72
  * ```typescript
@@ -445,6 +445,8 @@ interface Config {
445
445
  * Only applies when webVitalsMode is set. Overrides default thresholds for the selected mode.
446
446
  */
447
447
  webVitalsThresholds?: Partial<Record<WebVitalType, number>>;
448
+ /** Interval in milliseconds between event batch sends. @default 10000 (10 seconds) */
449
+ sendIntervalMs?: number;
448
450
  /** Optional configuration for third-party integrations. */
449
451
  integrations?: {
450
452
  /** TraceLog integration options. */
@@ -1180,7 +1182,7 @@ declare class StorageManager {
1180
1182
  *
1181
1183
  * **Core Functionality**:
1182
1184
  * - **Event Tracking**: Captures all user interactions (clicks, scrolls, page views, custom events, web vitals, errors)
1183
- * - **Queue Management**: Batches events with 10-second intervals to optimize network requests
1185
+ * - **Queue Management**: Batches events with 10-second base intervals (exponential backoff on failure) to optimize network requests
1184
1186
  * - **Deduplication**: LRU cache with 1000-entry fingerprint storage prevents duplicate events
1185
1187
  * - **Rate Limiting**: Client-side limits (50 events/second global, 60/minute per event name)
1186
1188
  * - **Per-Session Caps**: Configurable limits prevent runaway generation (1000 total, type-specific limits)
@@ -1243,8 +1245,9 @@ declare class EventManager extends StateManager {
1243
1245
  private readonly perEventRateLimits;
1244
1246
  private eventsQueue;
1245
1247
  private pendingEventsBuffer;
1246
- private sendIntervalId;
1248
+ private sendTimeoutId;
1247
1249
  private sendInProgress;
1250
+ private consecutiveSendFailures;
1248
1251
  private rateLimitCounter;
1249
1252
  private rateLimitWindowStart;
1250
1253
  private lastSessionId;
@@ -1356,7 +1359,7 @@ declare class EventManager extends StateManager {
1356
1359
  * and allow subsequent init() → destroy() → init() cycles.
1357
1360
  *
1358
1361
  * **Cleanup Actions**:
1359
- * 1. **Clear send interval**: Stops periodic 10-second queue flush timer
1362
+ * 1. **Clear send timeout**: Cancels pending queue flush timeout and resets backoff state
1360
1363
  * 2. **Clear all queues and buffers**:
1361
1364
  * - `eventsQueue`: Discarded (not sent)
1362
1365
  * - `pendingEventsBuffer`: Discarded (events before session init)
@@ -1366,8 +1369,8 @@ declare class EventManager extends StateManager {
1366
1369
  * 6. **Stop SenderManagers**: Calls `stop()` on all SenderManager instances
1367
1370
  *
1368
1371
  * **Important Behavior**:
1369
- * - **No final flush**: Events in queue are NOT sent before stopping
1370
- * - For flush before destroy, call `flushImmediatelySync()` first
1372
+ * - **No final flush**: `stop()` itself does NOT send queued events
1373
+ * - `App.destroy()` calls `flushImmediatelySync()` before `stop()` automatically
1371
1374
  *
1372
1375
  * **Multi-Integration**:
1373
1376
  * - Stops all SenderManager instances (SaaS + Custom)
@@ -1388,7 +1391,7 @@ declare class EventManager extends StateManager {
1388
1391
  * Flushes all events in the queue asynchronously.
1389
1392
  *
1390
1393
  * **Purpose**: Force immediate sending of queued events without waiting for
1391
- * the 10-second periodic flush timer.
1394
+ * the scheduled queue flush timeout.
1392
1395
  *
1393
1396
  * **Use Cases**:
1394
1397
  * - Manual flush triggered by user action
@@ -1553,7 +1556,7 @@ declare class EventManager extends StateManager {
1553
1556
  * @see src/managers/README.md (lines 5-75) for pending buffer details
1554
1557
  */
1555
1558
  flushPendingEvents(): void;
1556
- private clearSendInterval;
1559
+ private clearSendTimeout;
1557
1560
  private isSuccessfulResult;
1558
1561
  private flushEvents;
1559
1562
  private sendEventsQueue;
@@ -1564,7 +1567,8 @@ declare class EventManager extends StateManager {
1564
1567
  private createEventFingerprint;
1565
1568
  private createEventSignature;
1566
1569
  private addToQueue;
1567
- private startSendInterval;
1570
+ private scheduleSendTimeout;
1571
+ private calculateSendDelay;
1568
1572
  private shouldSample;
1569
1573
  private checkRateLimit;
1570
1574
  private checkPerEventRateLimit;
@@ -66,7 +66,7 @@ type MetadataType = MetadataPrimitive | string[] | MetadataNestedObject | Metada
66
66
  * Result returned by tracelog.init()
67
67
  *
68
68
  * Contains the session identifier generated during initialization.
69
- * The sessionId is empty string in edge cases (SSR, disabled, race condition).
69
+ * The sessionId is empty string in edge cases (SSR, disabled).
70
70
  *
71
71
  * @example
72
72
  * ```typescript
@@ -445,6 +445,8 @@ interface Config {
445
445
  * Only applies when webVitalsMode is set. Overrides default thresholds for the selected mode.
446
446
  */
447
447
  webVitalsThresholds?: Partial<Record<WebVitalType, number>>;
448
+ /** Interval in milliseconds between event batch sends. @default 10000 (10 seconds) */
449
+ sendIntervalMs?: number;
448
450
  /** Optional configuration for third-party integrations. */
449
451
  integrations?: {
450
452
  /** TraceLog integration options. */
@@ -1180,7 +1182,7 @@ declare class StorageManager {
1180
1182
  *
1181
1183
  * **Core Functionality**:
1182
1184
  * - **Event Tracking**: Captures all user interactions (clicks, scrolls, page views, custom events, web vitals, errors)
1183
- * - **Queue Management**: Batches events with 10-second intervals to optimize network requests
1185
+ * - **Queue Management**: Batches events with 10-second base intervals (exponential backoff on failure) to optimize network requests
1184
1186
  * - **Deduplication**: LRU cache with 1000-entry fingerprint storage prevents duplicate events
1185
1187
  * - **Rate Limiting**: Client-side limits (50 events/second global, 60/minute per event name)
1186
1188
  * - **Per-Session Caps**: Configurable limits prevent runaway generation (1000 total, type-specific limits)
@@ -1243,8 +1245,9 @@ declare class EventManager extends StateManager {
1243
1245
  private readonly perEventRateLimits;
1244
1246
  private eventsQueue;
1245
1247
  private pendingEventsBuffer;
1246
- private sendIntervalId;
1248
+ private sendTimeoutId;
1247
1249
  private sendInProgress;
1250
+ private consecutiveSendFailures;
1248
1251
  private rateLimitCounter;
1249
1252
  private rateLimitWindowStart;
1250
1253
  private lastSessionId;
@@ -1356,7 +1359,7 @@ declare class EventManager extends StateManager {
1356
1359
  * and allow subsequent init() → destroy() → init() cycles.
1357
1360
  *
1358
1361
  * **Cleanup Actions**:
1359
- * 1. **Clear send interval**: Stops periodic 10-second queue flush timer
1362
+ * 1. **Clear send timeout**: Cancels pending queue flush timeout and resets backoff state
1360
1363
  * 2. **Clear all queues and buffers**:
1361
1364
  * - `eventsQueue`: Discarded (not sent)
1362
1365
  * - `pendingEventsBuffer`: Discarded (events before session init)
@@ -1366,8 +1369,8 @@ declare class EventManager extends StateManager {
1366
1369
  * 6. **Stop SenderManagers**: Calls `stop()` on all SenderManager instances
1367
1370
  *
1368
1371
  * **Important Behavior**:
1369
- * - **No final flush**: Events in queue are NOT sent before stopping
1370
- * - For flush before destroy, call `flushImmediatelySync()` first
1372
+ * - **No final flush**: `stop()` itself does NOT send queued events
1373
+ * - `App.destroy()` calls `flushImmediatelySync()` before `stop()` automatically
1371
1374
  *
1372
1375
  * **Multi-Integration**:
1373
1376
  * - Stops all SenderManager instances (SaaS + Custom)
@@ -1388,7 +1391,7 @@ declare class EventManager extends StateManager {
1388
1391
  * Flushes all events in the queue asynchronously.
1389
1392
  *
1390
1393
  * **Purpose**: Force immediate sending of queued events without waiting for
1391
- * the 10-second periodic flush timer.
1394
+ * the scheduled queue flush timeout.
1392
1395
  *
1393
1396
  * **Use Cases**:
1394
1397
  * - Manual flush triggered by user action
@@ -1553,7 +1556,7 @@ declare class EventManager extends StateManager {
1553
1556
  * @see src/managers/README.md (lines 5-75) for pending buffer details
1554
1557
  */
1555
1558
  flushPendingEvents(): void;
1556
- private clearSendInterval;
1559
+ private clearSendTimeout;
1557
1560
  private isSuccessfulResult;
1558
1561
  private flushEvents;
1559
1562
  private sendEventsQueue;
@@ -1564,7 +1567,8 @@ declare class EventManager extends StateManager {
1564
1567
  private createEventFingerprint;
1565
1568
  private createEventSignature;
1566
1569
  private addToQueue;
1567
- private startSendInterval;
1570
+ private scheduleSendTimeout;
1571
+ private calculateSendDelay;
1568
1572
  private shouldSample;
1569
1573
  private checkRateLimit;
1570
1574
  private checkPerEventRateLimit;