@mastra/observability 1.9.2-alpha.0 → 1.9.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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @mastra/observability
2
2
 
3
+ ## 1.9.2-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Improved tracing overhead when filtering spans. Spans dropped by `excludeSpanTypes` or the internal-span filter (`includeInternalSpans: false`) now skip payload serialization and retention entirely instead of paying the cost and discarding at export time. ([#15487](https://github.com/mastra-ai/mastra/pull/15487))
8
+
9
+ - Updated dependencies [[`6315317`](https://github.com/mastra-ai/mastra/commit/63153175fe9a7b224e5be7c209bbebc01dd9b0d5), [`9d3b24b`](https://github.com/mastra-ai/mastra/commit/9d3b24b19407ae9c09586cf7766d38dc4dff4a69)]:
10
+ - @mastra/core@1.26.0-alpha.6
11
+
3
12
  ## 1.9.2-alpha.0
4
13
 
5
14
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -19239,32 +19239,58 @@ var BaseSpan = class {
19239
19239
  parentSpanId;
19240
19240
  /** Deep clean options for serialization */
19241
19241
  deepCleanOptions;
19242
+ /**
19243
+ * Whether this span is filtered out before export. When true, BaseSpan/
19244
+ * DefaultSpan skip attaching attributes/input/output/errorInfo/requestContext
19245
+ * entirely -- they are never read on excluded spans, and skipping avoids
19246
+ * both the deepClean cost and holding references to large payloads for
19247
+ * the lifetime of the span. Set when excludeSpanTypes drops the type,
19248
+ * when the span is internal and includeInternalSpans is false, or when
19249
+ * the subclass is always excluded (e.g., NoOpSpan).
19250
+ *
19251
+ * Note: metadata is still attached and deepCleaned because it is read in
19252
+ * process by getCorrelationContext() and by getLoggerContext() /
19253
+ * getMetricsContext() (which structuredClone it).
19254
+ */
19255
+ isExcluded;
19242
19256
  /** Cached canonical correlation context for this live span */
19243
19257
  correlationContext;
19258
+ /**
19259
+ * Subclasses can override to unconditionally mark the span as excluded.
19260
+ * NoOpSpan uses this because it is never exported regardless of config.
19261
+ */
19262
+ get alwaysExcluded() {
19263
+ return false;
19264
+ }
19244
19265
  constructor(options, observabilityInstance) {
19245
- const serializationOptions = observabilityInstance.getConfig().serializationOptions;
19246
- this.deepCleanOptions = mergeSerializationOptions(serializationOptions);
19266
+ const observabilityConfig = observabilityInstance.getConfig();
19267
+ this.deepCleanOptions = mergeSerializationOptions(observabilityConfig.serializationOptions);
19247
19268
  this.name = options.name;
19248
19269
  this.type = options.type;
19249
- this.attributes = deepClean(options.attributes, this.deepCleanOptions) || {};
19270
+ this.isInternal = isSpanInternal(this.type, options.tracingPolicy?.internal);
19271
+ this.isExcluded = this.alwaysExcluded || observabilityConfig.excludeSpanTypes?.includes(this.type) === true || this.isInternal && !observabilityConfig.includeInternalSpans;
19250
19272
  this.metadata = deepClean(
19251
19273
  options.parent?.metadata || options.metadata ? { ...options.parent?.metadata, ...options.metadata } : void 0,
19252
19274
  this.deepCleanOptions
19253
19275
  );
19254
- if (options.requestContext && options.requestContext.size() > 0) {
19255
- this.requestContext = deepClean(options.requestContext.all, this.deepCleanOptions);
19256
- }
19257
19276
  this.parent = options.parent;
19258
19277
  this.startTime = options.startTime ?? /* @__PURE__ */ new Date();
19259
19278
  this.observabilityInstance = observabilityInstance;
19260
19279
  this.isEvent = options.isEvent ?? false;
19261
- this.isInternal = isSpanInternal(this.type, options.tracingPolicy?.internal);
19262
19280
  this.traceState = options.traceState;
19263
19281
  this.tags = !options.parent && options.tags?.length ? options.tags : void 0;
19264
19282
  const entityParent = this.getParentSpan(false);
19265
19283
  this.entityType = options.entityType ?? entityParent?.entityType;
19266
19284
  this.entityId = options.entityId ?? entityParent?.entityId;
19267
19285
  this.entityName = options.entityName ?? entityParent?.entityName;
19286
+ if (this.isExcluded) {
19287
+ this.attributes = {};
19288
+ return;
19289
+ }
19290
+ this.attributes = deepClean(options.attributes, this.deepCleanOptions) || {};
19291
+ if (options.requestContext && options.requestContext.size() > 0) {
19292
+ this.requestContext = deepClean(options.requestContext.all, this.deepCleanOptions);
19293
+ }
19268
19294
  if (this.isEvent) {
19269
19295
  this.output = deepClean(options.output, this.deepCleanOptions);
19270
19296
  } else {
@@ -19468,46 +19494,51 @@ var DefaultSpan = class extends BaseSpan {
19468
19494
  return;
19469
19495
  }
19470
19496
  this.endTime = /* @__PURE__ */ new Date();
19497
+ if (options?.metadata) {
19498
+ this.metadata = { ...this.metadata, ...deepClean(options.metadata, this.deepCleanOptions) };
19499
+ }
19500
+ if (this.isExcluded) {
19501
+ return;
19502
+ }
19471
19503
  if (options?.output !== void 0) {
19472
19504
  this.output = deepClean(options.output, this.deepCleanOptions);
19473
19505
  }
19474
19506
  if (options?.attributes) {
19475
19507
  this.attributes = { ...this.attributes, ...deepClean(options.attributes, this.deepCleanOptions) };
19476
19508
  }
19477
- if (options?.metadata) {
19478
- this.metadata = { ...this.metadata, ...deepClean(options.metadata, this.deepCleanOptions) };
19479
- }
19480
19509
  }
19481
19510
  error(options) {
19482
19511
  if (this.isEvent) {
19483
19512
  return;
19484
19513
  }
19485
19514
  const { error: error48, endSpan = true, attributes, metadata } = options;
19486
- this.errorInfo = deepClean(
19487
- error48 instanceof error$1.MastraError ? {
19488
- id: error48.id,
19489
- details: error48.details,
19490
- category: error48.category,
19491
- domain: error48.domain,
19492
- message: error48.message,
19493
- name: error48.name,
19494
- // Prefer the original cause's stack when available. MastraError wraps
19495
- // thrown errors, so its own stack points to the wrapping site rather
19496
- // than where the underlying error was thrown.
19497
- stack: error48.cause instanceof Error && error48.cause.stack || error48.stack
19498
- } : {
19499
- message: error48.message,
19500
- name: error48.name,
19501
- stack: error48.stack
19502
- },
19503
- this.deepCleanOptions
19504
- );
19505
- if (attributes) {
19506
- this.attributes = { ...this.attributes, ...deepClean(attributes, this.deepCleanOptions) };
19507
- }
19508
19515
  if (metadata) {
19509
19516
  this.metadata = { ...this.metadata, ...deepClean(metadata, this.deepCleanOptions) };
19510
19517
  }
19518
+ if (!this.isExcluded) {
19519
+ this.errorInfo = deepClean(
19520
+ error48 instanceof error$1.MastraError ? {
19521
+ id: error48.id,
19522
+ details: error48.details,
19523
+ category: error48.category,
19524
+ domain: error48.domain,
19525
+ message: error48.message,
19526
+ name: error48.name,
19527
+ // Prefer the original cause's stack when available. MastraError wraps
19528
+ // thrown errors, so its own stack points to the wrapping site rather
19529
+ // than where the underlying error was thrown.
19530
+ stack: error48.cause instanceof Error && error48.cause.stack || error48.stack
19531
+ } : {
19532
+ message: error48.message,
19533
+ name: error48.name,
19534
+ stack: error48.stack
19535
+ },
19536
+ this.deepCleanOptions
19537
+ );
19538
+ if (attributes) {
19539
+ this.attributes = { ...this.attributes, ...deepClean(attributes, this.deepCleanOptions) };
19540
+ }
19541
+ }
19511
19542
  if (endSpan) {
19512
19543
  this.end();
19513
19544
  } else {
@@ -19521,6 +19552,12 @@ var DefaultSpan = class extends BaseSpan {
19521
19552
  if (options.name !== void 0) {
19522
19553
  this.name = options.name;
19523
19554
  }
19555
+ if (options.metadata) {
19556
+ this.metadata = { ...this.metadata, ...deepClean(options.metadata, this.deepCleanOptions) };
19557
+ }
19558
+ if (this.isExcluded) {
19559
+ return;
19560
+ }
19524
19561
  if (options.input !== void 0) {
19525
19562
  this.input = deepClean(options.input, this.deepCleanOptions);
19526
19563
  }
@@ -19530,9 +19567,6 @@ var DefaultSpan = class extends BaseSpan {
19530
19567
  if (options.attributes) {
19531
19568
  this.attributes = { ...this.attributes, ...deepClean(options.attributes, this.deepCleanOptions) };
19532
19569
  }
19533
- if (options.metadata) {
19534
- this.metadata = { ...this.metadata, ...deepClean(options.metadata, this.deepCleanOptions) };
19535
- }
19536
19570
  }
19537
19571
  get isValid() {
19538
19572
  return true;
@@ -19608,6 +19642,10 @@ var NoOpSpan = class extends BaseSpan {
19608
19642
  get isValid() {
19609
19643
  return false;
19610
19644
  }
19645
+ // NoOpSpan is never exported, so treat it as always excluded.
19646
+ get alwaysExcluded() {
19647
+ return true;
19648
+ }
19611
19649
  };
19612
19650
 
19613
19651
  // src/instances/base.ts