@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/dist/index.js CHANGED
@@ -1443,6 +1443,16 @@ function emitUsageMetrics(attrs, usage, metrics) {
1443
1443
  model,
1444
1444
  usage
1445
1445
  });
1446
+ if (isNoMatchingModelResult(metricCosts) && attrs.model && attrs.model !== model) {
1447
+ const configuredModelCosts = estimateCosts({
1448
+ provider,
1449
+ model: attrs.model,
1450
+ usage
1451
+ });
1452
+ if (!isNoMatchingModelResult(configuredModelCosts)) {
1453
+ metricCosts = configuredModelCosts;
1454
+ }
1455
+ }
1446
1456
  }
1447
1457
  } catch {
1448
1458
  metricCosts = /* @__PURE__ */ new Map();
@@ -1460,6 +1470,9 @@ function emitUsageMetrics(attrs, usage, metrics) {
1460
1470
  emit(sample.name, sample.value);
1461
1471
  }
1462
1472
  }
1473
+ function isNoMatchingModelResult(metricCosts) {
1474
+ return metricCosts.size > 0 && [...metricCosts.values()].every((costContext) => costContext.costMetadata?.error === "no_matching_model");
1475
+ }
1463
1476
  function getProvidedCostContext(attrs, usage) {
1464
1477
  const costContext = attrs.costContext;
1465
1478
  if (typeof costContext?.estimatedCost !== "number") {
@@ -1666,6 +1679,14 @@ function supportsModelInference() {
1666
1679
  function formatPreviewLabel(label, fallback) {
1667
1680
  return typeof label === "string" && label.length > 0 ? label : fallback;
1668
1681
  }
1682
+ function formatToolResultPreviewValue(value) {
1683
+ if (typeof value === "string") return value;
1684
+ if (value && typeof value === "object" && "type" in value && value.type === "text") {
1685
+ const textValue = value.value;
1686
+ if (typeof textValue === "string") return textValue;
1687
+ }
1688
+ return JSON.stringify(value);
1689
+ }
1669
1690
  function summarizePart(part) {
1670
1691
  if (typeof part === "string") {
1671
1692
  return part;
@@ -1694,7 +1715,7 @@ function summarizePart(part) {
1694
1715
  if ("function" in part && part.function && typeof part.function === "object") {
1695
1716
  return `[tool: ${formatPreviewLabel(part.function.name, "unknown")}]`;
1696
1717
  }
1697
- if ("toolName" in part) {
1718
+ if ("toolName" in part && !("type" in part && part.type === "tool-result")) {
1698
1719
  return `[tool: ${formatPreviewLabel(part.toolName, "unknown")}]`;
1699
1720
  }
1700
1721
  if ("type" in part && typeof part.type === "string") {
@@ -1707,8 +1728,15 @@ function summarizePart(part) {
1707
1728
  return "[reasoning]";
1708
1729
  case "tool-call":
1709
1730
  return `[tool: ${formatPreviewLabel(part.toolName, "unknown")}]`;
1710
- case "tool-result":
1711
- return "[tool-result]";
1731
+ case "tool-result": {
1732
+ const toolResult = part;
1733
+ const mastraMeta = toolResult.providerMetadata?.mastra ?? toolResult.providerOptions?.mastra;
1734
+ const toolName = formatPreviewLabel(part.toolName, "unknown");
1735
+ if (mastraMeta?.modelOutput !== void 0) {
1736
+ return formatToolResultPreviewValue(mastraMeta.modelOutput);
1737
+ }
1738
+ return `[tool-result: ${toolName}]`;
1739
+ }
1712
1740
  default:
1713
1741
  return `[${part.type}]`;
1714
1742
  }
@@ -2402,7 +2430,9 @@ var ModelSpanTracker = class {
2402
2430
  if (dynamic !== void 0) metadata.dynamic = dynamic;
2403
2431
  if (providerExecuted !== void 0) metadata.providerExecuted = providerExecuted;
2404
2432
  if (providerMetadata !== void 0) metadata.providerMetadata = providerMetadata;
2405
- this.#createEventSpan(chunk.type, providerExecuted ? result : void 0, { metadata });
2433
+ const mastraMeta = providerMetadata?.mastra;
2434
+ const spanOutput = providerExecuted ? result : mastraMeta?.modelOutput !== void 0 ? mastraMeta.modelOutput : void 0;
2435
+ this.#createEventSpan(chunk.type, spanOutput, { metadata });
2406
2436
  break;
2407
2437
  }
2408
2438
  }