Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Watch a Trace Unfold

In this lesson, you watched one hiker’s question go through the assistant while its trace grew in the trace file, one line per step, and worked out each step’s share of the request’s time.

Key Points

  • The request log gives one number for the whole request. The question “Does hut 5 have a free bed on Saturday?” took 1,826 milliseconds, and the log line can’t tell you which step took that time. It’s the one JSON line per request that Configuration, CORS and Logging for Node APIs also builds.
  • You can watch the trace file grow. In a second terminal in the project folder, tail -n 0 -f skips the lines already in the file and prints each new line as it’s added. In PowerShell, Get-Content with -Wait -Tail 0 does the same. The file is named for the date in UTC, which can differ from your local date: ls traces lists every date, newest last.
  • The run in the video uses stand-ins: a stand-in model, a scripted fake that the course’s exercises also use, and a keyword stand-in for retrieval. They return scripted results after set waits, so the times are a toy, and yours will differ. Retrieval with the local embeddings in your download won’t take under a millisecond like the stand-in.
  • Each step’s line lands when that step ends, because span() writes it in its finally block.
  • The question takes the tool path from Record a Trace per Request, and its trace has six lines: retrieve found two warden reports in under a millisecond; a model call with "promptVersion":"v2", "model":"capable" and "stopReason":"tool_call" asked for the hut-availability tool after 701 ms.
  • Then the tool ran and the answer streamed. hutAvailability found six free beds at hut 5 for July 18 (the assistant runs in a simulated July season) in about a millisecond. The answer streamed in a streamAnswer span, with a second model call inside it whose line landed first, after 1,104 ms with "stopReason":"end", and the streamAnswer line 1 ms later. Last, checks found no failures. Then the request’s log line landed in the server’s terminal: 1,810 milliseconds.
  • The stand-in fills the neutral fields its own way. It has no model ID, so model holds its role in your config, capable. With your provider, it holds the model the response names. Its stop reasons, tool_call and end, are its own words, and your provider’s stop reasons go in the same field.
  • Every new line starts with the same trace ID, the request ID in the log line. The terminal shows only this request’s new lines, and the file still holds the first ask’s lines above them, under their own ID. Read top to bottom, the lines tell the request’s story: what retrieval found, what the model asked for, what the tool returned, and how the model finished.
  • A step’s share is its time divided by the request’s. In this scripted run, the first model call took 38.7% and the streamed answer 61.0%. Retrieval, the tool and the checks took under 1% between them. The 3 ms the spans don’t account for is a residual: rounding, Express’s own work and the trace writes. With the stand-in’s set waits, the two model calls were almost all of the request’s time.
  • A trace grows one line per step, written when the step ends, all under the request’s ID. These shares are from one scripted request. Ask the same question with your own model, and your trace gives you your real shares.

The Trace From the Video

The question’s six trace lines, shortened here to their main fields and spread over several lines each:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 In the last lesson, each step of a request started writing a span to the trace file. Now you’ll watch that file grow while one question goes through the assistant.

00:10 A hiker asks whether hut 5 has a free bed on Saturday. The page shows the answer, and the server’s terminal shows the request’s log line. The request took 1,826 milliseconds.

00:24 That’s almost two seconds, and the log line gives you one number for all of it. It can’t tell you which step took the time.

00:33 To watch the trace, open a second terminal in the project folder, and use tail on today’s trace file. It’s named for the date in UTC, which can differ from your own.

00:43 Its -n 0 option skips the lines already in the file, and -f keeps following it, printing each new line. In PowerShell, Get-Content with its -Wait option does the same.

00:55 This run uses the stand-in model from the course’s exercises, and a stand-in for retrieval too. They return scripted results after set waits, so these times are a toy, and yours will differ.

01:09 Now ask the same question again, and watch both terminals.

01:14 Retrieval runs first, and finds two warden reports. Its line lands in the file. Retrieval took under a millisecond. Then the model call starts, with the reports and the tool.

01:26 Its bar grows. Next to it is the span() function from your trace module. Your turn: pause the video and predict when this call’s line will appear in the file.

01:41 When the call ends. The span() function writes its line in its finally block, after the step is done. Here, that’s 701 milliseconds later.

01:52 The prompt version is v2. The model field holds capable, its role in your config. The stop reason, tool_call, asks for the tool. Both are the stand-in’s own values.

02:04 With your provider, its model and its stop reasons go in the same fields.

02:11 The tool runs with hut 5 and Saturday’s date. The assistant runs in a simulated July season, so that’s July 18. It finds six free beds, in about a millisecond.

02:22 Now the answer streams to the page, inside a streamAnswer span, with the tool’s result in its input. A second model call runs inside that span.

02:32 It ends first, so its line lands first, after 1,104 milliseconds, with a stop reason of end. Then the streamAnswer line lands, one millisecond later.

02:44 Last, the checks run on the answer, and none fail. The response finishes, and the request’s line lands in the server’s terminal: 1,810 milliseconds.

02:56 The terminal shows six new lines for this request. The file still holds the first ask’s lines above them, under the first ask’s ID. Every new line starts with the same trace ID: the request ID in the log line.

03:09 Read top to bottom, they tell you what retrieval found, what the model asked for, what the tool returned, and how the model finished. Divide each step’s time by the request’s.

03:21 The first model call took 38.7 percent of it. The streamed answer took 61 percent. Retrieval, the tool and the checks took under one percent between them.

03:33 That leaves three milliseconds the spans don’t account for: rounding, Express’s own work and the trace writes. So in this run, with the stand-in’s set waits, the two model calls were almost all of the request’s time.

03:48 So a trace grows one line per step, written when the step ends, and all under the request’s ID.

03:56 These shares are from one scripted request. Ask the same question with your own model, and your trace gives you your real shares.

04:05 Every request now adds lines like these, and a busy summer adds thousands. In the next lesson, Decide What Traces Keep, you’ll choose which traces to keep, and for how long.

Become a Member to join the conversation.