@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/dist/index.js CHANGED
@@ -5452,6 +5452,110 @@ var ModelSpanTracker = class {
5452
5452
  }
5453
5453
  };
5454
5454
 
5455
+ // src/spans/serialization.ts
5456
+ var DEFAULT_KEYS_TO_STRIP = /* @__PURE__ */ new Set([
5457
+ "logger",
5458
+ "experimental_providerMetadata",
5459
+ "providerMetadata",
5460
+ "steps",
5461
+ "tracingContext"
5462
+ ]);
5463
+ var DEFAULT_DEEP_CLEAN_OPTIONS = Object.freeze({
5464
+ keysToStrip: DEFAULT_KEYS_TO_STRIP,
5465
+ maxDepth: 6,
5466
+ maxStringLength: 1024,
5467
+ maxArrayLength: 50,
5468
+ maxObjectKeys: 50
5469
+ });
5470
+ function truncateString(s, maxChars) {
5471
+ if (s.length <= maxChars) {
5472
+ return s;
5473
+ }
5474
+ return s.slice(0, maxChars) + "\u2026[truncated]";
5475
+ }
5476
+ function deepClean(value, options = DEFAULT_DEEP_CLEAN_OPTIONS) {
5477
+ const { keysToStrip, maxDepth, maxStringLength, maxArrayLength, maxObjectKeys } = options;
5478
+ const seen = /* @__PURE__ */ new WeakSet();
5479
+ function helper(val, depth) {
5480
+ if (depth > maxDepth) {
5481
+ return "[MaxDepth]";
5482
+ }
5483
+ if (val === null || val === void 0) {
5484
+ return val;
5485
+ }
5486
+ if (typeof val === "string") {
5487
+ return truncateString(val, maxStringLength);
5488
+ }
5489
+ if (typeof val === "number" || typeof val === "boolean") {
5490
+ return val;
5491
+ }
5492
+ if (typeof val === "bigint") {
5493
+ return `${val}n`;
5494
+ }
5495
+ if (typeof val === "function") {
5496
+ return "[Function]";
5497
+ }
5498
+ if (typeof val === "symbol") {
5499
+ return val.description ? `[Symbol(${val.description})]` : "[Symbol]";
5500
+ }
5501
+ if (val instanceof Date) {
5502
+ return val;
5503
+ }
5504
+ if (val instanceof Error) {
5505
+ return {
5506
+ name: val.name,
5507
+ message: val.message ? truncateString(val.message, maxStringLength) : void 0
5508
+ };
5509
+ }
5510
+ if (typeof val === "object") {
5511
+ if (seen.has(val)) {
5512
+ return "[Circular]";
5513
+ }
5514
+ seen.add(val);
5515
+ }
5516
+ if (Array.isArray(val)) {
5517
+ const limitedArray = val.slice(0, maxArrayLength);
5518
+ const cleaned2 = limitedArray.map((item) => helper(item, depth + 1));
5519
+ if (val.length > maxArrayLength) {
5520
+ cleaned2.push(`[\u2026${val.length - maxArrayLength} more items]`);
5521
+ }
5522
+ return cleaned2;
5523
+ }
5524
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(val)) {
5525
+ return `[Buffer length=${val.length}]`;
5526
+ }
5527
+ if (ArrayBuffer.isView(val)) {
5528
+ const ctor = val.constructor?.name ?? "TypedArray";
5529
+ const byteLength = val.byteLength ?? "?";
5530
+ return `[${ctor} byteLength=${byteLength}]`;
5531
+ }
5532
+ if (val instanceof ArrayBuffer) {
5533
+ return `[ArrayBuffer byteLength=${val.byteLength}]`;
5534
+ }
5535
+ const cleaned = {};
5536
+ const entries = Object.entries(val);
5537
+ let keyCount = 0;
5538
+ for (const [key, v] of entries) {
5539
+ if (keysToStrip.has(key)) {
5540
+ continue;
5541
+ }
5542
+ if (keyCount >= maxObjectKeys) {
5543
+ cleaned["__truncated"] = `${entries.length - keyCount} more keys omitted`;
5544
+ break;
5545
+ }
5546
+ try {
5547
+ cleaned[key] = helper(v, depth + 1);
5548
+ keyCount++;
5549
+ } catch (error) {
5550
+ cleaned[key] = `[${error instanceof Error ? error.message : String(error)}]`;
5551
+ keyCount++;
5552
+ }
5553
+ }
5554
+ return cleaned;
5555
+ }
5556
+ return helper(value, 0);
5557
+ }
5558
+
5455
5559
  // src/spans/base.ts
