@mastra/observability 1.18.4 → 1.19.0-alpha.0
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/exporters/tracking.d.ts +7 -0
- package/dist/exporters/tracking.d.ts.map +1 -1
- package/dist/index.cjs +84 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +84 -19
- package/dist/index.js.map +1 -1
- package/dist/instances/base.d.ts.map +1 -1
- package/dist/spans/base.d.ts +1 -1
- package/dist/spans/base.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -149,6 +149,10 @@ export declare class TraceData<TRootData, TSpanData, TEventData, TMetadata> {
|
|
|
149
149
|
clearWaitingFor(args: {
|
|
150
150
|
spanId: string;
|
|
151
151
|
}): void;
|
|
152
|
+
/**
|
|
153
|
+
* Get the span IDs that have events waiting on them.
|
|
154
|
+
*/
|
|
155
|
+
getWaitingForSpanIds(): string[];
|
|
152
156
|
/**
|
|
153
157
|
* Get total count of events in all waiting queues.
|
|
154
158
|
*/
|
|
@@ -448,6 +452,9 @@ export declare abstract class TrackingExporter<TRootData, TSpanData, TEventData,
|
|
|
448
452
|
* This is useful in serverless environments where you need to ensure spans
|
|
449
453
|
* are exported before the runtime instance is terminated.
|
|
450
454
|
*
|
|
455
|
+
* Queued events whose dependencies have been built are processed first, so
|
|
456
|
+
* a shutdown() right after flush() only aborts spans that are still open.
|
|
457
|
+
*
|
|
451
458
|
* Subclasses should override _flush() to implement vendor-specific flush logic.
|
|
452
459
|
*/
|
|
453
460
|
flush(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracking.d.ts","sourceRoot":"","sources":["../../src/exporters/tracking.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC/F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC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KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAU3B;IAED;;;OAGG;IACH,UAAgB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAG;IAEhD;;;OAGG;IACH,UAAgB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAG;IAEjD;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAoD9B;CACF"}
|
package/dist/index.cjs
CHANGED
|
@@ -3204,6 +3204,7 @@ var BaseSpan = class BaseSpan {
|
|
|
3204
3204
|
exportSpan(includeInternalSpans) {
|
|
3205
3205
|
const hideInput = this.traceState?.hideInput ?? false;
|
|
3206
3206
|
const hideOutput = this.traceState?.hideOutput ?? false;
|
|
3207
|
+
const nestedUnderParent = this.traceState?.nestedUnderParent ?? false;
|
|
3207
3208
|
return {
|
|
3208
3209
|
id: this.id,
|
|
3209
3210
|
traceId: this.traceId,
|
|
@@ -3225,7 +3226,8 @@ var BaseSpan = class BaseSpan {
|
|
|
3225
3226
|
...this.isInternal ? { isInternal: true } : {},
|
|
3226
3227
|
parentSpanId: this.getParentSpanId(includeInternalSpans),
|
|
3227
3228
|
externalParentSpanId: this.getExportedExternalParentSpanId(includeInternalSpans),
|
|
3228
|
-
...
|
|
3229
|
+
...nestedUnderParent ? { nestedUnderParent: true } : {},
|
|
3230
|
+
...this.isRootSpan && !nestedUnderParent && this.tags?.length ? { tags: this.tags } : {}
|
|
3229
3231
|
};
|
|
3230
3232
|
}
|
|
3231
3233
|
get externalTraceId() {
|
|
@@ -3238,7 +3240,7 @@ var BaseSpan = class BaseSpan {
|
|
|
3238
3240
|
async executeInContext(fn) {
|
|
3239
3241
|
const bridge = this.observabilityInstance.getBridge();
|
|
3240
3242
|
if (bridge?.executeInContext) {
|
|
3241
|
-
const bridgeContextSpan = this.isInternal ? this.getParentSpan(false) : this;
|
|
3243
|
+
const bridgeContextSpan = this.isInternal || this.isExcluded ? this.getParentSpan(false) : this;
|
|
3242
3244
|
return bridge.executeInContext(bridgeContextSpan?.id ?? this.id, fn);
|
|
3243
3245
|
}
|
|
3244
3246
|
return fn();
|
|
@@ -3250,7 +3252,7 @@ var BaseSpan = class BaseSpan {
|
|
|
3250
3252
|
executeInContextSync(fn) {
|
|
3251
3253
|
const bridge = this.observabilityInstance.getBridge();
|
|
3252
3254
|
if (bridge?.executeInContextSync) {
|
|
3253
|
-
const bridgeContextSpan = this.isInternal ? this.getParentSpan(false) : this;
|
|
3255
|
+
const bridgeContextSpan = this.isInternal || this.isExcluded ? this.getParentSpan(false) : this;
|
|
3254
3256
|
return bridge.executeInContextSync(bridgeContextSpan?.id ?? this.id, fn);
|
|
3255
3257
|
}
|
|
3256
3258
|
return fn();
|
|
@@ -3295,7 +3297,7 @@ var DefaultSpan = class extends BaseSpan {
|
|
|
3295
3297
|
return;
|
|
3296
3298
|
}
|
|
3297
3299
|
const bridge = observabilityInstance.getBridge();
|
|
3298
|
-
if (bridge && !this.isInternal) {
|
|
3300
|
+
if (bridge && !this.isInternal && !this.isExcluded) {
|
|
3299
3301
|
const bridgeIds = bridge.createSpan(options);
|
|
3300
3302
|
if (bridgeIds) {
|
|
3301
3303
|
this.id = bridgeIds.spanId;
|
|
@@ -4772,6 +4774,11 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
|
|
|
4772
4774
|
tags,
|
|
4773
4775
|
requestContext
|
|
4774
4776
|
});
|
|
4777
|
+
if (!options.parent && traceState?.nestedUnderParent && (!tracingOptions?.traceId || span.traceId !== tracingOptions.traceId || !tracingOptions.parentSpanId || !(span instanceof BaseSpan) || span.externalParentSpanId !== tracingOptions.parentSpanId)) {
|
|
4778
|
+
const { nestedUnderParent: _ignored, ...ownTraceState } = traceState;
|
|
4779
|
+
span.traceState = ownTraceState;
|
|
4780
|
+
this.logger.debug("[Observability] Ignoring tracingOptions.nestUnderParent: the run did not join the requested trace under the requested parent");
|
|
4781
|
+
}
|
|
4775
4782
|
if (rest.type === _mastra_core_observability.SpanType.MODEL_GENERATION && this.config.excludeSpanTypes?.includes(_mastra_core_observability.SpanType.MODEL_GENERATION)) {
|
|
4776
4783
|
const attrs = rest.attributes;
|
|
4777
4784
|
const model = resolveModelId(attrs?.responseModel, attrs?.model);
|
|
@@ -4807,6 +4814,7 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
|
|
|
4807
4814
|
traceId: cached.traceId,
|
|
4808
4815
|
spanId: cached.id,
|
|
4809
4816
|
parentSpanId: cached.parentSpanId,
|
|
4817
|
+
externalParentSpanId: cached.externalParentSpanId,
|
|
4810
4818
|
startTime: cached.startTime instanceof Date ? cached.startTime : new Date(cached.startTime),
|
|
4811
4819
|
input: cached.input,
|
|
4812
4820
|
attributes: cached.attributes,
|
|
@@ -4814,7 +4822,11 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
|
|
|
4814
4822
|
entityType: cached.entityType,
|
|
4815
4823
|
entityId: cached.entityId,
|
|
4816
4824
|
entityName: cached.entityName,
|
|
4817
|
-
tracingPolicy: cached.isInternal ? { internal: _mastra_core_observability.InternalSpans.ALL } : void 0
|
|
4825
|
+
tracingPolicy: cached.isInternal ? { internal: _mastra_core_observability.InternalSpans.ALL } : void 0,
|
|
4826
|
+
traceState: cached.nestedUnderParent ? {
|
|
4827
|
+
requestContextKeys: [],
|
|
4828
|
+
nestedUnderParent: true
|
|
4829
|
+
} : void 0
|
|
4818
4830
|
});
|
|
4819
4831
|
this.wireSpanLifecycle(span);
|
|
4820
4832
|
return span;
|
|
@@ -5018,11 +5030,13 @@ var BaseObservabilityInstance = class extends _mastra_core_base.MastraBase {
|
|
|
5018
5030
|
const allKeys = [...configuredKeys, ...additionalKeys];
|
|
5019
5031
|
const hideInput = tracingOptions?.hideInput;
|
|
5020
5032
|
const hideOutput = tracingOptions?.hideOutput;
|
|
5021
|
-
|
|
5033
|
+
const nestedUnderParent = tracingOptions?.nestUnderParent === true;
|
|
5034
|
+
if (allKeys.length === 0 && !hideInput && !hideOutput && !nestedUnderParent) return;
|
|
5022
5035
|
return {
|
|
5023
5036
|
requestContextKeys: allKeys,
|
|
5024
5037
|
...hideInput !== void 0 && { hideInput },
|
|
5025
|
-
...hideOutput !== void 0 && { hideOutput }
|
|
5038
|
+
...hideOutput !== void 0 && { hideOutput },
|
|
5039
|
+
...nestedUnderParent && { nestedUnderParent }
|
|
5026
5040
|
};
|
|
5027
5041
|
}
|
|
5028
5042
|
/**
|
|
@@ -5894,6 +5908,12 @@ var TraceData = class {
|
|
|
5894
5908
|
this.#waitingForParent.delete(args.spanId);
|
|
5895
5909
|
}
|
|
5896
5910
|
/**
|
|
5911
|
+
* Get the span IDs that have events waiting on them.
|
|
5912
|
+
*/
|
|
5913
|
+
getWaitingForSpanIds() {
|
|
5914
|
+
return [...this.#waitingForParent.keys()];
|
|
5915
|
+
}
|
|
5916
|
+
/**
|
|
5897
5917
|
* Get total count of events in all waiting queues.
|
|
5898
5918
|
*/
|
|
5899
5919
|
waitingQueueSize() {
|
|
@@ -6077,6 +6097,8 @@ var TrackingExporter = class extends BaseExporter {
|
|
|
6077
6097
|
#hardCapEnforcementInProgress = false;
|
|
6078
6098
|
/** Map of traceId to scheduled cleanup timeout */
|
|
6079
6099
|
#pendingCleanups = /* @__PURE__ */ new Map();
|
|
6100
|
+
/** Waiting-queue replays started by setImmediate that haven't finished yet */
|
|
6101
|
+
#activeReplays = /* @__PURE__ */ new Set();
|
|
6080
6102
|
/** Subclass configuration with resolved values */
|
|
6081
6103
|
config;
|
|
6082
6104
|
/** Maximum attempts to process a queued event before dropping */
|
|
@@ -6104,12 +6126,13 @@ var TrackingExporter = class extends BaseExporter {
|
|
|
6104
6126
|
*/
|
|
6105
6127
|
#scheduleProcessWaitingForRoot(traceId) {
|
|
6106
6128
|
setImmediate(() => {
|
|
6107
|
-
this.#
|
|
6129
|
+
if (this.#shutdownStarted) return;
|
|
6130
|
+
this.#trackReplay(this.#processWaitingForRoot(traceId).then(() => {}, (error) => {
|
|
6108
6131
|
this.logger.error(`${this.name}: Error processing waiting-for-root queue`, {
|
|
6109
6132
|
error,
|
|
6110
6133
|
traceId
|
|
6111
6134
|
});
|
|
6112
|
-
});
|
|
6135
|
+
}));
|
|
6113
6136
|
});
|
|
6114
6137
|
}
|
|
6115
6138
|
/**
|
|
@@ -6118,24 +6141,59 @@ var TrackingExporter = class extends BaseExporter {
|
|
|
6118
6141
|
*/
|
|
6119
6142
|
#scheduleProcessWaitingFor(traceId, spanId) {
|
|
6120
6143
|
setImmediate(() => {
|
|
6121
|
-
this.#
|
|
6144
|
+
if (this.#shutdownStarted) return;
|
|
6145
|
+
this.#trackReplay(this.#processWaitingFor(traceId, spanId).then(() => {}, (error) => {
|
|
6122
6146
|
this.logger.error(`${this.name}: Error processing waiting queue`, {
|
|
6123
6147
|
error,
|
|
6124
6148
|
traceId,
|
|
6125
6149
|
spanId
|
|
6126
6150
|
});
|
|
6127
|
-
});
|
|
6151
|
+
}));
|
|
6128
6152
|
});
|
|
6129
6153
|
}
|
|
6130
6154
|
/**
|
|
6155
|
+
* Track a running replay so flush() and shutdown() can wait for it.
|
|
6156
|
+
*/
|
|
6157
|
+
#trackReplay(replay) {
|
|
6158
|
+
this.#activeReplays.add(replay);
|
|
6159
|
+
replay.finally(() => this.#activeReplays.delete(replay));
|
|
6160
|
+
}
|
|
6161
|
+
/**
|
|
6162
|
+
* Process every queued event whose dependency has been built, without waiting for the
|
|
6163
|
+
* setImmediate-scheduled replays (which never fire under fake timers). Waits for replays
|
|
6164
|
+
* that are already running, then repeats until a pass makes no progress, so cascades
|
|
6165
|
+
* (root -> parent -> child -> end) are fully drained.
|
|
6166
|
+
*/
|
|
6167
|
+
async #drainWaitingQueues() {
|
|
6168
|
+
while (true) {
|
|
6169
|
+
while (this.#activeReplays.size > 0) await Promise.all(this.#activeReplays);
|
|
6170
|
+
let progressed = false;
|
|
6171
|
+
for (const [traceId, traceData] of this.#traceMap) try {
|
|
6172
|
+
if (traceData.isRootProcessed() && await this.#processWaitingForRoot(traceId) > 0) progressed = true;
|
|
6173
|
+
for (const spanId of traceData.getWaitingForSpanIds()) {
|
|
6174
|
+
if (!traceData.hasSpan({ spanId })) continue;
|
|
6175
|
+
if (await this.#processWaitingFor(traceId, spanId) > 0) progressed = true;
|
|
6176
|
+
}
|
|
6177
|
+
} catch (error) {
|
|
6178
|
+
this.logger.error(`${this.name}: Error draining waiting queues`, {
|
|
6179
|
+
error,
|
|
6180
|
+
traceId
|
|
6181
|
+
});
|
|
6182
|
+
}
|
|
6183
|
+
if (!progressed && this.#activeReplays.size === 0) return;
|
|
6184
|
+
}
|
|
6185
|
+
}
|
|
6186
|
+
/**
|
|
6131
6187
|
* Process all events waiting for root span.
|
|
6188
|
+
* Takes the queue before processing, so a concurrent call can't process the same events.
|
|
6189
|
+
* @returns The number of events that left the queue (processed, moved or dropped)
|
|
6132
6190
|
*/
|
|
6133
6191
|
async #processWaitingForRoot(traceId) {
|
|
6134
|
-
if (this.#shutdownStarted) return;
|
|
6135
6192
|
const traceData = this.#traceMap.get(traceId);
|
|
6136
|
-
if (!traceData) return;
|
|
6193
|
+
if (!traceData) return 0;
|
|
6137
6194
|
const queue = traceData.getEventsWaitingForRoot();
|
|
6138
|
-
if (queue.length === 0) return;
|
|
6195
|
+
if (queue.length === 0) return 0;
|
|
6196
|
+
traceData.clearWaitingForRoot();
|
|
6139
6197
|
this.logger.debug(`${this.name}: Processing ${queue.length} events waiting for root`, { traceId });
|
|
6140
6198
|
const toKeep = [];
|
|
6141
6199
|
const now = Date.now();
|
|
@@ -6171,23 +6229,25 @@ var TrackingExporter = class extends BaseExporter {
|
|
|
6171
6229
|
else toKeep.push(queuedEvent);
|
|
6172
6230
|
}
|
|
6173
6231
|
}
|
|
6174
|
-
traceData.clearWaitingForRoot();
|
|
6175
6232
|
for (const event of toKeep) traceData.addToWaitingQueue({
|
|
6176
6233
|
event: event.event,
|
|
6177
6234
|
waitingFor: "root",
|
|
6178
6235
|
attempts: event.attempts,
|
|
6179
6236
|
queuedAt: event.queuedAt
|
|
6180
6237
|
});
|
|
6238
|
+
return queue.length - toKeep.length;
|
|
6181
6239
|
}
|
|
6182
6240
|
/**
|
|
6183
6241
|
* Process events waiting for a specific parent span.
|
|
6242
|
+
* Takes the queue before processing, so a concurrent call can't process the same events.
|
|
6243
|
+
* @returns The number of events that left the queue (processed, moved or dropped)
|
|
6184
6244
|
*/
|
|
6185
6245
|
async #processWaitingFor(traceId, spanId) {
|
|
6186
|
-
if (this.#shutdownStarted) return;
|
|
6187
6246
|
const traceData = this.#traceMap.get(traceId);
|
|
6188
|
-
if (!traceData) return;
|
|
6247
|
+
if (!traceData) return 0;
|
|
6189
6248
|
const queue = traceData.getEventsWaitingFor({ spanId });
|
|
6190
|
-
if (queue.length === 0) return;
|
|
6249
|
+
if (queue.length === 0) return 0;
|
|
6250
|
+
traceData.clearWaitingFor({ spanId });
|
|
6191
6251
|
this.logger.debug(`${this.name}: Processing ${queue.length} events waiting for span`, {
|
|
6192
6252
|
traceId,
|
|
6193
6253
|
spanId
|
|
@@ -6217,13 +6277,13 @@ var TrackingExporter = class extends BaseExporter {
|
|
|
6217
6277
|
queuedEvent.attempts++;
|
|
6218
6278
|
if (!await this.#tryProcessQueuedEvent(queuedEvent, traceData)) toKeep.push(queuedEvent);
|
|
6219
6279
|
}
|
|
6220
|
-
traceData.clearWaitingFor({ spanId });
|
|
6221
6280
|
for (const event of toKeep) traceData.addToWaitingQueue({
|
|
6222
6281
|
event: event.event,
|
|
6223
6282
|
waitingFor: spanId,
|
|
6224
6283
|
attempts: event.attempts,
|
|
6225
6284
|
queuedAt: event.queuedAt
|
|
6226
6285
|
});
|
|
6286
|
+
return queue.length - toKeep.length;
|
|
6227
6287
|
}
|
|
6228
6288
|
/**
|
|
6229
6289
|
* Try to process a queued event.
|
|
@@ -6683,11 +6743,15 @@ var TrackingExporter = class extends BaseExporter {
|
|
|
6683
6743
|
* This is useful in serverless environments where you need to ensure spans
|
|
6684
6744
|
* are exported before the runtime instance is terminated.
|
|
6685
6745
|
*
|
|
6746
|
+
* Queued events whose dependencies have been built are processed first, so
|
|
6747
|
+
* a shutdown() right after flush() only aborts spans that are still open.
|
|
6748
|
+
*
|
|
6686
6749
|
* Subclasses should override _flush() to implement vendor-specific flush logic.
|
|
6687
6750
|
*/
|
|
6688
6751
|
async flush() {
|
|
6689
6752
|
if (this.isDisabled) return;
|
|
6690
6753
|
this.logger.debug(`${this.name}: Flushing`);
|
|
6754
|
+
if (!this.#shutdownStarted) await this.#drainWaitingQueues();
|
|
6691
6755
|
await this._flush();
|
|
6692
6756
|
}
|
|
6693
6757
|
/**
|
|
@@ -6707,6 +6771,7 @@ var TrackingExporter = class extends BaseExporter {
|
|
|
6707
6771
|
async shutdown() {
|
|
6708
6772
|
if (this.isDisabled) return;
|
|
6709
6773
|
this.#shutdownStarted = true;
|
|
6774
|
+
await this.#drainWaitingQueues();
|
|
6710
6775
|
await this._preShutdown();
|
|
6711
6776
|
for (const [traceId, timeout] of this.#pendingCleanups) {
|
|
6712
6777
|
clearTimeout(timeout);
|