@mastra/observability 1.20.0-alpha.1 → 1.20.1-alpha.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.
package/dist/index.js CHANGED
@@ -6396,6 +6396,8 @@ var TrackingExporter = class extends BaseExporter {
6396
6396
  #pendingCleanups = /* @__PURE__ */ new Map();
6397
6397
  /** Waiting-queue replays started by setImmediate that haven't finished yet */
6398
6398
  #activeReplays = /* @__PURE__ */ new Set();
6399
+ /** Hard-cap enforcements started by getTraceData() that haven't finished yet */
6400
+ #activeHardCapEnforcements = /* @__PURE__ */ new Set();
6399
6401
  /** Subclass configuration with resolved values */
6400
6402
  config;
6401
6403
  /** Maximum attempts to process a queued event before dropping */
@@ -6481,6 +6483,15 @@ var TrackingExporter = class extends BaseExporter {
6481
6483
  }
6482
6484
  }
6483
6485
  /**
6486
+ * Wait for fire-and-forget hard-cap enforcements, so the aborts they issue are
6487
+ * handed to the vendor before flush() / shutdown() send or abort anything else.
6488
+ * Only the ones running right now are joined; enforcements started by spans that
6489
+ * arrive later belong to a later flush, so this never spins under traffic.
6490
+ */
6491
+ async #drainHardCapEnforcements() {
6492
+ await Promise.all([...this.#activeHardCapEnforcements]);
6493
+ }
6494
+ /**
6484
6495
  * Process all events waiting for root span.
6485
6496
  * Takes the queue before processing, so a concurrent call can't process the same events.
6486
6497
  * @returns The number of events that left the queue (processed, moved or dropped)
@@ -7014,9 +7025,11 @@ var TrackingExporter = class extends BaseExporter {
7014
7025
  traceId,
7015
7026
  method
7016
7027
  });
7017
- this.#enforceHardCap().catch((error) => {
7028
+ const enforcement = this.#enforceHardCap().catch((error) => {
7018
7029
  this.logger.error(`${this.name}: Error enforcing hard cap`, { error });
7019
7030
  });
7031
+ this.#activeHardCapEnforcements.add(enforcement);
7032
+ enforcement.finally(() => this.#activeHardCapEnforcements.delete(enforcement));
7020
7033
  }
7021
7034
  return this.#traceMap.get(traceId);
7022
7035
  }
@@ -7049,6 +7062,7 @@ var TrackingExporter = class extends BaseExporter {
7049
7062
  if (this.isDisabled) return;
7050
7063
  this.logger.debug(`${this.name}: Flushing`);
7051
7064
  if (!this.#shutdownStarted) await this.#drainWaitingQueues();
7065
+ await this.#drainHardCapEnforcements();
7052
7066
  await this._flush();
7053
7067
  }
7054
7068
  /**
@@ -7069,6 +7083,7 @@ var TrackingExporter = class extends BaseExporter {
7069
7083
  if (this.isDisabled) return;
7070
7084
  this.#shutdownStarted = true;
7071
7085
  await this.#drainWaitingQueues();
7086
+ await this.#drainHardCapEnforcements();
7072
7087
  await this._preShutdown();
7073
7088
  for (const [traceId, timeout] of this.#pendingCleanups) {
7074
7089
  clearTimeout(timeout);