5456
5560
  function isSpanInternal(spanType, flags) {
5457
5561
  if (flags === void 0 || flags === InternalSpans.NONE) {
@@ -5618,49 +5722,6 @@ var BaseSpan = class {
5618
5722
  return fn();
5619
5723
  }
5620
5724
  };
5621
- var DEFAULT_KEYS_TO_STRIP = /* @__PURE__ */ new Set([
5622
- "logger",
5623
- "experimental_providerMetadata",
5624
- "providerMetadata",
5625
- "steps",
5626
- "tracingContext"
5627
- ]);
5628
- function deepClean(value, options = {}, _seen = /* @__PURE__ */ new WeakSet(), _depth = 0) {
5629
- const { keysToStrip = DEFAULT_KEYS_TO_STRIP, maxDepth = 10 } = options;
5630
- if (_depth > maxDepth) {
5631
- return "[MaxDepth]";
5632
- }
5633
- if (value === null || typeof value !== "object") {
5634
- try {
5635
- JSON.stringify(value);
5636
- return value;
5637
- } catch (error) {
5638
- return `[${error instanceof Error ? error.message : String(error)}]`;
5639
- }
5640
- }
5641
- if (_seen.has(value)) {
5642
- return "[Circular]";
5643
- }
5644
- _seen.add(value);
5645
- if (value instanceof Date) {
5646
- return value;
5647
- }
5648
- if (Array.isArray(value)) {
5649
- return value.map((item) => deepClean(item, options, _seen, _depth + 1));
5650
- }
5651
- const cleaned = {};
5652
- for (const [key, val] of Object.entries(value)) {
5653
- if (keysToStrip.has(key)) {
5654
- continue;
5655
- }
5656
- try {
5657
- cleaned[key] = deepClean(val, options, _seen, _depth + 1);
5658
- } catch (error) {
5659
- cleaned[key] = `[${error instanceof Error ? error.message : String(error)}]`;
5660
- }
5661
- }
5662
- return cleaned;
5663
- }
5664
5725
  var DefaultSpan = class extends BaseSpan {
5665
5726
  id;
5666
5727
  traceId;
@@ -6538,6 +6599,6 @@ function buildTracingOptions(...updaters) {
6538
6599
  return updaters.reduce((opts, updater) => updater(opts), {});
6539
6600
  }
6540
6601
 
6541
- export { BaseExporter, BaseObservabilityInstance, BaseSpan, CloudExporter, ConsoleExporter, DefaultExporter, DefaultObservabilityInstance, DefaultSpan, ModelSpanTracker, NoOpSpan, Observability, SamplingStrategyType, SensitiveDataFilter, TestExporter, buildTracingOptions, deepClean, getExternalParentId, observabilityConfigValueSchema, observabilityInstanceConfigSchema, observabilityRegistryConfigSchema, samplingStrategySchema };
6602
+ export { BaseExporter, BaseObservabilityInstance, BaseSpan, CloudExporter, ConsoleExporter, DEFAULT_DEEP_CLEAN_OPTIONS, DEFAULT_KEYS_TO_STRIP, DefaultExporter, DefaultObservabilityInstance, DefaultSpan, ModelSpanTracker, NoOpSpan, Observability, SamplingStrategyType, SensitiveDataFilter, TestExporter, buildTracingOptions, deepClean, getExternalParentId, observabilityConfigValueSchema, observabilityInstanceConfigSchema, observabilityRegistryConfigSchema, samplingStrategySchema, truncateString };
6542
6603
  //# sourceMappingURL=index.js.map
6543
6604
  //# sourceMappingURL=index.js.map