@mastra/observability 1.19.0-alpha.2 → 1.19.0-alpha.4

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
@@ -2240,6 +2240,7 @@ var ModelSpanTracker = class {
2240
2240
  #stepIndex = 0;
2241
2241
  #chunkSequence = 0;
2242
2242
  #completionStartTime;
2243
+ #inferenceCompletionStartTime;
2243
2244
  #currentStepInputIsFinal = false;
2244
2245
  /** When true, step-finish chunks don't auto-close the step span (for durable execution) */
2245
2246
  #deferStepClose = false;
@@ -2261,8 +2262,9 @@ var ModelSpanTracker = class {
2261
2262
  * Capture the completion start time (time to first token) when the first content chunk arrives.
2262
2263
  */
2263
2264
  #captureCompletionStartTime() {
2264
- if (this.#completionStartTime) return;
2265
- this.#completionStartTime = /* @__PURE__ */ new Date();
2265
+ const now = /* @__PURE__ */ new Date();
2266
+ this.#completionStartTime ??= now;
2267
+ this.#inferenceCompletionStartTime ??= now;
2266
2268
  }
2267
2269
  /**
2268
2270
  * Get the tracing context for creating child spans.
@@ -2400,7 +2402,7 @@ var ModelSpanTracker = class {
2400
2402
  usage,
2401
2403
  finishReason: payload.stepResult.reason,
2402
2404
  warnings: payload.stepResult.warnings,
2403
- completionStartTime: this.#completionStartTime,
2405
+ completionStartTime: this.#inferenceCompletionStartTime,
2404
2406
  ...responseModel?.trim() ? { responseModel } : {}
2405
2407
  }
2406
2408
  });
@@ -2424,6 +2426,7 @@ var ModelSpanTracker = class {
2424
2426
  startInference(payload) {
2425
2427
  if (!supportsModelInference()) return;
2426
2428
  if (!this.#currentStepSpan || this.#currentInferenceSpan) return;
2429
+ this.#inferenceCompletionStartTime = void 0;
2427
2430
  const input = extractStepInput(payload);
2428
2431
  const generationAttrs = this.#modelSpan?.attributes;
2429
2432
  const ctx = this.#inferenceContext;
@@ -2447,6 +2450,16 @@ var ModelSpanTracker = class {
2447
2450
  });
2448
2451
  }
2449
2452
  /**
2453
+ * End the open MODEL_INFERENCE span as interrupted while keeping MODEL_STEP open,
2454
+ * so a replacement request for the same step gets its own inference span.
2455
+ */
2456
+ interruptInference() {
2457
+ this.#endChunkSpan();
2458
+ if (!this.#currentInferenceSpan) return;
2459
+ this.#currentInferenceSpan.end({ attributes: { finishReason: "interrupted" } });
2460
+ this.#currentInferenceSpan = void 0;
2461
+ }
2462
+ /**
2450
2463
  * Update the current step span with additional payload data.
2451
2464
  * Called when step-start chunk arrives with request/warnings info.
2452
2465
  */