@mastra/observability 1.21.0 → 1.21.1-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/index.js CHANGED
@@ -2638,7 +2638,7 @@ var ModelSpanTracker = class {
2638
2638
  * Returns undefined if no step span is active.
2639
2639
  */
2640
2640
  exportCurrentStep() {
2641
- return this.#currentStepSpan?.exportSpan();
2641
+ return this.#currentStepSpan?.snapshot();
2642
2642
  }
2643
2643
  /**
2644
2644
  * Get the pending step finish payload (captured when defer mode is enabled).
@@ -3550,6 +3550,13 @@ var BaseSpan = class BaseSpan {
3550
3550
  ...this.isRootSpan && !nestedUnderParent && this.tags?.length ? { tags: this.tags } : {}
3551
3551
  };
3552
3552
  }
3553
+ /** Returns the span saved for a later `rebuildSpan()`, with its trace state */
3554
+ snapshot() {
3555
+ return {
3556
+ ...this.exportSpan(),
3557
+ ...this.traceState ? { traceState: this.traceState } : {}
3558
+ };
3559
+ }
3553
3560
  get externalTraceId() {
3554
3561
  return this.isValid ? this.traceId : void 0;
3555
3562
  }
@@ -5156,7 +5163,7 @@ var BaseObservabilityInstance = class extends MastraBase {
5156
5163
  * - Can have end(), update(), error() called on it
5157
5164
  * - Will emit SPAN_ENDED or SPAN_UPDATED when those methods are called
5158
5165
  *
5159
- * @param cached - The exported span data to rebuild from
5166
+ * @param cached - The span snapshot to rebuild from
5160
5167
  * @returns A span that can have lifecycle methods called on it
5161
5168
  */
5162
5169
  rebuildSpan(cached) {
@@ -5176,15 +5183,26 @@ var BaseObservabilityInstance = class extends MastraBase {
5176
5183
  entityId: cached.entityId,
5177
5184
  entityName: cached.entityName,
5178
5185
  tracingPolicy: cached.isInternal ? { internal: InternalSpans.ALL } : void 0,
5179
- traceState: cached.nestedUnderParent ? {
5180
- requestContextKeys: [],
5181
- nestedUnderParent: true
5182
- } : void 0
5186
+ traceState: this.rebuildTraceState(cached)
5183
5187
  });
5184
5188
  this.wireSpanLifecycle(span);
5185
5189
  return span;
5186
5190
  }
5187
5191
  /**
5192
+ * Restore the trace-level rules for a rebuilt span. Spans saved with
5193
+ * `exportSpan()` before `snapshot()` existed fall back to the instance's
5194
+ * configured keys, so an in-flight durable run keeps at least those across an upgrade.
5195
+ */
5196
+ rebuildTraceState(cached) {
5197
+ if (cached.traceState) return cached.traceState;
5198
+ const fallback = this.computeTraceState();
5199
+ if (!cached.nestedUnderParent) return fallback;
5200
+ return {
5201
+ requestContextKeys: fallback?.requestContextKeys ?? [],
5202
+ nestedUnderParent: true
5203
+ };
5204
+ }
5205
+ /**
5188
5206
  * Get current configuration
5189
5207
  */
5190
5208
  getConfig() {