@mastra/observability 1.15.1 → 1.15.2-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,23 @@
1
1
  # @mastra/observability
2
2
 
3
+ ## 1.15.2-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed pricing lookup when a provider-reported response model does not match a known pricing entry but the configured model does. Cost estimation now falls back to the configured model before reporting `no_matching_model`. ([#16585](https://github.com/mastra-ai/mastra/pull/16585))
8
+
9
+ - Updated dependencies [[`0200e75`](https://github.com/mastra-ai/mastra/commit/0200e7552d02d4221cd6040bf4eddf189a97a156), [`06e0d63`](https://github.com/mastra-ai/mastra/commit/06e0d63d42bc2a202e18bc091f3781f409f5e6fb), [`438a971`](https://github.com/mastra-ai/mastra/commit/438a9715c8b4398e5eaf8914a1f19dc8a85dc1de), [`77518cc`](https://github.com/mastra-ai/mastra/commit/77518ccb5bb8cc684875081e64213dc85cffdbee), [`bb2a13b`](https://github.com/mastra-ai/mastra/commit/bb2a13bb4b32e6bb807200fe7b18ae8fa4322118), [`a73cd1a`](https://github.com/mastra-ai/mastra/commit/a73cd1a62a5e4ca023dcc39ba150029f4f1f74c1), [`0b5cc47`](https://github.com/mastra-ai/mastra/commit/0b5cc4726dc18d9a685a27520db39ff1b36bb89a), [`87f38a3`](https://github.com/mastra-ai/mastra/commit/87f38a3de03e24731f2dd6f8ed6a60b6722b85a1), [`d5fa3cd`](https://github.com/mastra-ai/mastra/commit/d5fa3cda1788c3cb93a361a3c6ec47de6ba21e98), [`fe98ef2`](https://github.com/mastra-ai/mastra/commit/fe98ef2e66dbfcbd7d645c88c9ee1e67b458a136), [`793ea0f`](https://github.com/mastra-ai/mastra/commit/793ea0f52f831178837f21c83af6af93bf4ce638), [`507a5c4`](https://github.com/mastra-ai/mastra/commit/507a5c461bdc3136ad80744c0efbb55ce1f18f97), [`79b3626`](https://github.com/mastra-ai/mastra/commit/79b3626f8d647307eb07c8da14c9073c2699719d)]:
10
+ - @mastra/core@1.47.0-alpha.6
11
+
12
+ ## 1.15.2-alpha.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Tool telemetry is now more informative for tools that transform their output before sending to the model. Tool-result spans in traces show the actual value the model received instead of being empty, and step input previews display the tool result content instead of an opaque `[tool-result]` placeholder. This makes it easier to debug tool behavior in Langfuse, Datadog, and other observability providers. ([#18417](https://github.com/mastra-ai/mastra/pull/18417))
17
+
18
+ - Updated dependencies [[`bf3fe49`](https://github.com/mastra-ai/mastra/commit/bf3fe49f9467dbbdb8f9eaf74e0f7971ffb19559), [`24ceaea`](https://github.com/mastra-ai/mastra/commit/24ceaea0bdd8609cabbab764380608ca6621a194), [`6ccf67b`](https://github.com/mastra-ai/mastra/commit/6ccf67bf075753754927a57bc2e1734ba2c820c5), [`825d8de`](https://github.com/mastra-ai/mastra/commit/825d8def9fa64c2bcc3d8dd6b49e09342c3ac5c7), [`ffa09e7`](https://github.com/mastra-ai/mastra/commit/ffa09e772a5c92270eabe2090fc42d45bd8ec4b7), [`461a7c5`](https://github.com/mastra-ai/mastra/commit/461a7c501449295287f4f0ee4b0b42344f39fcf8), [`4211472`](https://github.com/mastra-ai/mastra/commit/4211472a5a2bd319c60cd2e42d9109c3eef7ac1c), [`9e45902`](https://github.com/mastra-ai/mastra/commit/9e4590208e745055cecca202e2db0e5c65e17d3c), [`5c0df77`](https://github.com/mastra-ai/mastra/commit/5c0df776c40efa420f8c07a2f3ee66010296618e)]:
19
+ - @mastra/core@1.47.0-alpha.3
20
+
3
21
  ## 1.15.1
4
22
 
5
23
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -1451,6 +1451,16 @@ function emitUsageMetrics(attrs, usage, metrics) {
1451
1451
  model,
1452
1452
  usage
1453
1453
  });
1454
+ if (isNoMatchingModelResult(metricCosts) && attrs.model && attrs.model !== model) {
1455
+ const configuredModelCosts = estimateCosts({
1456
+ provider,
1457
+ model: attrs.model,
1458
+ usage
1459
+ });
1460
+ if (!isNoMatchingModelResult(configuredModelCosts)) {
1461
+ metricCosts = configuredModelCosts;
1462
+ }
1463
+ }
1454
1464
  }
1455
1465
  } catch {
1456
1466
  metricCosts = /* @__PURE__ */ new Map();
@@ -1468,6 +1478,9 @@ function emitUsageMetrics(attrs, usage, metrics) {
1468
1478
  emit(sample.name, sample.value);
1469
1479
  }
1470
1480
  }
1481
+ function isNoMatchingModelResult(metricCosts) {
1482
+ return metricCosts.size > 0 && [...metricCosts.values()].every((costContext) => costContext.costMetadata?.error === "no_matching_model");
1483
+ }
1471
1484
  function getProvidedCostContext(attrs, usage) {
1472
1485
  const costContext = attrs.costContext;
1473
1486
  if (typeof costContext?.estimatedCost !== "number") {
@@ -1674,6 +1687,14 @@ function supportsModelInference() {
1674
1687
  function formatPreviewLabel(label, fallback) {
1675
1688
  return typeof label === "string" && label.length > 0 ? label : fallback;
1676
1689
  }
1690
+ function formatToolResultPreviewValue(value) {
1691
+ if (typeof value === "string") return value;
1692
+ if (value && typeof value === "object" && "type" in value && value.type === "text") {
1693
+ const textValue = value.value;
1694
+ if (typeof textValue === "string") return textValue;
1695
+ }
1696
+ return JSON.stringify(value);
1697
+ }
1677
1698
  function summarizePart(part) {
1678
1699
  if (typeof part === "string") {
1679
1700
  return part;
@@ -1702,7 +1723,7 @@ function summarizePart(part) {
1702
1723
  if ("function" in part && part.function && typeof part.function === "object") {
1703
1724
  return `[tool: ${formatPreviewLabel(part.function.name, "unknown")}]`;
1704
1725
  }
1705
- if ("toolName" in part) {
1726
+ if ("toolName" in part && !("type" in part && part.type === "tool-result")) {
1706
1727
  return `[tool: ${formatPreviewLabel(part.toolName, "unknown")}]`;
1707
1728
  }
1708
1729
  if ("type" in part && typeof part.type === "string") {
@@ -1715,8 +1736,15 @@ function summarizePart(part) {
1715
1736
  return "[reasoning]";
1716
1737
  case "tool-call":
1717
1738
  return `[tool: ${formatPreviewLabel(part.toolName, "unknown")}]`;
1718
- case "tool-result":
1719
- return "[tool-result]";
1739
+ case "tool-result": {
1740
+ const toolResult = part;
1741
+ const mastraMeta = toolResult.providerMetadata?.mastra ?? toolResult.providerOptions?.mastra;
1742
+ const toolName = formatPreviewLabel(part.toolName, "unknown");
1743
+ if (mastraMeta?.modelOutput !== void 0) {
1744
+ return formatToolResultPreviewValue(mastraMeta.modelOutput);
1745
+ }
1746
+ return `[tool-result: ${toolName}]`;
1747
+ }
1720
1748
  default:
1721
1749
  return `[${part.type}]`;
1722
1750
  }
@@ -2410,7 +2438,9 @@ var ModelSpanTracker = class {
2410
2438
  if (dynamic !== void 0) metadata.dynamic = dynamic;
2411
2439
  if (providerExecuted !== void 0) metadata.providerExecuted = providerExecuted;
2412
2440
  if (providerMetadata !== void 0) metadata.providerMetadata = providerMetadata;
2413
- this.#createEventSpan(chunk.type, providerExecuted ? result : void 0, { metadata });
2441
+ const mastraMeta = providerMetadata?.mastra;
2442
+ const spanOutput = providerExecuted ? result : mastraMeta?.modelOutput !== void 0 ? mastraMeta.modelOutput : void 0;
2443
+ this.#createEventSpan(chunk.type, spanOutput, { metadata });
2414
2444
  break;
2415
2445
  }
2416
2446
  }