@mastra/observability 1.16.4 → 1.16.5

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,14 @@
1
1
  # @mastra/observability
2
2
 
3
+ ## 1.16.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed token metrics losing model labels and cost data when providers return blank response model IDs. ([#20742](https://github.com/mastra-ai/mastra/pull/20742))
8
+
9
+ - Updated dependencies [[`8d2399b`](https://github.com/mastra-ai/mastra/commit/8d2399b638f8e0945cf2cda0187dbea8dcf0b784), [`c8002da`](https://github.com/mastra-ai/mastra/commit/c8002da7775c468e2965b6ff5f82045450fa8cb9), [`92be47f`](https://github.com/mastra-ai/mastra/commit/92be47fbd26ffccec0e2131ef7c1d9e70dd5ef4a), [`89200ba`](https://github.com/mastra-ai/mastra/commit/89200bafa05444bb7949b363ce7b743e29867561), [`c950138`](https://github.com/mastra-ai/mastra/commit/c950138e72e4f317a40187e3800588731ab790ce), [`810c7e7`](https://github.com/mastra-ai/mastra/commit/810c7e74929989d8b8b5db52cd3af22cd0998af4), [`063c8b2`](https://github.com/mastra-ai/mastra/commit/063c8b2eb14e4e5ca021779bc33e8c3c031c8604), [`f9f9884`](https://github.com/mastra-ai/mastra/commit/f9f98848ee194dc71a787a709ec430b065cdc41b), [`e0904dc`](https://github.com/mastra-ai/mastra/commit/e0904dc538792e54e1806b70172e5900ac49bff4), [`9672fab`](https://github.com/mastra-ai/mastra/commit/9672fabfbcadb961a35c22a2d6722e077f7b24b9), [`f4e964c`](https://github.com/mastra-ai/mastra/commit/f4e964cad57057301d6bed5c55bcdd730175b941), [`1f7bbd7`](https://github.com/mastra-ai/mastra/commit/1f7bbd7785a8d230aad02454ecabeb4a0b2cc96f), [`e47ff36`](https://github.com/mastra-ai/mastra/commit/e47ff36945720f4ee4caa09f6e83514d7d188608), [`64d6781`](https://github.com/mastra-ai/mastra/commit/64d67814bccddd314f7e09643243821e57cb87b6), [`fb9a6ac`](https://github.com/mastra-ai/mastra/commit/fb9a6ac11c9560518742ece60b49d6b062845fd3), [`aa2cec8`](https://github.com/mastra-ai/mastra/commit/aa2cec8501f634d51c2f3ebfb3dd3aa7af8d2ca2), [`c848e65`](https://github.com/mastra-ai/mastra/commit/c848e655a64ff10331a8ceafafe7f18e70a0f092), [`2adf8eb`](https://github.com/mastra-ai/mastra/commit/2adf8eb4a70ed2b6cff2dd39281496ea0e025fac), [`0494489`](https://github.com/mastra-ai/mastra/commit/049448906e4c3d2d615bbe865b073a0d890ddb7c), [`8d1aeb8`](https://github.com/mastra-ai/mastra/commit/8d1aeb8acf7c20c4bb8e4d8e4bdc6569c83ac561), [`8264611`](https://github.com/mastra-ai/mastra/commit/8264611510e421b818bc7395dc2ae4d9c2d518b2), [`d8fa243`](https://github.com/mastra-ai/mastra/commit/d8fa2430d21113e330c4e676ac65e1235cf44f81), [`44fc98b`](https://github.com/mastra-ai/mastra/commit/44fc98b9d1242aa87a3ab44bdce9e9f12c44d8c9), [`f933ba3`](https://github.com/mastra-ai/mastra/commit/f933ba32700e1d0bf143311c1a08f88300b840b6), [`83065bf`](https://github.com/mastra-ai/mastra/commit/83065bfee9e47c3c6f09132a9034501f6cfb69cf), [`0f2ef41`](https://github.com/mastra-ai/mastra/commit/0f2ef4118da022e4f30dac4e9856cc3a8c97671c), [`01b162f`](https://github.com/mastra-ai/mastra/commit/01b162fe435295881aa7ea55f1759407ad5175ad)]:
10
+ - @mastra/core@1.57.0
11
+
3
12
  ## 1.16.4
4
13
 
5
14
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -954,6 +954,12 @@ function cloneCostContext(costContext) {
954
954
  };
955
955
  }
956
956
  //#endregion
957
+ //#region src/model-id.ts
958
+ /** Return the first model id that contains non-whitespace characters. */
959
+ function resolveModelId(...candidates) {
960
+ return candidates.find((candidate) => candidate?.trim());
961
+ }
962
+ //#endregion
957
963
  //#region src/metrics/pricing-model.ts
958
964
  var PricingTier = class {
959
965
  index;
@@ -1530,7 +1536,7 @@ function emitUsageMetrics(attrs, usage, metrics) {
1530
1536
  if (providedCostContext) metricCosts = providedCostContext;
1531
1537
  else try {
1532
1538
  const provider = attrs.provider;
1533
- const model = attrs.responseModel ?? attrs.model;
1539
+ const model = resolveModelId(attrs.responseModel, attrs.model);
1534
1540
  if (provider && model) {
1535
1541
  metricCosts = estimateCosts({
1536
1542
  provider,
@@ -1567,7 +1573,7 @@ function getProvidedCostContext(attrs, usage) {
1567
1573
  if (typeof costContext?.estimatedCost !== "number") return;
1568
1574
  const carrierMetric = usage.inputTokens !== void 0 ? TokenMetrics.TOTAL_INPUT : TokenMetrics.TOTAL_OUTPUT;
1569
1575
  const provider = costContext.provider ?? attrs.provider;
1570
- const model = costContext.model ?? attrs.responseModel ?? attrs.model;
1576
+ const model = resolveModelId(costContext.model, attrs.responseModel, attrs.model);
1571
1577
  const contexts = /* @__PURE__ */ new Map();
1572
1578
  for (const sample of getTokenMetricSamples(usage)) contexts.set(sample.name, {
1573
1579
  provider,
@@ -2999,7 +3005,7 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
2999
3005
  });
3000
3006
  if (rest.type === _mastra_core_observability.SpanType.MODEL_GENERATION && this.config.excludeSpanTypes?.includes(_mastra_core_observability.SpanType.MODEL_GENERATION)) {
3001
3007
  const attrs = rest.attributes;
3002
- const model = attrs?.responseModel ?? attrs?.model;
3008
+ const model = resolveModelId(attrs?.responseModel, attrs?.model);
3003
3009
  if (attrs?.provider || model) this.#excludedModelMeta.set(span, {
3004
3010
  provider: attrs?.provider,
3005
3011
  model
@@ -3402,7 +3408,7 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
3402
3408
  ancestor,
3403
3409
  usage,
3404
3410
  provider: endAttrs?.provider ?? liveAttrs?.provider,
3405
- model: endAttrs?.responseModel ?? endAttrs?.model ?? liveAttrs?.responseModel ?? liveAttrs?.model
3411
+ model: resolveModelId(endAttrs?.responseModel, endAttrs?.model, liveAttrs?.responseModel, liveAttrs?.model)
3406
3412
  };
3407
3413
  }
3408
3414
  /**
@@ -3424,7 +3430,7 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
3424
3430
  return {
3425
3431
  usage,
3426
3432
  provider: endAttrs?.provider ?? liveAttrs?.provider ?? stashed?.provider,
3427
- model: endAttrs?.responseModel ?? endAttrs?.model ?? liveAttrs?.responseModel ?? liveAttrs?.model ?? stashed?.model
3433
+ model: resolveModelId(endAttrs?.responseModel, endAttrs?.model, liveAttrs?.responseModel, liveAttrs?.model, stashed?.model)
3428
3434
  };
3429
3435
  }
3430
3436
  /**