@mastra/observability 1.5.1-alpha.0 → 1.5.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,29 @@
1
1
  # @mastra/observability
2
2
 
3
+ ## 1.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix cache token extraction in multi-step agent runs. Prefer AI SDK aggregated `inputTokenDetails` over `providerMetadata` (which only reflects the last step). Also fix truthiness checks to correctly handle zero values for cache and reasoning tokens. ([#14492](https://github.com/mastra-ai/mastra/pull/14492))
8
+
9
+ Fix Datadog metric keys to match dd-trace expected format: `cacheReadTokens`, `cacheWriteTokens`, `reasoningOutputTokens`.
10
+
11
+ - Fixed span serialization to avoid incorrect [Circular] placeholders in traces. ([#14263](https://github.com/mastra-ai/mastra/pull/14263))
12
+
13
+ - Updated dependencies [[`cb611a1`](https://github.com/mastra-ai/mastra/commit/cb611a1e89a4f4cf74c97b57e0c27bb56f2eceb5), [`da93115`](https://github.com/mastra-ai/mastra/commit/da931155c1a9bc63d455d3d86b4ec984db5991fe), [`62d1d3c`](https://github.com/mastra-ai/mastra/commit/62d1d3cc08fe8182e7080237fd975de862ec8c91), [`9e1a3ed`](https://github.com/mastra-ai/mastra/commit/9e1a3ed07cfafb5e8e19a796ce0bee817002d7c0), [`8681ecb`](https://github.com/mastra-ai/mastra/commit/8681ecb86184d5907267000e4576cc442a9a83fc), [`28d0249`](https://github.com/mastra-ai/mastra/commit/28d0249295782277040ad1e0d243e695b7ab1ce4), [`681ee1c`](https://github.com/mastra-ai/mastra/commit/681ee1c811359efd1b8bebc4bce35b9bb7b14bec), [`bb0f09d`](https://github.com/mastra-ai/mastra/commit/bb0f09dbac58401b36069f483acf5673202db5b5), [`a579f7a`](https://github.com/mastra-ai/mastra/commit/a579f7a31e582674862b5679bc79af7ccf7429b8), [`5f7e9d0`](https://github.com/mastra-ai/mastra/commit/5f7e9d0db664020e1f3d97d7d18c6b0b9d4843d0), [`d7f14c3`](https://github.com/mastra-ai/mastra/commit/d7f14c3285cd253ecdd5f58139b7b6cbdf3678b5), [`0efe12a`](https://github.com/mastra-ai/mastra/commit/0efe12a5f008a939a1aac71699486ba40138054e)]:
14
+ - @mastra/core@1.15.0
15
+
16
+ ## 1.5.1-alpha.1
17
+
18
+ ### Patch Changes
19
+
20
+ - Fix cache token extraction in multi-step agent runs. Prefer AI SDK aggregated `inputTokenDetails` over `providerMetadata` (which only reflects the last step). Also fix truthiness checks to correctly handle zero values for cache and reasoning tokens. ([#14492](https://github.com/mastra-ai/mastra/pull/14492))
21
+
22
+ Fix Datadog metric keys to match dd-trace expected format: `cacheReadTokens`, `cacheWriteTokens`, `reasoningOutputTokens`.
23
+
24
+ - Updated dependencies [[`9e1a3ed`](https://github.com/mastra-ai/mastra/commit/9e1a3ed07cfafb5e8e19a796ce0bee817002d7c0), [`a579f7a`](https://github.com/mastra-ai/mastra/commit/a579f7a31e582674862b5679bc79af7ccf7429b8)]:
25
+ - @mastra/core@1.15.0-alpha.2
26
+
3
27
  ## 1.5.1-alpha.0
4
28
 
5
29
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -17426,6 +17426,9 @@ var MetricsContextImpl = class {
17426
17426
  };
17427
17427
 
17428
17428
  // src/usage.ts
17429
+ function isDefined(value) {
17430
+ return value != null;
17431
+ }
17429
17432
  function extractUsageMetrics(usage, providerMetadata) {
17430
17433
  if (!usage) {
17431
17434
  return {};
@@ -17434,31 +17437,38 @@ function extractUsageMetrics(usage, providerMetadata) {
17434
17437
  const outputDetails = {};
17435
17438
  let inputTokens = usage.inputTokens;
17436
17439
  const outputTokens = usage.outputTokens;
17437
- if (usage.cachedInputTokens) {
17440
+ const aiSdkDetails = usage.inputTokenDetails;
17441
+ if (isDefined(aiSdkDetails?.cacheReadTokens)) {
17442
+ inputDetails.cacheRead = aiSdkDetails.cacheReadTokens;
17443
+ }
17444
+ if (isDefined(aiSdkDetails?.cacheWriteTokens)) {
17445
+ inputDetails.cacheWrite = aiSdkDetails.cacheWriteTokens;
17446
+ }
17447
+ if (!isDefined(inputDetails.cacheRead) && isDefined(usage.cachedInputTokens)) {
17438
17448
  inputDetails.cacheRead = usage.cachedInputTokens;
17439
17449
  }
17440
- if (usage.reasoningTokens) {
17450
+ if (isDefined(usage.reasoningTokens)) {
17441
17451
  outputDetails.reasoning = usage.reasoningTokens;
17442
17452
  }
17443
17453
  const anthropic = providerMetadata?.anthropic;
17444
17454
  if (anthropic) {
17445
- if (anthropic.cacheReadInputTokens) {
17455
+ if (!isDefined(inputDetails.cacheRead) && isDefined(anthropic.cacheReadInputTokens)) {
17446
17456
  inputDetails.cacheRead = anthropic.cacheReadInputTokens;
17447
17457
  }
17448
- if (anthropic.cacheCreationInputTokens) {
17458
+ if (!isDefined(inputDetails.cacheWrite) && isDefined(anthropic.cacheCreationInputTokens)) {
17449
17459
  inputDetails.cacheWrite = anthropic.cacheCreationInputTokens;
17450
17460
  }
17451
- if (anthropic.cacheReadInputTokens || anthropic.cacheCreationInputTokens) {
17461
+ if (isDefined(inputDetails.cacheRead) || isDefined(inputDetails.cacheWrite)) {
17452
17462
  inputDetails.text = usage.inputTokens;
17453
- inputTokens = (usage.inputTokens ?? 0) + (anthropic.cacheReadInputTokens ?? 0) + (anthropic.cacheCreationInputTokens ?? 0);
17463
+ inputTokens = (usage.inputTokens ?? 0) + (inputDetails.cacheRead ?? 0) + (inputDetails.cacheWrite ?? 0);
17454
17464
  }
17455
17465
  }
17456
17466
  const google = providerMetadata?.google;
17457
17467
  if (google?.usageMetadata) {
17458
- if (google.usageMetadata.cachedContentTokenCount) {
17468
+ if (!isDefined(inputDetails.cacheRead) && isDefined(google.usageMetadata.cachedContentTokenCount)) {
17459
17469
  inputDetails.cacheRead = google.usageMetadata.cachedContentTokenCount;
17460
17470
  }
17461
- if (google.usageMetadata.thoughtsTokenCount) {
17471
+ if (isDefined(google.usageMetadata.thoughtsTokenCount)) {
17462
17472
  outputDetails.reasoning = google.usageMetadata.thoughtsTokenCount;
17463
17473
  }
17464
17474
  }