@mastra/observability 1.13.0-alpha.0 → 1.13.0-alpha.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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @mastra/observability
2
2
 
3
+ ## 1.13.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - `MastraStorageExporter` now notifies custom exporters and connected integrations when it cannot persist observability events, such as unsupported storage or retries being exceeded. This matches the behavior already available on `DefaultExporter`. ([#16755](https://github.com/mastra-ai/mastra/pull/16755))
8
+
9
+ Also fixed an issue in both exporters where span updates waiting on their parent span could be silently lost if a later flush in the same cycle failed.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [[`5556cc1`](https://github.com/mastra-ai/mastra/commit/5556cc1befec71518d84f826b3bfe3a079a9daf7), [`5499303`](https://github.com/mastra-ai/mastra/commit/54993032c1ebc09642625b78d2014e0cf84a3cae), [`e47bca7`](https://github.com/mastra-ai/mastra/commit/e47bca7b72866d3abd173b9f530ac4318113a8ff), [`0031d0f`](https://github.com/mastra-ai/mastra/commit/0031d0f13831d7843ac5d498734a7d92862e2ce3), [`3498b49`](https://github.com/mastra-ai/mastra/commit/3498b4946be94f4313cd817733589680dcda5278), [`359439b`](https://github.com/mastra-ai/mastra/commit/359439bb8c635e048176306828195f8297f50021)]:
14
+ - @mastra/core@1.36.0-alpha.3
15
+
3
16
  ## 1.13.0-alpha.0
4
17
 
5
18
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/exporters/default.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACX,QAAQ,EACR,UAAU,EACV,aAAa,EAId,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAwB,sBAAsB,EAAwB,MAAM,sBAAsB,CAAC;AAS/G,OAAO,KAAK,EAAE,kBAA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AAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAW7D;;;;OAIG;YACW,WAAW;IAOzB;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAQtD;;OAEG;IACG,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAQhD;;OAEG;IACG,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpD;;OAEG;IACG,eAAe,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ1D;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAYhC"}
@@ -37,6 +37,8 @@ export declare class MastraStorageExporter extends BaseExporter {
37
37
  * Returns the flush promise when flushing so callers can await it.
38
38
  */
39
39
  private handleBatchedFlush;
40
+ private sanitizeDropError;
41
+ private emitDrop;
40
42
  /**
41
43
  * Flush a batch of create events for a single signal type.
42
44
  * On "not implemented" errors, disables the signal for future flushes.
@@ -1 +1 @@
1
- {"version":3,"file":"mastra-storage.d.ts","sourceRoot":"","sources":["../../src/exporters/mastra-storage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACX,QAAQ,EACR,UAAU,EACV,aAAa,EACd,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAwB,sBAAsB,EAAwB,MAAM,sBAAsB,CAAC;AAS/G,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC,4FAA4F;AAC5F,MAAM,WAAW,2BAA4B,SAAQ,kBAAkB;IACrE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc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AE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpD;;OAEG;IACG,eAAe,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ1D;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAYhC"}
package/dist/index.cjs CHANGED
@@ -16020,7 +16020,10 @@ var DefaultExporter = class extends BaseExporter {
16020
16020
  deferredUpdates.length = 0;
16021
16021
  this.emitDrop("tracing", "unsupported-storage", events.length + deferredCountAtEntry, error48);
16022
16022
  } else {
16023
- deferredUpdates.length = 0;
16023
+ const newlyDeferred = deferredUpdates.length - deferredCountAtEntry;
16024
+ if (newlyDeferred > 0) {
16025
+ deferredUpdates.splice(deferredUpdates.length - newlyDeferred, newlyDeferred);
16026
+ }
16024
16027
  const dropped = this.#eventBuffer.reAddUpdates(events);
16025
16028
  this.emitDrop("tracing", "retry-exhausted", dropped.length, error48);
16026
16029
  }
@@ -16719,6 +16722,7 @@ var MastraStorageExporter = class extends BaseExporter {
16719
16722
  #observabilityStorage;
16720
16723
  #resolvedStrategy;
16721
16724
  #flushTimer;
16725
+ #emitDropEvent;
16722
16726
  // Signals whose storage methods threw "not implemented" — skip on future flushes
16723
16727
  #unsupportedSignals = /* @__PURE__ */ new Set();
16724
16728
  constructor(config2 = {}) {
@@ -16740,6 +16744,7 @@ var MastraStorageExporter = class extends BaseExporter {
16740
16744
  async init(options) {
16741
16745
  try {
16742
16746
  this.#isInitializing = true;
16747
+ this.#emitDropEvent = options.emitDropEvent;
16743
16748
  this.#storage = options.mastra?.getStorage();
16744
16749
  if (!this.#storage) {
16745
16750
  this.logger.warn("MastraStorageExporter disabled: Storage not available. Traces will not be persisted.");
@@ -16825,21 +16830,54 @@ var MastraStorageExporter = class extends BaseExporter {
16825
16830
  this.scheduleFlush();
16826
16831
  }
16827
16832
  }
16833
+ sanitizeDropError(error48) {
16834
+ if (error48 instanceof error$1.MastraError) {
16835
+ return {
16836
+ id: error48.id,
16837
+ domain: String(error48.domain),
16838
+ message: error48.message
16839
+ };
16840
+ }
16841
+ if (error48 instanceof Error) {
16842
+ return { message: error48.message };
16843
+ }
16844
+ return { message: String(error48) };
16845
+ }
16846
+ emitDrop(signal, reason, count, error48) {
16847
+ if (count === 0) return;
16848
+ const dropEvent = {
16849
+ type: "drop",
16850
+ signal,
16851
+ reason,
16852
+ count,
16853
+ timestamp: /* @__PURE__ */ new Date(),
16854
+ exporterName: this.name,
16855
+ ...this.#observabilityStorage ? { storageName: this.#observabilityStorage.constructor.name } : {},
16856
+ ...error48 === void 0 ? {} : { error: this.sanitizeDropError(error48) }
16857
+ };
16858
+ this.#emitDropEvent?.(dropEvent);
16859
+ }
16828
16860
  /**
16829
16861
  * Flush a batch of create events for a single signal type.
16830
16862
  * On "not implemented" errors, disables the signal for future flushes.
16831
16863
  * On other errors, re-adds events to the buffer for retry.
16832
16864
  */
16833
16865
  async flushCreates(signal, events, storageCall) {
16834
- if (this.#unsupportedSignals.has(signal) || events.length === 0) return;
16866
+ if (events.length === 0) return;
16867
+ if (this.#unsupportedSignals.has(signal)) {
16868
+ this.emitDrop(signal, "unsupported-storage", events.length);
16869
+ return;
16870
+ }
16835
16871
  try {
16836
16872
  await storageCall(events);
16837
16873
  } catch (error48) {
16838
16874
  if (error48 instanceof error$1.MastraError && error48.domain === error$1.ErrorDomain.MASTRA_OBSERVABILITY && error48.id.endsWith("_NOT_IMPLEMENTED")) {
16839
16875
  this.logger.warn(error48.message);
16840
16876
  this.#unsupportedSignals.add(signal);
16877
+ this.emitDrop(signal, "unsupported-storage", events.length, error48);
16841
16878
  } else {
16842
- this.#eventBuffer.reAddCreates(events);
16879
+ const dropped = this.#eventBuffer.reAddCreates(events);
16880
+ this.emitDrop(signal, "retry-exhausted", dropped.length, error48);
16843
16881
  }
16844
16882
  }
16845
16883
  }
@@ -16848,7 +16886,12 @@ var MastraStorageExporter = class extends BaseExporter {
16848
16886
  * When `isEnd` is true, successfully flushed spans are removed from tracking.
16849
16887
  */
16850
16888
  async flushSpanUpdates(events, deferredUpdates, isEnd) {
16851
- if (this.#unsupportedSignals.has("tracing") || events.length === 0) return;
16889
+ const deferredCountAtEntry = deferredUpdates.length;
16890
+ if (events.length === 0) return;
16891
+ if (this.#unsupportedSignals.has("tracing")) {
16892
+ this.emitDrop("tracing", "unsupported-storage", events.length);
16893
+ return;
16894
+ }
16852
16895
  const partials = [];
16853
16896
  for (const event of events) {
16854
16897
  const span = event.exportedSpan;
@@ -16872,9 +16915,15 @@ var MastraStorageExporter = class extends BaseExporter {
16872
16915
  if (error48 instanceof error$1.MastraError && error48.domain === error$1.ErrorDomain.MASTRA_OBSERVABILITY && error48.id.endsWith("_NOT_IMPLEMENTED")) {
16873
16916
  this.logger.warn(error48.message);
16874
16917
  this.#unsupportedSignals.add("tracing");
16875
- } else {
16876
16918
  deferredUpdates.length = 0;
16877
- this.#eventBuffer.reAddUpdates(events);
16919
+ this.emitDrop("tracing", "unsupported-storage", events.length + deferredCountAtEntry, error48);
16920
+ } else {
16921
+ const newlyDeferred = deferredUpdates.length - deferredCountAtEntry;
16922
+ if (newlyDeferred > 0) {
16923
+ deferredUpdates.splice(deferredUpdates.length - newlyDeferred, newlyDeferred);
16924
+ }
16925
+ const dropped = this.#eventBuffer.reAddUpdates(events);
16926
+ this.emitDrop("tracing", "retry-exhausted", dropped.length, error48);
16878
16927
  }
16879
16928
  }
16880
16929
  }
@@ -16950,17 +16999,17 @@ var MastraStorageExporter = class extends BaseExporter {
16950
16999
  (events) => this.#observabilityStorage.batchCreateFeedback({ feedbacks: events.map((f) => storage.buildFeedbackRecord(f)) })
16951
17000
  ),
16952
17001
  this.flushCreates(
16953
- "logs",
17002
+ "log",
16954
17003
  createLogEvents,
16955
17004
  (events) => this.#observabilityStorage.batchCreateLogs({ logs: events.map((l) => storage.buildLogRecord(l)) })
16956
17005
  ),
16957
17006
  this.flushCreates(
16958
- "metrics",
17007
+ "metric",
16959
17008
  createMetricEvents,
16960
17009
  (events) => this.#observabilityStorage.batchCreateMetrics({ metrics: events.map((m) => storage.buildMetricRecord(m)) })
16961
17010
  ),
16962
17011
  this.flushCreates(
16963
- "scores",
17012
+ "score",
16964
17013
  createScoreEvents,
16965
17014
  (events) => this.#observabilityStorage.batchCreateScores({ scores: events.map((s) => storage.buildScoreRecord(s)) })
16966
17015
  ),
@@ -16974,7 +17023,13 @@ var MastraStorageExporter = class extends BaseExporter {
16974
17023
  await this.flushSpanUpdates(updateSpanEvents, deferredUpdates, false);
16975
17024
  await this.flushSpanUpdates(endSpanEvents, deferredUpdates, true);
16976
17025
  if (deferredUpdates.length > 0) {
16977
- this.#eventBuffer.reAddUpdates(deferredUpdates);
17026
+ if (this.#unsupportedSignals.has("tracing")) {
17027
+ this.emitDrop("tracing", "unsupported-storage", deferredUpdates.length);
17028
+ deferredUpdates.length = 0;
17029
+ } else {
17030
+ const dropped = this.#eventBuffer.reAddUpdates(deferredUpdates);
17031
+ this.emitDrop("tracing", "retry-exhausted", dropped.length);
17032
+ }
16978
17033
  }
16979
17034
  const elapsed = Date.now() - startTime;
16980
17035
  this.logger.debug("Batch flushed", {