@mastra/observability 1.2.0 → 1.2.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.
package/dist/index.js CHANGED
@@ -5556,6 +5556,8 @@ var DefaultExporter = class extends BaseExporter {
5556
5556
  #resolvedStrategy;
5557
5557
  buffer;
5558
5558
  #flushTimer = null;
5559
+ #isInitializing = false;
5560
+ #initPromises = /* @__PURE__ */ new Set();
5559
5561
  // Track all spans that have been created, persists across flushes
5560
5562
  allCreatedSpans = /* @__PURE__ */ new Set();
5561
5563
  constructor(config = {}) {
@@ -5589,17 +5591,28 @@ var DefaultExporter = class extends BaseExporter {
5589
5591
  * Initialize the exporter (called after all dependencies are ready)
5590
5592
  */
5591
5593
  async init(options) {
5592
- this.#storage = options.mastra?.getStorage();
5593
- if (!this.#storage) {
5594
- this.logger.warn("DefaultExporter disabled: Storage not available. Traces will not be persisted.");
5595
- return;
5596
- }
5597
- this.#observability = await this.#storage.getStore("observability");
5598
- if (!this.#observability) {
5599
- this.logger.warn("DefaultExporter disabled: Observability storage not available. Traces will not be persisted.");
5600
- return;
5594
+ try {
5595
+ this.#isInitializing = true;
5596
+ this.#storage = options.mastra?.getStorage();
5597
+ if (!this.#storage) {
5598
+ this.logger.warn("DefaultExporter disabled: Storage not available. Traces will not be persisted.");
5599
+ return;
5600
+ }
5601
+ this.#observability = await this.#storage.getStore("observability");
5602
+ if (!this.#observability) {
5603
+ this.logger.warn(
5604
+ "DefaultExporter disabled: Observability storage not available. Traces will not be persisted."
5605
+ );
5606
+ return;
5607
+ }
5608
+ this.initializeStrategy(this.#observability, this.#storage.constructor.name);
5609
+ } finally {
5610
+ this.#isInitializing = false;
5611
+ this.#initPromises.forEach((resolve) => {
5612
+ resolve();
5613
+ });
5614
+ this.#initPromises.clear();
5601
5615
  }
5602
- this.initializeStrategy(this.#observability, this.#storage.constructor.name);
5603
5616
  }
5604
5617
  /**
5605
5618
  * Initialize the resolved strategy once observability store is available
@@ -6004,6 +6017,7 @@ var DefaultExporter = class extends BaseExporter {
6004
6017
  }
6005
6018
  }
6006
6019
  async _exportTracingEvent(event) {
6020
+ await this.waitForInit();
6007
6021
  if (!this.#observability) {
6008
6022
  this.logger.debug("Cannot store traces. Observability storage is not initialized");
6009
6023
  return;
@@ -6023,6 +6037,17 @@ var DefaultExporter = class extends BaseExporter {
6023
6037
  break;
6024
6038
  }
6025
6039
  }
6040
+ /**
6041
+ * Resolves when an ongoing init call is finished
6042
+ * Doesn't wait for the caller to call init
6043
+ * @returns
6044
+ */
6045
+ async waitForInit() {
6046
+ if (!this.#isInitializing) return;
6047
+ return new Promise((resolve) => {
6048
+ this.#initPromises.add(resolve);
6049
+ });
6050
+ }
6026
6051
  /**
6027
6052
  * Force flush any buffered spans without shutting down the exporter.
6028
6053
  * This is useful in serverless environments where you need to ensure spans
@@ -7451,6 +7476,7 @@ function compressJsonSchema(schema, depth = 0) {
7451
7476
  }
7452
7477
  function deepClean(value, options = DEFAULT_DEEP_CLEAN_OPTIONS) {
7453
7478
  const { keysToStrip, maxDepth, maxStringLength, maxArrayLength, maxObjectKeys } = options;
7479
+ const stripSet = keysToStrip instanceof Set ? keysToStrip : new Set(Array.isArray(keysToStrip) ? keysToStrip : Object.keys(keysToStrip));
7454
7480
  const seen = /* @__PURE__ */ new WeakSet();
7455
7481
  function helper(val, depth) {
7456
7482
  if (depth > maxDepth) {
@@ -7521,7 +7547,7 @@ function deepClean(value, options = DEFAULT_DEEP_CLEAN_OPTIONS) {
7521
7547
  const entries = Object.entries(val);
7522
7548
  let keyCount = 0;
7523
7549
  for (const [key, v] of entries) {
7524
- if (keysToStrip.has(key)) {
7550
+ if (stripSet.has(key)) {
7525
7551
  continue;
7526
7552
  }
7527
7553
  if (keyCount >= maxObjectKeys) {