@mastra/observability 1.11.0 → 1.11.1-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/dist/index.js CHANGED
@@ -13985,9 +13985,9 @@ var BaseExporter = class {
13985
13985
  *
13986
13986
  * @param reason - Reason why the exporter is disabled
13987
13987
  */
13988
- setDisabled(reason) {
13988
+ setDisabled(reason, level = "warn") {
13989
13989
  this.#disabled = true;
13990
- this.logger.warn(`${this.name} disabled: ${reason}`);
13990
+ this.logger[level](`${this.name} disabled: ${reason}`);
13991
13991
  }
13992
13992
  /**
13993
13993
  * Apply the customSpanFormatter if configured.
@@ -15171,7 +15171,7 @@ var CloudExporter = class extends BaseExporter {
15171
15171
  const rawProjectId = config2.projectId ?? process.env.MASTRA_PROJECT_ID;
15172
15172
  const projectId = rawProjectId && VALID_PROJECT_ID.test(rawProjectId) ? rawProjectId : void 0;
15173
15173
  if (!accessToken) {
15174
- this.setDisabled("MASTRA_CLOUD_ACCESS_TOKEN environment variable not set.");
15174
+ this.setDisabled("MASTRA_CLOUD_ACCESS_TOKEN environment variable not set.", "debug");
15175
15175
  }
15176
15176
  const tracesEndpointOverride = config2.tracesEndpoint ?? process.env.MASTRA_CLOUD_TRACES_ENDPOINT;
15177
15177
  let baseEndpoint;
@@ -18733,7 +18733,11 @@ function summarizeRequestBody(body) {
18733
18733
  }
18734
18734
  return Object.keys(summary).length > 0 ? summary : "[request body]";
18735
18735
  }
18736
- function extractStepInput(request) {
18736
+ function extractStepInput(payload) {
18737
+ if (Array.isArray(payload?.inputMessages)) {
18738
+ return normalizeMessages(payload.inputMessages);
18739
+ }
18740
+ const request = payload?.request;
18737
18741
  if (!request) return void 0;
18738
18742
  const { body } = request;
18739
18743
  if (body == null) return request;
@@ -18753,6 +18757,7 @@ var ModelSpanTracker = class {
18753
18757
  #stepIndex = 0;
18754
18758
  #chunkSequence = 0;
18755
18759
  #completionStartTime;
18760
+ #currentStepInputIsFinal = false;
18756
18761
  /** When true, step-finish chunks don't auto-close the step span (for durable execution) */
18757
18762
  #deferStepClose = false;
18758
18763
  /** Stored step-finish payload when defer mode is enabled */
@@ -18846,6 +18851,7 @@ var ModelSpanTracker = class {
18846
18851
  if (this.#currentStepSpan) {
18847
18852
  return;
18848
18853
  }
18854
+ const input = extractStepInput(payload);
18849
18855
  this.#currentStepSpan = this.#modelSpan?.createChildSpan({
18850
18856
  name: `step: ${this.#stepIndex}`,
18851
18857
  type: SpanType.MODEL_STEP,
@@ -18854,8 +18860,9 @@ var ModelSpanTracker = class {
18854
18860
  ...payload?.messageId ? { messageId: payload.messageId } : {},
18855
18861
  ...payload?.warnings?.length ? { warnings: payload.warnings } : {}
18856
18862
  },
18857
- input: extractStepInput(payload?.request)
18863
+ input
18858
18864
  });
18865
+ this.#currentStepInputIsFinal = Array.isArray(payload?.inputMessages);
18859
18866
  this.#chunkSequence = 0;
18860
18867
  }
18861
18868
  /**
@@ -18866,13 +18873,18 @@ var ModelSpanTracker = class {
18866
18873
  if (!this.#currentStepSpan || !payload) {
18867
18874
  return;
18868
18875
  }
18876
+ const hasFinalInput = Array.isArray(payload.inputMessages);
18877
+ const input = hasFinalInput || !this.#currentStepInputIsFinal ? extractStepInput(payload) : void 0;
18869
18878
  this.#currentStepSpan.update({
18870
- input: extractStepInput(payload.request),
18879
+ ...input !== void 0 ? { input } : {},
18871
18880
  attributes: {
18872
18881
  ...payload.messageId ? { messageId: payload.messageId } : {},
18873
18882
  ...payload.warnings?.length ? { warnings: payload.warnings } : {}
18874
18883
  }
18875
18884
  });
18885
+ if (hasFinalInput) {
18886
+ this.#currentStepInputIsFinal = true;
18887
+ }
18876
18888
  }
18877
18889
  /**
18878
18890
  * End the current Model execution step with token usage, finish reason, output, and metadata
@@ -18904,6 +18916,7 @@ var ModelSpanTracker = class {
18904
18916
  }
18905
18917
  });
18906
18918
  this.#currentStepSpan = void 0;
18919
+ this.#currentStepInputIsFinal = false;
18907
18920
  this.#stepIndex++;
18908
18921
  }
18909
18922
  /**
@@ -19479,7 +19492,8 @@ var BaseSpan = class {
19479
19492
  async executeInContext(fn) {
19480
19493
  const bridge = this.observabilityInstance.getBridge();
19481
19494
  if (bridge?.executeInContext) {
19482
- return bridge.executeInContext(this.id, fn);
19495
+ const bridgeContextSpan = this.isInternal ? this.getParentSpan(false) : this;
19496
+ return bridge.executeInContext(bridgeContextSpan?.id ?? this.id, fn);
19483
19497
  }
19484
19498
  return fn();
19485
19499
  }
@@ -19490,7 +19504,8 @@ var BaseSpan = class {
19490
19504
  executeInContextSync(fn) {
19491
19505
  const bridge = this.observabilityInstance.getBridge();
19492
19506
  if (bridge?.executeInContextSync) {
19493
- return bridge.executeInContextSync(this.id, fn);
19507
+ const bridgeContextSpan = this.isInternal ? this.getParentSpan(false) : this;
19508
+ return bridge.executeInContextSync(bridgeContextSpan?.id ?? this.id, fn);
19494
19509
  }
19495
19510
  return fn();
19496
19511
  }