@mastra/observability 1.20.0-alpha.0 → 1.20.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.
@@ -1 +1 @@
1
- {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../src/default.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EACV,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,aAAa,EAEb,uBAAuB,EAEvB,qBAAqB,EACrB,aAAa,EACb,UAAU,EAEX,MAAM,4BAA4B,CAAC;AAKpC,OAAO,KAAK,EAA+B,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAkCzF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,aAAc,SAAQ,UAAW,YAAW,uBAAuB;;IAK9E,YAAY,MAAM,EAAE,2BAA2B,EA8I9C;IAED,yFAAyF;IACzF,gBAAgB,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAoClD;IAED,sFAAsF;IACtF,SAAS,CAAC,OAAO,EAAE;QAAE,MAAM,EAAE,aAAa,CAAA;KAAE,GAAG,IAAI,CAKlD;IAED,0FAA0F;IAC1F,mBAAmB,CAAC,OAAO,EAAE,qBAAqB,GAAG,qBAAqB,GAAG,SAAS,CAErF;IAEK,gBAAgB,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CA2B/E;IAEK,QAAQ,CAAC,IAAI,EAAE;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB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kB,CAAC;QACxC,QAAQ,EAAE,aAAa,CAAC;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgChB;IAED,iFAAiF;IACjF,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,qBAAqB,EAAE,SAAS,UAAQ,GAAG,IAAI,CASvF;IAED,yCAAyC;IACzC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAE3D;IAED,8CAA8C;IAC9C,kBAAkB,IAAI,qBAAqB,GAAG,SAAS,CAEtD;IAED,mDAAmD;IACnD,aAAa,IAAI,WAAW,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAE1D;IAED,gFAAgF;IAChF,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExC;IAED,mEAAmE;IACnE,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjC;IAED,qEAAqE;IACrE,iBAAiB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAEhD;IAED,8DAA8D;IAC9D,KAAK,IAAI,IAAI,CAEZ;IAED,4DAA4D;IACtD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAED,qEAAqE;IAC/D,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAE9B;IAED;;;;;;;;OAQG;IACH,2BAA2B,IAAI,wBAAwB,GAAG,SAAS,CAQlE;CA2EF"}
@@ -64,6 +64,11 @@ export declare class DefaultExporter extends BaseExporter {
64
64
  * When `isEnd` is true, successfully flushed spans are removed from tracking.
65
65
  */
66
66
  private flushSpanUpdates;
67
+ /**
68
+ * Runs flushBuffer() and tracks its promise so flush() can wait for writes
69
+ * that a timer or size trigger started on their own.
70
+ */
71
+ private trackFlushBuffer;
67
72
  /**
68
73
  * Flushes the current buffer to storage.
69
74
  *
@@ -1 +1 @@
1
- {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/exporters/default.ts"],"names":[],"mappings":"AAEA,OAAO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,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmDtD;IAED;;OAEG;IACH,OAAO,CAAC,WAAW;IAyBnB;;OAEG;IACH,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,iBAAiB;IAiBzB;;;;OAIG;YACW,kBAAkB;IAQhC,OAAO,CAAC,iBAAiB;IAgBzB,OAAO,CAAC,QAAQ;IAsBhB;;;;OAIG;YACW,YAAY;IAkC1B;;;OAGG;YACW,gBAAgB;IA+D9B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAMxB;;;;;;;OAOG;YACW,WAAW;IA+HnB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAS5D;IAED;;;;OAIG;YACW,WAAW;IAOzB;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAMrD;IAED;;OAEG;IACG,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAM/C;IAED;;OAEG;IACG,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAMnD;IAED;;OAEG;IACG,eAAe,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAMzD;IAED;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CA2B3B;IAEK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAgB9B;CACF"}
@@ -56,6 +56,11 @@ export declare class MastraStorageExporter extends BaseExporter {
56
56
  * When `isEnd` is true, successfully flushed spans are removed from tracking.
57
57
  */
58
58
  private flushSpanUpdates;
59
+ /**
60
+ * Runs flushBuffer() and tracks its promise so flush() can wait for writes
61
+ * that a timer or size trigger started on their own.
62
+ */
63
+ private trackFlushBuffer;
59
64
  /**
60
65
  * Flushes the current buffer to storage.
61
66
  *
@@ -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,EAId,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,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IAGtB,QAAQ,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAAC;CAC5C;AAkCD;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,YAAY;;IACrD,IAAI,SAA6B;IAgBjC,YAAY,MAAM,GAAE,2BAAgC,EAenD;IAED;;OAEG;IACG,IAAI,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAQtD;IAED,OAAO,CAAC,eAAe;YAUT,iBAAiB;YA6CjB,iBAAiB;IAS/B;;OAEG;IACH,OAAO,CAAC,WAAW;IAyBnB;;OAEG;IACH,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,iBAAiB;IAiBzB;;;;OAIG;YACW,kBAAkB;IAQhC,OAAO,CAAC,iBAAiB;IAgBzB,OAAO,CAAC,QAAQ;IAsBhB;;;;OAIG;YACW,YAAY;IAkC1B;;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ODELS_DEV_API_URL = "https://models.dev/api.json";
1176
1176
  * not replace the pricing in use. The full catalog prices roughly 8,000 models.
1177
1177
  */
1178
1178
  const MIN_PRICED_MODELS = 1e3;
1179
- /** models.dev `cost` keys (USD per 1M tokens) mapped to pricing meters. */
1179
+ /** models.dev `cost` keys (USD per 1M tokens) mapped to pricing meters. Keyed by core's `ModelPricingRates` so the two cannot drift. */
1180
1180
  const COST_KEY_TO_METER = {
1181
1181
  input: "input_tokens",
1182
1182
  output: "output_tokens",
@@ -1316,6 +1316,7 @@ const BEDROCK_GEOGRAPHY_PREFIXES = /* @__PURE__ */ new Set([
1316
1316
  "au"
1317
1317
  ]);
1318
1318
  const AI_SDK_VERCEL_GATEWAY_PROVIDER_ID = "gateway";
1319
+ const AZURE_OPENAI_GATEWAY_ID = "azure-openai";
1319
1320
  const VERCEL_PRICING_PROVIDER_ID = "vercel";
1320
1321
  const AI_SDK_PROVIDER_NAMESPACE_ALIASES = /* @__PURE__ */ new Map([
1321
1322
  ["fireworks", "fireworks-ai"],
@@ -1326,6 +1327,11 @@ const AI_SDK_PROVIDER_NAMESPACE_ALIASES = /* @__PURE__ */ new Map([
1326
1327
  let cachedLoadError = null;
1327
1328
  let globalRegistry = null;
1328
1329
  let bundledRegistry = null;
1330
+ let gatewayRegistry = null;
1331
+ let gatewayCosts = {};
1332
+ let gatewaySource = null;
1333
+ const gatewayLoadAttempts = /* @__PURE__ */ new Map();
1334
+ let gatewayLoadInFlight = false;
1329
1335
  let refreshedAt = 0;
1330
1336
  let lastRefreshAttemptAt = 0;
1331
1337
  let refreshEtag;
@@ -1354,10 +1360,10 @@ var PricingRegistry = class PricingRegistry {
1354
1360
  return globalRegistry;
1355
1361
  }
1356
1362
  get(args) {
1357
- const match = this.find(args);
1358
- if (match || this !== globalRegistry) return match;
1359
- const bundledMatch = this === bundledRegistry ? null : getBundledRegistry()?.find(args);
1360
- if (bundledMatch) return bundledMatch;
1363
+ if (this !== globalRegistry) return this.find(args);
1364
+ const match = this.find(args) ?? (this === bundledRegistry ? null : getBundledRegistry()?.find(args)) ?? gatewayRegistry?.find(args);
1365
+ if (match) return match;
1366
+ loadGatewayPricing();
1361
1367
  refreshGlobalPricing();
1362
1368
  return null;
1363
1369
  }
@@ -1380,12 +1386,70 @@ function getBundledRegistry() {
1380
1386
  return bundledRegistry;
1381
1387
  }
1382
1388
  /**
1389
+ * Where to find the model router gateways whose `pricing` fills the gaps in models.dev. Prices
1390
+ * load on the first lookup that has no price, so production does not call gateways at startup;
1391
+ * under the same switches as the models.dev refresh (`mastra dev`, or
1392
+ * `MASTRA_AUTO_REFRESH_PRICING=true`) they also load right away, off the hot path, so the first
1393
+ * model call is priced. Each gateway is read once; a failed read is retried at most once an hour.
1394
+ */
1395
+ function setPricingGateways(source) {
1396
+ gatewaySource = source;
1397
+ if (isRefreshEnabled()) loadGatewayPricing();
1398
+ }
1399
+ /** Load `pricing` from every custom gateway not loaded yet. Off under `MASTRA_OFFLINE`. */
1400
+ async function loadGatewayPricing() {
1401
+ if (!gatewaySource || gatewayLoadInFlight || isOffline()) return;
1402
+ gatewayLoadInFlight = true;
1403
+ try {
1404
+ const builtInIds = await getBuiltInGatewayIds();
1405
+ let changed = false;
1406
+ for (const gateway of gatewaySource()) {
1407
+ const gatewayId = gateway.getId?.() ?? gateway.id;
1408
+ const lastAttempt = gatewayLoadAttempts.get(gateway) ?? 0;
1409
+ if (builtInIds.has(gatewayId) || Date.now() - lastAttempt < MIN_REFRESH_ATTEMPT_INTERVAL_MS) continue;
1410
+ try {
1411
+ const providers = await gateway.fetchProviders();
1412
+ for (const [providerId, config] of Object.entries(providers ?? {})) for (const [modelId, cost] of Object.entries(config?.pricing ?? {})) (gatewayCosts[providerId] ??= { models: {} }).models[modelId] = { cost };
1413
+ gatewayLoadAttempts.set(gateway, Infinity);
1414
+ changed = true;
1415
+ } catch (error) {
1416
+ gatewayLoadAttempts.set(gateway, Date.now());
1417
+ console.warn(`Failed to load model prices from gateway ${gatewayId}:`, error);
1418
+ }
1419
+ }
1420
+ if (changed) gatewayRegistry = new PricingRegistry(modelsDevToPricingModels(gatewayCosts));
1421
+ } finally {
1422
+ gatewayLoadInFlight = false;
1423
+ }
1424
+ }
1425
+ /**
1426
+ * The gateways core ships: the ones Mastra registers on its own, plus Azure OpenAI, which users
1427
+ * construct themselves. Their `fetchProviders()` can hit the network and never carries prices.
1428
+ * Read from core when it exports the list (1.46+), else the known ids.
1429
+ */
1430
+ async function getBuiltInGatewayIds() {
1431
+ try {
1432
+ const { defaultGateways, getGatewayId } = await import("@mastra/core/llm");
1433
+ return /* @__PURE__ */ new Set([...defaultGateways.map(getGatewayId), AZURE_OPENAI_GATEWAY_ID]);
1434
+ } catch {
1435
+ return /* @__PURE__ */ new Set([
1436
+ "models.dev",
1437
+ "netlify",
1438
+ "mastra",
1439
+ AZURE_OPENAI_GATEWAY_ID
1440
+ ]);
1441
+ }
1442
+ }
1443
+ function isOffline() {
1444
+ const offline = process.env.MASTRA_OFFLINE;
1445
+ return offline === "true" || offline === "1";
1446
+ }
1447
+ /**
1383
1448
  * Same switches as the model router's auto-refresh in `@mastra/core`: on by default only under
1384
1449
  * `mastra dev` (`MASTRA_DEV`), opt-in elsewhere, and always off with `MASTRA_OFFLINE`.
1385
1450
  */
1386
1451
  function isRefreshEnabled() {
1387
- const offline = process.env.MASTRA_OFFLINE;
1388
- if (offline === "true" || offline === "1") return false;
1452
+ if (isOffline()) return false;
1389
1453
  const isDev = process.env.MASTRA_DEV === "true" || process.env.MASTRA_DEV === "1";
1390
1454
  const setting = process.env.MASTRA_AUTO_REFRESH_PRICING;
1391
1455
  return setting === "true" || setting !== "false" && isDev;
@@ -4026,6 +4090,8 @@ function resolveTracingStorageStrategy$1(config, observabilityStorage, storageNa
4026
4090
  return observabilityStrategy.preferred;
4027
4091
  }
4028
4092
  const FLUSH_SUCCEEDED$1 = { failed: false };
4093
+ /** Max join/write rounds a single flush() makes before it returns under continuous traffic */
4094
+ const MAX_FLUSH_ROUNDS$1 = 3;
4029
4095
  /**
4030
4096
  * @deprecated Use `MastraStorageExporter` from `@mastra/observability` instead.
4031
4097
  * This class is preserved unchanged so existing integrations (including code
@@ -4045,6 +4111,8 @@ var DefaultExporter = class extends BaseExporter {
4045
4111
  #observabilityStorage;
4046
4112
  #resolvedStrategy;
4047
4113
  #flushTimer;
4114
+ /** Storage writes (timer, size trigger, or flush()) that haven't finished yet */
4115
+ #inFlightFlushes = /* @__PURE__ */ new Set();
4048
4116
  #emitDropEvent;
4049
4117
  #unsupportedSignals = /* @__PURE__ */ new Set();
4050
4118
  constructor(config = {}) {
@@ -4119,7 +4187,7 @@ var DefaultExporter = class extends BaseExporter {
4119
4187
  if (this.#flushTimer) clearTimeout(this.#flushTimer);
4120
4188
  this.#flushTimer = setTimeout(() => {
4121
4189
  this.#flushTimer = void 0;
4122
- this.flushBuffer().catch((error) => {
4190
+ this.trackFlushBuffer().catch((error) => {
4123
4191
  this.logger.error("Scheduled flush failed", { error: error instanceof Error ? error.message : String(error) });
4124
4192
  });
4125
4193
  }, delayMs);
@@ -4149,7 +4217,7 @@ var DefaultExporter = class extends BaseExporter {
4149
4217
  * Returns the flush promise when flushing so callers can await it.
4150
4218
  */
4151
4219
  async handleBatchedFlush() {
4152
- if (this.shouldFlush()) await this.flushBuffer();
4220
+ if (this.shouldFlush()) await this.trackFlushBuffer();
4153
4221
  else if (this.#eventBuffer.totalSize === 1) this.scheduleFlush();
4154
4222
  }
4155
4223
  sanitizeDropError(error) {
@@ -4253,6 +4321,15 @@ var DefaultExporter = class extends BaseExporter {
4253
4321
  }
4254
4322
  }
4255
4323
  /**
4324
+ * Runs flushBuffer() and tracks its promise so flush() can wait for writes
4325
+ * that a timer or size trigger started on their own.
4326
+ */
4327
+ trackFlushBuffer() {
4328
+ const promise = this.flushBuffer().finally(() => this.#inFlightFlushes.delete(promise));
4329
+ this.#inFlightFlushes.add(promise);
4330
+ return promise;
4331
+ }
4332
+ /**
4256
4333
  * Flushes the current buffer to storage.
4257
4334
  *
4258
4335
  * Creates are flushed first, then their span keys are added to allCreatedSpans.
@@ -4411,10 +4488,16 @@ var DefaultExporter = class extends BaseExporter {
4411
4488
  * are exported before the runtime instance is terminated.
4412
4489
  */
4413
4490
  async flush() {
4414
- if (this.#eventBuffer.totalSize > 0) {
4415
- this.logger.debug("Flushing buffered events", { bufferedEvents: this.#eventBuffer.totalSize });
4416
- await this.flushBuffer();
4491
+ for (let round = 0; round < MAX_FLUSH_ROUNDS$1; round++) {
4492
+ if (this.#inFlightFlushes.size > 0) await Promise.allSettled([...this.#inFlightFlushes]);
4493
+ if (this.#eventBuffer.totalSize > 0) {
4494
+ this.logger.debug("Flushing buffered events", { bufferedEvents: this.#eventBuffer.totalSize });
4495
+ await this.trackFlushBuffer();
4496
+ }
4497
+ if (this.#inFlightFlushes.size === 0) return;
4417
4498
  }
4499
+ await Promise.allSettled([...this.#inFlightFlushes]);
4500
+ this.logger.warn(`flush() stopped after ${MAX_FLUSH_ROUNDS$1} rounds; new writes kept starting`, { bufferedEventsLeftBehind: this.#eventBuffer.totalSize });
4418
4501
  }
4419
4502
  async shutdown() {
4420
4503
  if (this.#flushTimer) {
@@ -4448,6 +4531,8 @@ function resolveTracingStorageStrategy(config, observabilityStorage, storageName
4448
4531
  return observabilityStrategy.preferred;
4449
4532
  }
4450
4533
  const FLUSH_SUCCEEDED = { failed: false };
4534
+ /** Max join/write rounds a single flush() makes before it returns under continuous traffic */
4535
+ const MAX_FLUSH_ROUNDS = 3;
4451
4536
  /**
4452
4537
  * Storage-backed exporter. Buffers observability events and flushes them in
4453
4538
  * batches to the configured ObservabilityStorage backend with retry support.
@@ -4462,6 +4547,8 @@ var MastraStorageExporter = class extends BaseExporter {
4462
4547
  #observabilityStorage;
4463
4548
  #resolvedStrategy;
4464
4549
  #flushTimer;
4550
+ /** Storage writes (timer, size trigger, or flush()) that haven't finished yet */
4551
+ #inFlightFlushes = /* @__PURE__ */ new Set();
4465
4552
  #emitDropEvent;
4466
4553
  #unsupportedSignals = /* @__PURE__ */ new Set();
4467
4554
  constructor(config = {}) {
@@ -4551,7 +4638,7 @@ var MastraStorageExporter = class extends BaseExporter {
4551
4638
  if (this.#flushTimer) clearTimeout(this.#flushTimer);
4552
4639
  this.#flushTimer = setTimeout(() => {
4553
4640
  this.#flushTimer = void 0;
4554
- this.flushBuffer().catch((error) => {
4641
+ this.trackFlushBuffer().catch((error) => {
4555
4642
  this.logger.error("Scheduled flush failed", { error: error instanceof Error ? error.message : String(error) });
4556
4643
  });
4557
4644
  }, delayMs);
@@ -4581,7 +4668,7 @@ var MastraStorageExporter = class extends BaseExporter {
4581
4668
  * Returns the flush promise when flushing so callers can await it.
4582
4669
  */
4583
4670
  async handleBatchedFlush() {
4584
- if (this.shouldFlush()) await this.flushBuffer();
4671
+ if (this.shouldFlush()) await this.trackFlushBuffer();
4585
4672
  else if (this.#eventBuffer.totalSize === 1) this.scheduleFlush();
4586
4673
  }
4587
4674
  sanitizeDropError(error) {
@@ -4685,6 +4772,15 @@ var MastraStorageExporter = class extends BaseExporter {
4685
4772
  }
4686
4773
  }
4687
4774
  /**
4775
+ * Runs flushBuffer() and tracks its promise so flush() can wait for writes
4776
+ * that a timer or size trigger started on their own.
4777
+ */
4778
+ trackFlushBuffer() {
4779
+ const promise = this.flushBuffer().finally(() => this.#inFlightFlushes.delete(promise));
4780
+ this.#inFlightFlushes.add(promise);
4781
+ return promise;
4782
+ }
4783
+ /**
4688
4784
  * Flushes the current buffer to storage.
4689
4785
  *
4690
4786
  * Creates are flushed first, then their span keys are added to allCreatedSpans.
@@ -4832,10 +4928,16 @@ var MastraStorageExporter = class extends BaseExporter {
4832
4928
  * are exported before the runtime instance is terminated.
4833
4929
  */
4834
4930
  async flush() {
4835
- if (this.#eventBuffer.totalSize > 0) {
4836
- this.logger.debug("Flushing buffered events", { bufferedEvents: this.#eventBuffer.totalSize });
4837
- await this.flushBuffer();
4931
+ for (let round = 0; round < MAX_FLUSH_ROUNDS; round++) {
4932
+ if (this.#inFlightFlushes.size > 0) await Promise.allSettled([...this.#inFlightFlushes]);
4933
+ if (this.#eventBuffer.totalSize > 0) {
4934
+ this.logger.debug("Flushing buffered events", { bufferedEvents: this.#eventBuffer.totalSize });
4935
+ await this.trackFlushBuffer();
4936
+ }
4937
+ if (this.#inFlightFlushes.size === 0) return;
4838
4938
  }
4939
+ await Promise.allSettled([...this.#inFlightFlushes]);
4940
+ this.logger.warn(`flush() stopped after ${MAX_FLUSH_ROUNDS} rounds; new writes kept starting`, { bufferedEventsLeftBehind: this.#eventBuffer.totalSize });
4839
4941
  }
4840
4942
  async shutdown() {
4841
4943
  if (this.#flushTimer) {
@@ -9957,6 +10059,7 @@ var Observability = class extends _mastra_core_base.MastraBase {
9957
10059
  const instances = this.listInstances();
9958
10060
  const { mastra } = options;
9959
10061
  this.#mastra = mastra;
10062
+ setPricingGateways(() => Object.values(mastra.listGateways?.() ?? {}));
9960
10063
  const mastraEnvironment = mastra.getEnvironment?.();
9961
10064
  instances.forEach((instance) => {
9962
10065
  instance.__setMastraEnvironment?.(mastraEnvironment);