@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 +9 -0
- package/dist/index.cjs +73 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +73 -35
- package/dist/index.js.map +1 -1
- package/dist/spans/base.d.ts +19 -0
- package/dist/spans/base.d.ts.map +1 -1
- package/dist/spans/default.d.ts.map +1 -1
- package/dist/spans/no-op.d.ts +1 -0
- package/dist/spans/no-op.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -19231,32 +19231,58 @@ var BaseSpan = class {
|
|
|
19231
19231
|
parentSpanId;
|
|
19232
19232
|
/** Deep clean options for serialization */
|
|
19233
19233
|
deepCleanOptions;
|
|
19234
|
+
/**
|
|
19235
|
+
* Whether this span is filtered out before export. When true, BaseSpan/
|
|
19236
|
+
* DefaultSpan skip attaching attributes/input/output/errorInfo/requestContext
|
|
19237
|
+
* entirely -- they are never read on excluded spans, and skipping avoids
|
|
19238
|
+
* both the deepClean cost and holding references to large payloads for
|
|
19239
|
+
* the lifetime of the span. Set when excludeSpanTypes drops the type,
|
|
19240
|
+
* when the span is internal and includeInternalSpans is false, or when
|
|
19241
|
+
* the subclass is always excluded (e.g., NoOpSpan).
|
|
19242
|
+
*
|
|
19243
|
+
* Note: metadata is still attached and deepCleaned because it is read in
|
|
19244
|
+
* process by getCorrelationContext() and by getLoggerContext() /
|
|
19245
|
+
* getMetricsContext() (which structuredClone it).
|
|
19246
|
+
*/
|
|
19247
|
+
isExcluded;
|
|
19234
19248
|
/** Cached canonical correlation context for this live span */
|
|
19235
19249
|
correlationContext;
|
|
19250
|
+
/**
|
|
19251
|
+
* Subclasses can override to unconditionally mark the span as excluded.
|
|
19252
|
+
* NoOpSpan uses this because it is never exported regardless of config.
|
|
19253
|
+
*/
|
|
19254
|
+
get alwaysExcluded() {
|
|
19255
|
+
return false;
|
|
19256
|
+
}
|
|
19236
19257
|
constructor(options, observabilityInstance) {
|
|
19237
|
-
const
|
|
19238
|
-
this.deepCleanOptions = mergeSerializationOptions(serializationOptions);
|
|
19258
|
+
const observabilityConfig = observabilityInstance.getConfig();
|
|
19259
|
+
this.deepCleanOptions = mergeSerializationOptions(observabilityConfig.serializationOptions);
|
|
19239
19260
|
this.name = options.name;
|
|
19240
19261
|
this.type = options.type;
|
|
19241
|
-
this.
|
|
19262
|
+
this.isInternal = isSpanInternal(this.type, options.tracingPolicy?.internal);
|
|
19263
|
+
this.isExcluded = this.alwaysExcluded || observabilityConfig.excludeSpanTypes?.includes(this.type) === true || this.isInternal && !observabilityConfig.includeInternalSpans;
|
|
19242
19264
|
this.metadata = deepClean(
|
|
19243
19265
|
options.parent?.metadata || options.metadata ? { ...options.parent?.metadata, ...options.metadata } : void 0,
|
|
19244
19266
|
this.deepCleanOptions
|
|
19245
19267
|
);
|
|
19246
|
-
if (options.requestContext && options.requestContext.size() > 0) {
|
|
19247
|
-
this.requestContext = deepClean(options.requestContext.all, this.deepCleanOptions);
|
|
19248
|
-
}
|
|
19249
19268
|
this.parent = options.parent;
|
|
19250
19269
|
this.startTime = options.startTime ?? /* @__PURE__ */ new Date();
|
|
19251
19270
|
this.observabilityInstance = observabilityInstance;
|
|
19252
19271
|
this.isEvent = options.isEvent ?? false;
|
|
19253
|
-
this.isInternal = isSpanInternal(this.type, options.tracingPolicy?.internal);
|
|
19254
19272
|
this.traceState = options.traceState;
|
|
19255
19273
|
this.tags = !options.parent && options.tags?.length ? options.tags : void 0;
|
|
19256
19274
|
const entityParent = this.getParentSpan(false);
|
|
19257
19275
|
this.entityType = options.entityType ?? entityParent?.entityType;
|
|
19258
19276
|
this.entityId = options.entityId ?? entityParent?.entityId;
|
|
19259
19277
|
this.entityName = options.entityName ?? entityParent?.entityName;
|
|
19278
|
+
if (this.isExcluded) {
|
|
19279
|
+
this.attributes = {};
|
|
19280
|
+
return;
|
|
19281
|
+
}
|
|
19282
|
+
this.attributes = deepClean(options.attributes, this.deepCleanOptions) || {};
|
|
19283
|
+
if (options.requestContext && options.requestContext.size() > 0) {
|
|
19284
|
+
this.requestContext = deepClean(options.requestContext.all, this.deepCleanOptions);
|
|
19285
|
+
}
|
|
19260
19286
|
if (this.isEvent) {
|
|
19261
19287
|
this.output = deepClean(options.output, this.deepCleanOptions);
|
|
19262
19288
|
} else {
|
|
@@ -19460,46 +19486,51 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
19460
19486
|
return;
|
|
19461
19487
|
}
|
|
19462
19488
|
this.endTime = /* @__PURE__ */ new Date();
|
|
19489
|
+
if (options?.metadata) {
|
|
19490
|
+
this.metadata = { ...this.metadata, ...deepClean(options.metadata, this.deepCleanOptions) };
|
|
19491
|
+
}
|
|
19492
|
+
if (this.isExcluded) {
|
|
19493
|
+
return;
|
|
19494
|
+
}
|
|
19463
19495
|
if (options?.output !== void 0) {
|
|
19464
19496
|
this.output = deepClean(options.output, this.deepCleanOptions);
|
|
19465
19497
|
}
|
|
19466
19498
|
if (options?.attributes) {
|
|
19467
19499
|
this.attributes = { ...this.attributes, ...deepClean(options.attributes, this.deepCleanOptions) };
|
|
19468
19500
|
}
|
|
19469
|
-
if (options?.metadata) {
|
|
19470
|
-
this.metadata = { ...this.metadata, ...deepClean(options.metadata, this.deepCleanOptions) };
|
|
19471
|
-
}
|
|
19472
19501
|
}
|
|
19473
19502
|
error(options) {
|
|
19474
19503
|
if (this.isEvent) {
|
|
19475
19504
|
return;
|
|
19476
19505
|
}
|
|
19477
19506
|
const { error: error48, endSpan = true, attributes, metadata } = options;
|
|
19478
|
-
this.errorInfo = deepClean(
|
|
19479
|
-
error48 instanceof MastraError ? {
|
|
19480
|
-
id: error48.id,
|
|
19481
|
-
details: error48.details,
|
|
19482
|
-
category: error48.category,
|
|
19483
|
-
domain: error48.domain,
|
|
19484
|
-
message: error48.message,
|
|
19485
|
-
name: error48.name,
|
|
19486
|
-
// Prefer the original cause's stack when available. MastraError wraps
|
|
19487
|
-
// thrown errors, so its own stack points to the wrapping site rather
|
|
19488
|
-
// than where the underlying error was thrown.
|
|
19489
|
-
stack: error48.cause instanceof Error && error48.cause.stack || error48.stack
|
|
19490
|
-
} : {
|
|
19491
|
-
message: error48.message,
|
|
19492
|
-
name: error48.name,
|
|
19493
|
-
stack: error48.stack
|
|
19494
|
-
},
|
|
19495
|
-
this.deepCleanOptions
|
|
19496
|
-
);
|
|
19497
|
-
if (attributes) {
|
|
19498
|
-
this.attributes = { ...this.attributes, ...deepClean(attributes, this.deepCleanOptions) };
|
|
19499
|
-
}
|
|
19500
19507
|
if (metadata) {
|
|
19501
19508
|
this.metadata = { ...this.metadata, ...deepClean(metadata, this.deepCleanOptions) };
|
|
19502
19509
|
}
|
|
19510
|
+
if (!this.isExcluded) {
|
|
19511
|
+
this.errorInfo = deepClean(
|
|
19512
|
+
error48 instanceof MastraError ? {
|
|
19513
|
+
id: error48.id,
|
|
19514
|
+
details: error48.details,
|
|
19515
|
+
category: error48.category,
|
|
19516
|
+
domain: error48.domain,
|
|
19517
|
+
message: error48.message,
|
|
19518
|
+
name: error48.name,
|
|
19519
|
+
// Prefer the original cause's stack when available. MastraError wraps
|
|
19520
|
+
// thrown errors, so its own stack points to the wrapping site rather
|
|
19521
|
+
// than where the underlying error was thrown.
|
|
19522
|
+
stack: error48.cause instanceof Error && error48.cause.stack || error48.stack
|
|
19523
|
+
} : {
|
|
19524
|
+
message: error48.message,
|
|
19525
|
+
name: error48.name,
|
|
19526
|
+
stack: error48.stack
|
|
19527
|
+
},
|
|
19528
|
+
this.deepCleanOptions
|
|
19529
|
+
);
|
|
19530
|
+
if (attributes) {
|
|
19531
|
+
this.attributes = { ...this.attributes, ...deepClean(attributes, this.deepCleanOptions) };
|
|
19532
|
+
}
|
|
19533
|
+
}
|
|
19503
19534
|
if (endSpan) {
|
|
19504
19535
|
this.end();
|
|
19505
19536
|
} else {
|
|
@@ -19513,6 +19544,12 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
19513
19544
|
if (options.name !== void 0) {
|
|
19514
19545
|
this.name = options.name;
|
|
19515
19546
|
}
|
|
19547
|
+
if (options.metadata) {
|
|
19548
|
+
this.metadata = { ...this.metadata, ...deepClean(options.metadata, this.deepCleanOptions) };
|
|
19549
|
+
}
|
|
19550
|
+
if (this.isExcluded) {
|
|
19551
|
+
return;
|
|
19552
|
+
}
|
|
19516
19553
|
if (options.input !== void 0) {
|
|
19517
19554
|
this.input = deepClean(options.input, this.deepCleanOptions);
|
|
19518
19555
|
}
|
|
@@ -19522,9 +19559,6 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
19522
19559
|
if (options.attributes) {
|
|
19523
19560
|
this.attributes = { ...this.attributes, ...deepClean(options.attributes, this.deepCleanOptions) };
|
|
19524
19561
|
}
|
|
19525
|
-
if (options.metadata) {
|
|
19526
|
-
this.metadata = { ...this.metadata, ...deepClean(options.metadata, this.deepCleanOptions) };
|
|
19527
|
-
}
|
|
19528
19562
|
}
|
|
19529
19563
|
get isValid() {
|
|
19530
19564
|
return true;
|
|
@@ -19600,6 +19634,10 @@ var NoOpSpan = class extends BaseSpan {
|
|
|
19600
19634
|
get isValid() {
|
|
19601
19635
|
return false;
|
|
19602
19636
|
}
|
|
19637
|
+
// NoOpSpan is never exported, so treat it as always excluded.
|
|
19638
|
+
get alwaysExcluded() {
|
|
19639
|
+
return true;
|
|
19640
|
+
}
|
|
19603
19641
|
};
|
|
19604
19642
|
|
|
19605
19643
|
// src/instances/base.ts
|