Skip to main content
Applies to:
  • Plan - Any
  • Deployment - Any
  • Use case - Identify which LLM calls in a trace or project take the longest

Summary

To rank LLM spans by how long they took, compute each span’s duration as metrics.end - metrics.start in a SQL query and sort by it. Run the query on the Query page. To inspect a single trace visually, open it and use the Timeline view, which scales span bars by duration.

What is happening

In the default Traces row type of the logs table, each row is a trace represented by its root span. Fields that exist only on child spans, such as the details of an individual LLM call, appear empty in that view. Each span records its start and end times in metrics.start and metrics.end as Unix timestamps in seconds. LLM spans have span_attributes.type set to llm. Subtracting the two timestamps gives the span’s duration in seconds, which you can sort on in SQL.

Fix or suggestion

Option 1: Rank the LLM spans in one trace

Replace the project ID and the trace’s root span ID, then run the query on the Query page or with bt sql:
The root_span_id filter scopes the query to a single trace and maps directly to the index, so the query stays fast.

Option 2: Rank LLM spans across a project

To find the slowest LLM calls across all traces, replace the root_span_id filter with a time range and return root_span_id so you can open each trace:
Sorting on a computed value requires the engine to read every matching span before it applies LIMIT. Keep the time range as short as your investigation allows. See Sort on indexed columns.

Option 3: Inspect one trace in the timeline

  1. Go to Logs and open the trace.
  2. Select Timeline in the outline. Bar width represents each span’s duration by default.
  3. To show only LLM spans, select and then Filter by span type.
See View as a timeline for the other scaling options. To list every span in the logs table instead of one row per trace, open the row type selector in the toolbar and choose Spans. See Browse logs.

How to confirm it worked

  • The query results list LLM spans with the largest duration_seconds values first.
  • In the trace timeline, the spans at the top of the query results have the widest bars.

Notes

  • To track LLM latency over time instead of finding individual slow spans, chart avg(metrics.end - metrics.start) or percentile(metrics.end - metrics.start, 0.95) grouped by model. See Example queries.
  • The metrics.end IS NOT NULL filter excludes spans that have no recorded end time.