@mastra/observability 1.0.0-beta.5 → 1.0.0-beta.6

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.0.0-beta.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Limits the size of large payloads in span data. ([#11237](https://github.com/mastra-ai/mastra/pull/11237))
8
+
9
+ - Updated dependencies [[`4f94ed8`](https://github.com/mastra-ai/mastra/commit/4f94ed8177abfde3ec536e3574883e075423350c), [`ac3cc23`](https://github.com/mastra-ai/mastra/commit/ac3cc2397d1966bc0fc2736a223abc449d3c7719), [`a86f4df`](https://github.com/mastra-ai/mastra/commit/a86f4df0407311e0d2ea49b9a541f0938810d6a9), [`029540c`](https://github.com/mastra-ai/mastra/commit/029540ca1e582fc2dd8d288ecd4a9b0f31a954ef), [`66741d1`](https://github.com/mastra-ai/mastra/commit/66741d1a99c4f42cf23a16109939e8348ac6852e), [`01b20fe`](https://github.com/mastra-ai/mastra/commit/01b20fefb7c67c2b7d79417598ef4e60256d1225), [`0dbf199`](https://github.com/mastra-ai/mastra/commit/0dbf199110f22192ce5c95b1c8148d4872b4d119), [`a7ce182`](https://github.com/mastra-ai/mastra/commit/a7ce1822a8785ce45d62dd5c911af465e144f7d7)]:
10
+ - @mastra/core@1.0.0-beta.14
11
+
3
12
  ## 1.0.0-beta.5
4
13
 
5
14
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -5454,6 +5454,110 @@ var ModelSpanTracker = class {
5454
5454
  }
5455
5455
  };
5456
5456
 
5457
+ // src/spans/serialization.ts
5458
+ var DEFAULT_KEYS_TO_STRIP = /* @__PURE__ */ new Set([
5459
+ "logger",
5460
+ "experimental_providerMetadata",
5461
+ "providerMetadata",
5462
+ "steps",
5463
+ "tracingContext"
5464
+ ]);
5465
+ var DEFAULT_DEEP_CLEAN_OPTIONS = Object.freeze({
5466
+ keysToStrip: DEFAULT_KEYS_TO_STRIP,
5467
+ maxDepth: 6,
5468
+ maxStringLength: 1024,
5469
+ maxArrayLength: 50,
5470
+ maxObjectKeys: 50
5471
+ });
5472
+ function truncateString(s, maxChars) {
5473
+ if (s.length <= maxChars) {
5474
+ return s;
5475
+ }
5476
+ return s.slice(0, maxChars) + "\u2026[truncated]";
5477
+ }
5478
+ function deepClean(value, options = DEFAULT_DEEP_CLEAN_OPTIONS) {
5479
+ const { keysToStrip, maxDepth, maxStringLength, maxArrayLength, maxObjectKeys } = options;
5480
+ const seen = /* @__PURE__ */ new WeakSet();
5481
+ function helper(val, depth) {
5482
+ if (depth > maxDepth) {
5483
+ return "[MaxDepth]";
5484
+ }
5485
+ if (val === null || val === void 0) {
5486
+ return val;
5487
+ }
5488
+ if (typeof val === "string") {
5489
+ return truncateString(val, maxStringLength);
5490
+ }
5491
+ if (typeof val === "number" || typeof val === "boolean") {
5492
+ return val;
5493
+ }
5494
+ if (typeof val === "bigint") {
5495
+ return `${val}n`;
5496
+ }
5497
+ if (typeof val === "function") {
5498
+ return "[Function]";
5499
+ }
5500
+ if (typeof val === "symbol") {
5501
+ return val.description ? `[Symbol(${val.description})]` : "[Symbol]";
5502
+ }
5503
+ if (val instanceof Date) {
5504
+ return val;
5505
+ }
5506
+ if (val instanceof Error) {
5507
+ return {
5508
+ name: val.name,
5509
+ message: val.message ? truncateString(val.message, maxStringLength) : void 0
5510
+ };
5511
+ }
5512
+ if (typeof val === "object") {
5513
+ if (seen.has(val)) {
5514
+ return "[Circular]";
5515
+ }
5516
+ seen.add(val);
5517
+ }
5518
+ if (Array.isArray(val)) {
5519
+ const limitedArray = val.slice(0, maxArrayLength);
5520
+ const cleaned2 = limitedArray.map((item) => helper(item, depth + 1));
5521
+ if (val.length > maxArrayLength) {
5522
+ cleaned2.push(`[\u2026${val.length - maxArrayLength} more items]`);
5523
+ }
5524
+ return cleaned2;
5525
+ }
5526
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(val)) {
5527
+ return `[Buffer length=${val.length}]`;
5528
+ }
5529
+ if (ArrayBuffer.isView(val)) {
5530
+ const ctor = val.constructor?.name ?? "TypedArray";
5531
+ const byteLength = val.byteLength ?? "?";
5532
+ return `[${ctor} byteLength=${byteLength}]`;
5533
+ }
5534
+ if (val instanceof ArrayBuffer) {
5535
+ return `[ArrayBuffer byteLength=${val.byteLength}]`;
5536
+ }
5537
+ const cleaned = {};
5538
+ const entries = Object.entries(val);
5539
+ let keyCount = 0;
5540
+ for (const [key, v] of entries) {
5541
+ if (keysToStrip.has(key)) {
5542
+ continue;
5543
+ }
5544
+ if (keyCount >= maxObjectKeys) {
5545
+ cleaned["__truncated"] = `${entries.length - keyCount} more keys omitted`;
5546
+ break;
5547
+ }
5548
+ try {
5549
+ cleaned[key] = helper(v, depth + 1);
5550
+ keyCount++;
5551
+ } catch (error) {
5552
+ cleaned[key] = `[${error instanceof Error ? error.message : String(error)}]`;
5553
+ keyCount++;
5554
+ }
5555
+ }
5556
+ return cleaned;
5557
+ }
5558
+ return helper(value, 0);
5559
+ }
5560
+
5457
5561
  // src/spans/base.ts
5458
5562
  function isSpanInternal(spanType, flags) {
5459
5563
  if (flags === void 0 || flags === observability.InternalSpans.NONE) {
@@ -5620,49 +5724,6 @@ var BaseSpan = class {
5620
5724
  return fn();
5621
5725
  }
5622
5726
  };
5623
- var DEFAULT_KEYS_TO_STRIP = /* @__PURE__ */ new Set([
5624
- "logger",
5625
- "experimental_providerMetadata",
5626
- "providerMetadata",
5627
- "steps",
5628
- "tracingContext"
5629
- ]);
5630
- function deepClean(value, options = {}, _seen = /* @__PURE__ */ new WeakSet(), _depth = 0) {
5631
- const { keysToStrip = DEFAULT_KEYS_TO_STRIP, maxDepth = 10 } = options;
5632
- if (_depth > maxDepth) {
5633
- return "[MaxDepth]";
5634
- }
5635
- if (value === null || typeof value !== "object") {
5636
- try {
5637
- JSON.stringify(value);
5638
- return value;
5639
- } catch (error) {
5640
- return `[${error instanceof Error ? error.message : String(error)}]`;
5641
- }
5642
- }
5643
- if (_seen.has(value)) {
5644
- return "[Circular]";
5645
- }
5646
- _seen.add(value);
5647
- if (value instanceof Date) {
5648
- return value;
5649
- }
5650
- if (Array.isArray(value)) {
5651
- return value.map((item) => deepClean(item, options, _seen, _depth + 1));
5652
- }
5653
- const cleaned = {};
5654
- for (const [key, val] of Object.entries(value)) {
5655
- if (keysToStrip.has(key)) {
5656
- continue;
5657
- }
5658
- try {
5659
- cleaned[key] = deepClean(val, options, _seen, _depth + 1);
5660
- } catch (error) {
5661
- cleaned[key] = `[${error instanceof Error ? error.message : String(error)}]`;
5662
- }
5663
- }
5664
- return cleaned;
5665
- }
5666
5727
  var DefaultSpan = class extends BaseSpan {
5667
5728
  id;
5668
5729
  traceId;
@@ -6545,6 +6606,8 @@ exports.BaseObservabilityInstance = BaseObservabilityInstance;
6545
6606
  exports.BaseSpan = BaseSpan;
6546
6607
  exports.CloudExporter = CloudExporter;
6547
6608
  exports.ConsoleExporter = ConsoleExporter;
6609
+ exports.DEFAULT_DEEP_CLEAN_OPTIONS = DEFAULT_DEEP_CLEAN_OPTIONS;
6610
+ exports.DEFAULT_KEYS_TO_STRIP = DEFAULT_KEYS_TO_STRIP;
6548
6611
  exports.DefaultExporter = DefaultExporter;
6549
6612
  exports.DefaultObservabilityInstance = DefaultObservabilityInstance;
6550
6613
  exports.DefaultSpan = DefaultSpan;
@@ -6561,5 +6624,6 @@ exports.observabilityConfigValueSchema = observabilityConfigValueSchema;
6561
6624
  exports.observabilityInstanceConfigSchema = observabilityInstanceConfigSchema;
6562
6625
  exports.observabilityRegistryConfigSchema = observabilityRegistryConfigSchema;
6563
6626
  exports.samplingStrategySchema = samplingStrategySchema;
6627
+ exports.truncateString = truncateString;
6564
6628
  //# sourceMappingURL=index.cjs.map
6565
6629
  //# sourceMappingURL=index.cjs.map