@mastra/observability 1.17.2 → 1.17.3
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 +26 -0
- package/dist/index.cjs +20 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -4
- package/dist/index.js.map +1 -1
- package/dist/instances/base.d.ts.map +1 -1
- package/dist/spans/base.d.ts +14 -0
- package/dist/spans/base.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createRequire } from "module";
|
|
|
2
2
|
import { MastraBase } from "@mastra/core/base";
|
|
3
3
|
import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
|
|
4
4
|
import { ConsoleLogger, LogLevel, RegisteredLogger } from "@mastra/core/logger";
|
|
5
|
-
import { DEFAULT_BLOCKED_LABELS, EntityType, InternalSpans, SpanType, TracingEventType, generateSignalId, noOpLoggerContext } from "@mastra/core/observability";
|
|
5
|
+
import { DEFAULT_BLOCKED_LABELS, EntityType, InternalSpans, SpanType, TracingEventType, generateSignalId, noOpLoggerContext, resolveExportedSpanId } from "@mastra/core/observability";
|
|
6
6
|
import { fetchWithRetry, getNestedValue, setNestedValue } from "@mastra/core/utils";
|
|
7
7
|
import { z } from "zod/v4";
|
|
8
8
|
import fs from "fs";
|
|
@@ -2854,6 +2854,23 @@ var BaseSpan = class BaseSpan {
|
|
|
2854
2854
|
if (parent.isExcluded || !includeInternalSpans && parent.isInternal) return parent.getParentSpan(includeInternalSpans);
|
|
2855
2855
|
return this.parent;
|
|
2856
2856
|
}
|
|
2857
|
+
/**
|
|
2858
|
+
* Get the spanId that observability signals (logs, metrics, scores) should
|
|
2859
|
+
* reference for this span. If this span itself reaches exporters, that is
|
|
2860
|
+
* its own id. If it is excluded from export (internal span, excludeSpanTypes,
|
|
2861
|
+
* or NoOpSpan), resolves to the nearest exportable ancestor instead.
|
|
2862
|
+
* Returns undefined when no exportable ancestor exists.
|
|
2863
|
+
*
|
|
2864
|
+
* Only covers exclusions known when the span is created (`isExcluded`). A
|
|
2865
|
+
* `spanFilter` or a span output processor can still drop a span at export
|
|
2866
|
+
* time — both run on the exported span data after the span ends, so their
|
|
2867
|
+
* verdict isn't knowable while signals are being stamped. Signals emitted
|
|
2868
|
+
* inside a span dropped that way still reference its own id.
|
|
2869
|
+
*/
|
|
2870
|
+
getExportedSpanId() {
|
|
2871
|
+
if (!this.isExcluded) return this.id;
|
|
2872
|
+
return this.getParentSpanId(this.observabilityInstance.getConfig().includeInternalSpans);
|
|
2873
|
+
}
|
|
2857
2874
|
/** Get the closest parent spanId that will reach exporters (unless includeInternalSpans) */
|
|
2858
2875
|
getParentSpanId(includeInternalSpans) {
|
|
2859
2876
|
if (!this.parent) return this.parentSpanId;
|
|
@@ -2895,7 +2912,7 @@ var BaseSpan = class BaseSpan {
|
|
|
2895
2912
|
const rootTags = rootSpan.tags?.length ? [...rootSpan.tags] : void 0;
|
|
2896
2913
|
this.correlationContext = {
|
|
2897
2914
|
traceId: this.traceId,
|
|
2898
|
-
spanId: this.
|
|
2915
|
+
spanId: this.getExportedSpanId(),
|
|
2899
2916
|
tags: rootTags,
|
|
2900
2917
|
entityType: this.entityType,
|
|
2901
2918
|
entityId: this.entityId,
|
|
@@ -3414,7 +3431,7 @@ var BaseObservabilityInstance = class extends MastraBase {
|
|
|
3414
3431
|
const metadata = span?.metadata ? structuredClone(span.metadata) : void 0;
|
|
3415
3432
|
return new LoggerContextImpl({
|
|
3416
3433
|
traceId: span?.traceId,
|
|
3417
|
-
spanId: span
|
|
3434
|
+
spanId: resolveExportedSpanId(span),
|
|
3418
3435
|
correlationContext,
|
|
3419
3436
|
metadata,
|
|
3420
3437
|
observabilityBus: this.observabilityBus,
|
|
@@ -3431,7 +3448,7 @@ var BaseObservabilityInstance = class extends MastraBase {
|
|
|
3431
3448
|
const metadata = span?.metadata ? structuredClone(span.metadata) : void 0;
|
|
3432
3449
|
return new MetricsContextImpl({
|
|
3433
3450
|
traceId: span?.traceId,
|
|
3434
|
-
spanId: span
|
|
3451
|
+
spanId: resolveExportedSpanId(span),
|
|
3435
3452
|
correlationContext,
|
|
3436
3453
|
metadata,
|
|
3437
3454
|
cardinalityFilter: this.cardinalityFilter,
|