@tracelog/lib 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -557,7 +557,7 @@ var LONG_TASK_THROTTLE_MS = 1e3;
557
557
  var MAX_NAVIGATION_HISTORY = 50;
558
558
 
559
559
  // package.json
560
- var version = "2.2.1";
560
+ var version = "2.3.0";
561
561
 
562
562
  // src/constants/version.constants.ts
563
563
  var LIB_VERSION = version;
@@ -2535,6 +2535,7 @@ var EventManager = class extends StateManager {
2535
2535
  eventsQueue = [];
2536
2536
  pendingEventsBuffer = [];
2537
2537
  sendIntervalId = null;
2538
+ sendInProgress = false;
2538
2539
  rateLimitCounter = 0;
2539
2540
  rateLimitWindowStart = 0;
2540
2541
  lastSessionId = null;
@@ -3183,42 +3184,47 @@ var EventManager = class extends StateManager {
3183
3184
  }
3184
3185
  }
3185
3186
  async sendEventsQueue() {
3186
- if (!this.get("sessionId") || this.eventsQueue.length === 0) {
3187
+ if (!this.get("sessionId") || this.eventsQueue.length === 0 || this.sendInProgress) {
3187
3188
  return;
3188
3189
  }
3189
- const body = this.buildEventsPayload();
3190
- if (this.dataSenders.length === 0) {
3191
- this.emitEventsQueue(body);
3192
- return;
3193
- }
3194
- const eventsToSend = [...this.eventsQueue];
3195
- const eventIds = eventsToSend.map((e) => e.id);
3196
- const sendPromises = this.dataSenders.map(
3197
- async (sender) => sender.sendEventsQueue(body, {
3198
- onSuccess: () => {
3199
- },
3200
- onFailure: () => {
3190
+ this.sendInProgress = true;
3191
+ try {
3192
+ const body = this.buildEventsPayload();
3193
+ if (this.dataSenders.length === 0) {
3194
+ this.emitEventsQueue(body);
3195
+ return;
3196
+ }
3197
+ const eventsToSend = [...this.eventsQueue];
3198
+ const eventIds = eventsToSend.map((e) => e.id);
3199
+ const sendPromises = this.dataSenders.map(
3200
+ async (sender) => sender.sendEventsQueue(body, {
3201
+ onSuccess: () => {
3202
+ },
3203
+ onFailure: () => {
3204
+ }
3205
+ })
3206
+ );
3207
+ const results = await Promise.allSettled(sendPromises);
3208
+ const anySucceeded = results.some((result) => this.isSuccessfulResult(result));
3209
+ if (anySucceeded) {
3210
+ this.removeProcessedEvents(eventIds);
3211
+ this.emitEventsQueue(body);
3212
+ const failedCount = results.filter((result) => !this.isSuccessfulResult(result)).length;
3213
+ if (failedCount > 0) {
3214
+ log("debug", "Periodic send completed with some failures, removed from queue and persisted per-integration", {
3215
+ data: { eventCount: eventsToSend.length, failedCount }
3216
+ });
3201
3217
  }
3202
- })
3203
- );
3204
- const results = await Promise.allSettled(sendPromises);
3205
- const anySucceeded = results.some((result) => this.isSuccessfulResult(result));
3206
- if (anySucceeded) {
3207
- this.removeProcessedEvents(eventIds);
3208
- this.emitEventsQueue(body);
3209
- const failedCount = results.filter((result) => !this.isSuccessfulResult(result)).length;
3210
- if (failedCount > 0) {
3211
- log("debug", "Periodic send completed with some failures, removed from queue and persisted per-integration", {
3212
- data: { eventCount: eventsToSend.length, failedCount }
3218
+ } else {
3219
+ log("debug", "Periodic send complete failure, events kept in queue for retry", {
3220
+ data: { eventCount: eventsToSend.length }
3213
3221
  });
3214
3222
  }
3215
- } else {
3216
- log("debug", "Periodic send complete failure, events kept in queue for retry", {
3217
- data: { eventCount: eventsToSend.length }
3218
- });
3219
- }
3220
- if (this.eventsQueue.length === 0) {
3221
- this.clearSendInterval();
3223
+ if (this.eventsQueue.length === 0) {
3224
+ this.clearSendInterval();
3225
+ }
3226
+ } finally {
3227
+ this.sendInProgress = false;
3222
3228
  }
3223
3229
  }
3224
3230
  buildEventsPayload() {