@mastra/observability 1.7.1-alpha.0 → 1.7.2-alpha.0

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,29 @@
1
1
  # @mastra/observability
2
2
 
3
+ ## 1.7.2-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - **Fixed Anthropic cache tokens being double-counted in observability metrics** ([#13914](https://github.com/mastra-ai/mastra/pull/13914))
8
+
9
+ Anthropic cache token usage is now normalized correctly for AI SDK v6-style usage payloads, so input token metrics and tracing output no longer overcount cached tokens when the total already includes them.
10
+
11
+ - Updated dependencies [[`81e4259`](https://github.com/mastra-ai/mastra/commit/81e425939b4ceeb4f586e9b6d89c3b1c1f2d2fe7), [`951b8a1`](https://github.com/mastra-ai/mastra/commit/951b8a1b5ef7e1474c59dc4f2b9fc1a8b1e508b6)]:
12
+ - @mastra/core@1.22.0-alpha.1
13
+
14
+ ## 1.7.1
15
+
16
+ ### Patch Changes
17
+
18
+ - Fixed score and feedback annotations being dropped before spans flush by emitting from live correlation context when available. Scores and feedback can now also be stored without a trace ID when only contextual metadata is available. ([#14942](https://github.com/mastra-ai/mastra/pull/14942))
19
+
20
+ - Fixed pricing model lookup to fall back to dot-to-dash normalization for model names (e.g. `gpt-5.2` → `gpt-5-2`), resolving `no_matching_model` errors for Azure deployments ([#14959](https://github.com/mastra-ai/mastra/pull/14959))
21
+
22
+ - Added error name and stack trace to SpanErrorInfo, allowing exporters to access the original error class name and stack trace for richer error reporting. ([#14944](https://github.com/mastra-ai/mastra/pull/14944))
23
+
24
+ - Updated dependencies [[`9a43b47`](https://github.com/mastra-ai/mastra/commit/9a43b476465e86c9aca381c2831066b5c33c999a), [`ec5c319`](https://github.com/mastra-ai/mastra/commit/ec5c3197a50d034cb8e9cc494eebfddc684b5d81), [`6517789`](https://github.com/mastra-ai/mastra/commit/65177895b74b5471fe2245c7292f0176d9b3385d), [`13f4327`](https://github.com/mastra-ai/mastra/commit/13f4327f052faebe199cefbe906d33bf90238767), [`9ad6aa6`](https://github.com/mastra-ai/mastra/commit/9ad6aa6dfe858afc6955d1df5f3f78c40bb96b9c), [`2862127`](https://github.com/mastra-ai/mastra/commit/2862127d0a7cbd28523120ad64fea067a95838e6), [`3d16814`](https://github.com/mastra-ai/mastra/commit/3d16814c395931373543728994ff45ac98093074), [`7f498d0`](https://github.com/mastra-ai/mastra/commit/7f498d099eacef64fd43ee412e3bd6f87965a8a6), [`8cf8a67`](https://github.com/mastra-ai/mastra/commit/8cf8a67b061b737cb06d501fb8c1967a98bbf3cb), [`d7827e3`](https://github.com/mastra-ai/mastra/commit/d7827e393937c6cb0c7a744dde4d31538cb542b7)]:
25
+ - @mastra/core@1.21.0
26
+
3
27
  ## 1.7.1-alpha.0
4
28
 
5
29
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -17891,6 +17891,9 @@ var CardinalityFilter = class {
17891
17891
  };
17892
17892
 
17893
17893
  // src/usage.ts
17894
+ function isV3RawUsage(raw) {
17895
+ return typeof raw === "object" && raw !== null && "inputTokens" in raw;
17896
+ }
17894
17897
  function isDefined(value) {
17895
17898
  return value != null;
17896
17899
  }
@@ -17917,13 +17920,15 @@ function extractUsageMetrics(usage, providerMetadata) {
17917
17920
  }
17918
17921
  const anthropic = providerMetadata?.anthropic;
17919
17922
  if (anthropic) {
17923
+ const rawV3InputUsage = isV3RawUsage(usage.raw) ? usage.raw.inputTokens : void 0;
17924
+ const hasV3CachedTotals = rawV3InputUsage?.total !== void 0 && (rawV3InputUsage.cacheRead !== void 0 || rawV3InputUsage.cacheWrite !== void 0);
17920
17925
  if (!isDefined(inputDetails.cacheRead) && isDefined(anthropic.cacheReadInputTokens)) {
17921
17926
  inputDetails.cacheRead = anthropic.cacheReadInputTokens;
17922
17927
  }
17923
17928
  if (!isDefined(inputDetails.cacheWrite) && isDefined(anthropic.cacheCreationInputTokens)) {
17924
17929
  inputDetails.cacheWrite = anthropic.cacheCreationInputTokens;
17925
17930
  }
17926
- if (isDefined(inputDetails.cacheRead) || isDefined(inputDetails.cacheWrite)) {
17931
+ if (!hasV3CachedTotals && (isDefined(inputDetails.cacheRead) || isDefined(inputDetails.cacheWrite))) {
17927
17932
  inputTokens = (usage.inputTokens ?? 0) + (inputDetails.cacheRead ?? 0) + (inputDetails.cacheWrite ?? 0);
17928
17933
  }
17929
17934
  }