@mastra/observability 1.0.0-beta.7 → 1.0.0-beta.8

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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # @mastra/observability
2
2
 
3
+ ## 1.0.0-beta.8
4
+
5
+ ### Patch Changes
6
+
7
+ - fix(observability): start MODEL_STEP span at beginning of LLM execution ([#11409](https://github.com/mastra-ai/mastra/pull/11409))
8
+
9
+ The MODEL_STEP span was being created when the step-start chunk arrived (after the model API call completed), causing the span's startTime to be close to its endTime instead of accurately reflecting when the step began.
10
+
11
+ This fix ensures MODEL_STEP spans capture the full duration of each LLM execution step, including the API call latency, by starting the span at the beginning of the step execution rather than when the response starts streaming.
12
+
13
+ Fixes #11271
14
+
15
+ - Updated dependencies [[`3d93a15`](https://github.com/mastra-ai/mastra/commit/3d93a15796b158c617461c8b98bede476ebb43e2), [`efe406a`](https://github.com/mastra-ai/mastra/commit/efe406a1353c24993280ebc2ed61dd9f65b84b26), [`119e5c6`](https://github.com/mastra-ai/mastra/commit/119e5c65008f3e5cfca954eefc2eb85e3bf40da4), [`74e504a`](https://github.com/mastra-ai/mastra/commit/74e504a3b584eafd2f198001c6a113bbec589fd3), [`e33fdbd`](https://github.com/mastra-ai/mastra/commit/e33fdbd07b33920d81e823122331b0c0bee0bb59), [`929f69c`](https://github.com/mastra-ai/mastra/commit/929f69c3436fa20dd0f0e2f7ebe8270bd82a1529), [`8a73529`](https://github.com/mastra-ai/mastra/commit/8a73529ca01187f604b1f3019d0a725ac63ae55f)]:
16
+ - @mastra/core@1.0.0-beta.16
17
+
3
18
  ## 1.0.0-beta.7
4
19
 
5
20
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -5136,9 +5136,14 @@ var ModelSpanTracker = class {
5136
5136
  this.#modelSpan?.update(options);
5137
5137
  }
5138
5138
  /**
5139
- * Start a new Model execution step
5139
+ * Start a new Model execution step.
5140
+ * This should be called at the beginning of LLM execution to capture accurate startTime.
5141
+ * The step-start chunk payload can be passed later via updateStep() if needed.
5140
5142
  */
5141
- #startStepSpan(payload) {
5143
+ startStep(payload) {
5144
+ if (this.#currentStepSpan) {
5145
+ return;
5146
+ }
5142
5147
  this.#currentStepSpan = this.#modelSpan?.createChildSpan({
5143
5148
  name: `step: ${this.#stepIndex}`,
5144
5149
  type: observability.SpanType.MODEL_STEP,
@@ -5151,6 +5156,22 @@ var ModelSpanTracker = class {
5151
5156
  });
5152
5157
  this.#chunkSequence = 0;
5153
5158
  }
5159
+ /**
5160
+ * Update the current step span with additional payload data.
5161
+ * Called when step-start chunk arrives with request/warnings info.
5162
+ */
5163
+ updateStep(payload) {
5164
+ if (!this.#currentStepSpan || !payload) {
5165
+ return;
5166
+ }
5167
+ this.#currentStepSpan.update({
5168
+ input: payload.request,
5169
+ attributes: {
5170
+ ...payload.messageId ? { messageId: payload.messageId } : {},
5171
+ ...payload.warnings?.length ? { warnings: payload.warnings } : {}
5172
+ }
5173
+ });
5174
+ }
5154
5175
  /**
5155
5176
  * End the current Model execution step with token usage, finish reason, output, and metadata
5156
5177
  */
@@ -5185,7 +5206,7 @@ var ModelSpanTracker = class {
5185
5206
  */
5186
5207
  #startChunkSpan(chunkType, initialData) {
5187
5208
  if (!this.#currentStepSpan) {
5188
- this.#startStepSpan();
5209
+ this.startStep();
5189
5210
  }
5190
5211
  this.#currentChunkSpan = this.#currentStepSpan?.createChildSpan({
5191
5212
  name: `chunk: '${chunkType}'`,
@@ -5225,7 +5246,7 @@ var ModelSpanTracker = class {
5225
5246
  */
5226
5247
  #createEventSpan(chunkType, output) {
5227
5248
  if (!this.#currentStepSpan) {
5228
- this.#startStepSpan();
5249
+ this.startStep();
5229
5250
  }
5230
5251
  const span = this.#currentStepSpan?.createEventSpan({
5231
5252
  name: `chunk: '${chunkType}'`,
@@ -5344,7 +5365,7 @@ var ModelSpanTracker = class {
5344
5365
  let acc = this.#toolOutputAccumulators.get(toolCallId);
5345
5366
  if (!acc) {
5346
5367
  if (!this.#currentStepSpan) {
5347
- this.#startStepSpan();
5368
+ this.startStep();
5348
5369
  }
5349
5370
  acc = {
5350
5371
  toolName: toolName || "unknown",
@@ -5444,7 +5465,11 @@ var ModelSpanTracker = class {
5444
5465
  this.#handleObjectChunk(chunk);
5445
5466
  break;
5446
5467
  case "step-start":
5447
- this.#startStepSpan(chunk.payload);
5468
+ if (this.#currentStepSpan) {
5469
+ this.updateStep(chunk.payload);
5470
+ } else {
5471
+ this.startStep(chunk.payload);
5472
+ }
5448
5473
  break;
5449
5474
  case "step-finish":
5450
5475
  this.#endStepSpan(chunk.payload);