> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orq.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LLM traces for debugging

> Explore step-by-step details of every LLM generation. Debug RAG pipelines, evaluators, guardrails, and caching with full workflow visibility and cost tracking.

## What are Traces

**Traces** record every AI request handled by **Orq.ai**, from a single model call to a multi-step **Agent** run. Each trace shows the full workflow of one request as a tree of steps (spans), with inputs, outputs, latency, token usage and cost for each step.

Traces are created for:

* Model calls sent through the [AI Gateway](/ai-gateway/using-the-router)
* [Agent](/ai-studio/ai-engineering/run-agents) runs, including sub-agent and tool calls
* [Deployment](/ai-studio/ai-engineering/deployments) invocations
* Coding sessions from [code assistants](/ai-studio/integrations/code-assistants/overview) connected to **Orq.ai**
* Application code instrumented with [OpenTelemetry frameworks](/ai-studio/integrations/frameworks/overview) or the [`@traced` decorator](#custom-tracing-using-the-traced-decorator)

A trace contains a step for each operation in the request, such as:

* LLM calls, including [Retries and Fallbacks](/ai-studio/ai-engineering/deployments#primary-model-retries-and-fallback)
* Tool and sub-agent calls
* [Evaluators](/ai-studio/optimize/evaluators) and [Guardrails](/ai-studio/ai-engineering/deployments#evaluators-and-guardrails)
* Retrieval from a [Knowledge Base](/ai-studio/ai-engineering/knowledge-bases), including [Embeddings](/ai-studio/ai-engineering/knowledge-bases#embedding-models)
* [Caching](/ai-studio/ai-engineering/deployments#cache)

## Creating Traces

Traces are generated automatically for requests through the **AI Gateway**, **Agents** and **Deployments**. Create custom traces for application code using framework instrumentation or the Orq.ai SDK.

### Framework Instrumentation

For popular AI frameworks and libraries, use automatic instrumentation with OpenTelemetry:

<Card title="Framework Integrations" icon="plug" href="/ai-studio/integrations/frameworks/overview">
  Explore automatic instrumentation for OpenAI, LangChain, LlamaIndex, CrewAI, Autogen, and 15+ other frameworks with OpenTelemetry integration.
</Card>

### Custom Tracing using the @traced decorator

For custom functions or application workflows, use the `@traced` decorator from the [Python SDK](https://github.com/orq-ai/orq-python). It works with both synchronous and async functions:

<CodeGroup>
  ```python Sync theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import os
  from orq_ai_sdk import Orq
  from orq_ai_sdk.traced import traced

  @traced(name="process_document", type="agent")
  def process_document(doc_id: str):
      result = {"status": "processed", "doc_id": doc_id}
      return result

  @traced(name="fetch_context", type="retrieval")
  def fetch_relevant_context(query: str):
      return {"context": "relevant information", "sources": ["doc1", "doc2"]}

  @traced(name="format_response", type="function")
  def format_response(raw_output: str, metadata: dict):
      return {"formatted": raw_output.strip(), "metadata": metadata}

  @traced(name="document_pipeline", type="agent")
  def document_pipeline(orq, doc_id: str):
      doc = process_document(doc_id)
      context = fetch_relevant_context("user query")

      response = orq.responses.create(
          model="agent/simple-agent",
          input=f"Summarize this document: {doc['status']}. Context: {context['context']}",
      )

      return format_response(response.output[0]["content"][0]["text"], {"doc_id": doc_id})

  with Orq(api_key=os.getenv("ORQ_API_KEY")) as orq:
      result = document_pipeline(orq, "doc-123")
      print(result)
  ```

  ```python Async theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import os
  import asyncio
  from orq_ai_sdk import Orq
  from orq_ai_sdk.traced import traced

  @traced(name="process_document", type="agent")
  async def process_document(doc_id: str):
      result = {"status": "processed", "doc_id": doc_id}
      return result

  @traced(name="fetch_context", type="retrieval")
  async def fetch_relevant_context(query: str):
      return {"context": "relevant information", "sources": ["doc1", "doc2"]}

  @traced(name="format_response", type="function")
  async def format_response(raw_output: str, metadata: dict):
      return {"formatted": raw_output.strip(), "metadata": metadata}

  @traced(name="document_pipeline", type="agent")
  async def document_pipeline(orq, doc_id: str):
      doc = await process_document(doc_id)
      context = await fetch_relevant_context("user query")

      response = await orq.responses.create_async(
          model="agent/simple-agent",
          input=f"Summarize this document: {doc['status']}. Context: {context['context']}",
      )

      return await format_response(response.output[0]["content"][0]["text"], {"doc_id": doc_id})

  async def main():
      async with Orq(api_key=os.getenv("ORQ_API_KEY")) as orq:
          result = await document_pipeline(orq, "doc-123")
          print(result)

  asyncio.run(main())
  ```
</CodeGroup>

The result is a single trace with each decorated function appearing as a nested span:

<Frame caption="Custom trace with nested spans from @traced.">
  <img src="https://mintcdn.com/orqai/Sq2lGFeR4EsRHsB1/images/traced-example.png?fit=max&auto=format&n=Sq2lGFeR4EsRHsB1&q=85&s=c4d4f21efd839ab45ca91f84893401f0" alt="Trace view showing a document_pipeline root span with process_document, fetch_context, and format_response nested as child spans, each with latency and token usage." width="1526" height="913" data-path="images/traced-example.png" />
</Frame>

<Info>
  The `@traced` decorator supports the following span types:

  | Type | Description |
  | - | - |
  | `agent` | A high-level orchestration step or agent workflow |
  | `embedding` | An embedding generation operation |
  | `function` | A general-purpose function or processing step |
  | `llm` | A direct LLM API call |
  | `retrieval` | A retrieval or knowledge lookup operation |
  | `tool` | An external tool call |

  Capture or suppress inputs/outputs with `capture_input` and `capture_output`, and attach custom metadata with the `attributes` parameter:

  ```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  @traced(
      name="process_document",
      type="agent",
      capture_input=False,
      capture_output=False,
      attributes={"version": "1.0", "env": "production"}
  )
  def process_document(doc_id: str):
      ...
  ```
</Info>

## How to Lookup Traces

To find traces, open **Traces** in the **Observability** section of the sidebar.

The page has three parts:

* **Query bar**: search, filters, time range, and the <kbd><Icon icon="eye" /> Views</kbd>, <kbd><Icon icon="table-columns" /> Fields</kbd>, <kbd><Icon icon="list-check" /> Review</kbd> and <kbd><Icon icon="arrows-rotate" /> Reload</kbd> buttons.
* **Activity chart**: the number of **Successful** and **Errors** traces over the selected time range. Click a bar to zoom into that time window, then click <kbd><Icon icon="rotate-left" /></kbd> to go back to the previous range.
* **Traces table**: one row per trace, newest first. Scroll down to load more traces.

Select a row to open the trace in a side panel, showing the **hierarchy** of events in order of execution and the details of the selected step. With a trace open, press <kbd>J</kbd> and <kbd>K</kbd> to move to the next or previous trace.

Turn on **Live** to refresh the list every 10 seconds. Live pauses while a trace is open.

<Tip>
  Search, filters, columns and time range are stored in the page URL. Copy the URL to share the exact list with a teammate.
</Tip>

### Trace Views

Each trace can be inspected in three views to suit different debugging and analysis needs.

<Tabs>
  <Tab title="Trace" icon="diagram-project">
    The **Trace** view shows the full execution tree for a single run. Each step is displayed hierarchically, including LLM calls, tool invocations, knowledge retrievals, and memory interactions. Use this view to inspect inputs, outputs, token usage, and latency at every step.

    For multi-agent runs, the hierarchy renders as an **agent graph**: parent agents and their sub-agent calls are shown as a nested tree, making it easy to follow how work was delegated across agents and where time was spent. See [Agent Graphs](/ai-studio/observability/agent-graphs) for how graphs are produced and how to debug delegation paths.

    <Frame>
      <img src="https://mintcdn.com/orqai/ZrHBE0npZNYLFUSD/images/agent-traces-49.png?fit=max&auto=format&n=ZrHBE0npZNYLFUSD&q=85&s=b69af1b7446be69afbf11cde2e516630" alt="Trace view in Orq.ai showing a multi-agent call graph: product-orchestrator delegates to agent-compositor, which calls agent-response, call_sub_agent, find_documents, and router-cache-agent. The right panel shows span properties, input, and output for the selected step." width="3468" height="1980" data-path="images/agent-traces-49.png" />
    </Frame>

    <Tip>
      Erroring Traces are shown with a <Icon icon="circle-exclamation" color="red" /> icon.
    </Tip>

    <Info>
      Manually evaluate responses using **Annotations** directly on individual spans. Annotations defined in the project are available on all spans automatically. Learn more in [Annotations](/ai-studio/observability/annotations).
    </Info>
  </Tab>

  <Tab title="Thread" icon="messages">
    The **Thread** view presents the execution as a conversation thread, showing the sequence of messages exchanged between the user, the agent, and any tools. Use this view to follow the narrative flow of a task and understand how the agent reasoned through a problem.

    <Frame>
      <img src="https://mintcdn.com/orqai/hYJ46ZNib1CGRiid/images/agent-traces-thread.png?fit=max&auto=format&n=hYJ46ZNib1CGRiid&q=85&s=6b2904b134eee8a2a6a4f37751e5be41" alt="The Thread view presenting agent execution as a conversation showing messages between the user, agent, and tools." width="1161" height="1176" data-path="images/agent-traces-thread.png" />
    </Frame>
  </Tab>

  <Tab title="Timeline" icon="chart-gantt">
    The **Timeline** view shows execution steps plotted against time, making it easy to identify bottlenecks, measure step durations, and understand which operations ran sequentially or in parallel.

    <Frame>
      <img src="https://mintcdn.com/orqai/hYJ46ZNib1CGRiid/images/agent-traces-timeline.png?fit=max&auto=format&n=hYJ46ZNib1CGRiid&q=85&s=727f7c4a29aa23a55b81126c612c384d" alt="The Timeline view plotting execution steps against time to identify bottlenecks and measure step durations." width="1165" height="1176" data-path="images/agent-traces-timeline.png" />
    </Frame>
  </Tab>
</Tabs>

### Search and Time Range

The search box matches part of a trace ID, thread ID or session ID, and the name, span ID, model, provider, agent name or tool name of any span in the trace. Matching is case-insensitive.

Select the time range picker <kbd><Icon icon="clock" /></kbd> to choose a preset from **5 mins** to **90 days**, or set a **Start date** and **End date** for a custom range. Presets longer than the workspace's data retention are disabled. The last preset used is remembered for the next visit.

<Tip>
  Switch the query bar from **Builder** to **OQL** to write the query as a pipeline, for example `fetch traces | filter status == "error" | sort end_time desc | limit 100`. See [Trace and log selection with OQL](/ai-studio/observability/oql).
</Tip>

### Viewing Errors

Traces that encountered an error show a red **error** status badge in the list, and are counted as **Errors** in the activity chart. Add a **Status** filter with the value `error` to scope the list to errors only.

<Frame caption="Traces list filtered to error status.">
  <img src="https://mintcdn.com/orqai/XWoQ2F5BVHxTrRfP/images/traces-errors.png?fit=max&auto=format&n=XWoQ2F5BVHxTrRfP&q=85&s=cc2cce27558ff888f206690a6a6311e9" alt="Traces list over 14 days with a Status is error filter chip, red error bars in the activity chart and a red error badge on every row." width="2000" height="607" data-path="images/traces-errors.png" />
</Frame>

The **Status** filter combines with any other filter, for example:

* Filter by **Status** `error` and an **Identity** to see all errors for a specific user.
* Combine with **Project** or a metadata field to narrow down failures to a particular environment or deployment.

Save the filter as a [view](#creating-custom-views) to return to it in one click.

### Filtering Traces

1. Click <kbd><Icon icon="bars-filter" /> Filter</kbd> in the query bar.
2. Select a field. Search the list to find it faster. Common fields such as **Status**, **Model** and **Trace name** are listed first, followed by the attributes and metadata fields found in the workspace's traces.
3. Select an operator, for example `==`, `!=`, `contains`, `in`, `between` or `is empty`.
4. Pick a suggested value or type one, then click <kbd><Icon icon="plus" /> Filter</kbd>.

The first filter applies immediately. Each filter then appears as a chip below the query bar:

* Click a chip to change its operator or value, or click <kbd><Icon icon="xmark" /></kbd> to remove it.
* Click <kbd><Icon icon="plus" /></kbd> to add another filter.
* With two or more filters, choose **and** to match all of them or **or** to match any of them.
* Changes to the filters wait until **Run** is clicked. **Clear** removes all filters at once.

<Frame caption="Traces filtered by status, model and duration.">
  <img src="https://mintcdn.com/orqai/XWoQ2F5BVHxTrRfP/images/traces-filters.png?fit=max&auto=format&n=XWoQ2F5BVHxTrRfP&q=85&s=acf7bda0ec0820b103deeb4370c78cd1" alt="Traces list filtered with three chips combined with and: Status is success, Model is claude-sonnet-5 and Duration greater than or equals 8000, returning three matching traces." width="2000" height="578" data-path="images/traces-filters.png" />
</Frame>

<Info>
  When working with [Agents](/ai-studio/ai-engineering/run-agents#traces), access traces directly from the Agent page with automatic filtering for that specific agent.
</Info>

### Filter grammar

The **Search traces** and **Search logs** APIs take a `filters` array alongside the free-text `query`. Each entry is one condition:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "field": "status",
  "op": "in",
  "values": ["error"]
}
```

| Key | Value |
| - | - |
| `field` | Field name, up to 128 characters of letters, digits, and `_ . : -` |
| `op` | Comparison operator, from the set below |
| `values` | String array, up to 100 entries of up to 4096 characters each. Numeric and timestamp values are sent as strings |

`filter_operator` combines the entries with `and` (default) or `or`. A request accepts up to 20 filters. `from` and `to` are required and bound the search window; `sort`, `limit`, and `page_token` follow the [Search traces reference](/reference/traces/search-traces) for traces and the [Search logs reference](/reference/logs/search-logs) for logs.

The `op` values are `eq`, `neq`, `in`, `not_in`, `gt`, `gte`, `lt`, `lte`, `between`, `contains`, `exists`, and `not_exists`. The table lists the operators each type commonly accepts; a specific field may accept fewer or more:

| Field type | Operators | Example |
| - | - | - |
| String | `eq`, `neq`, `in`, `not_in`, `contains`, `exists`, `not_exists` | `{"field": "name", "op": "contains", "values": ["checkout"]}` |
| Number | `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `between`, `exists` | `{"field": "tokens.total", "op": "gt", "values": ["1000"]}` |
| Timestamp | `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `between`, `exists`, `not_exists` | `{"field": "start_time", "op": "gte", "values": ["2026-10-01T00:00:00Z"]}` |
| Boolean | `eq`, `neq`, `exists`, `not_exists` | `{"field": "eval_passed", "op": "eq", "values": ["true"]}` |
| Enum | `eq`, `neq`, `in`, `not_in` | `{"field": "status", "op": "in", "values": ["error"]}` |

`between` takes exactly two values, the lower bound first. `exists` and `not_exists` take no values.

Field-level support varies, so call `GET /v3/traces/fields` for the filter fields, their types, and the operators each one accepts. Log search uses the same filter object and operator vocabulary.

### Configuring Columns

Click <kbd><Icon icon="table-columns" /> Fields</kbd> to open the **Fields** panel and choose which columns the table shows. Every attribute and metadata field found in the workspace's traces can be shown as a column, next to the built-in columns such as **Start time**, **Status**, **Trace name**, **Duration**, **Total tokens**, **Total cost** and **Trace ID**.

<Frame caption="The Fields panel.">
  <img src="https://mintcdn.com/orqai/XWoQ2F5BVHxTrRfP/images/traces-fields-panel.png?fit=max&auto=format&n=XWoQ2F5BVHxTrRfP&q=85&s=19a9236e52c71aaca0b7189c469ad946" alt="Fields panel in the Selected view showing 11 of 61 fields checked, including Start time, Status, Trace ID and Total cost, with a search box at the top." width="578" height="914" data-path="images/traces-fields-panel.png" />
</Frame>

* **Show or hide**: check or uncheck a field. Search the panel to find a field by name.
* **Reorder**: switch to **Selected** and drag a field by <Icon icon="grip-vertical" /> to move its column. Reordering only works while all selected fields are visible, so clear the search box first.
* **Resize**: drag the right edge of a column header.
* **Rename**: open <Icon icon="ellipsis" /> on an attribute or metadata column header and select **Edit name** to give it a display name.
* **Remove**: open <Icon icon="ellipsis" /> on a column header and select **Remove** to hide it.

Column widths and order are remembered in the browser. To keep a column layout and share it with the workspace, save it in a view.

### Creating Custom Views

A view saves the current filters, columns and column names under a name, to reopen them later from the <kbd><Icon icon="eye" /> Views</kbd> dropdown.

To create a view:

1. Set the filters and columns.
2. Open <kbd><Icon icon="eye" /> Views</kbd> and select **Create new view**.
3. Enter a **Name**.
4. Optionally check **Make this view private for myself**. Views are shared with workspace members by default.
5. Click **Create View**.

To update a view, select it, change the filters or columns, then open **Save** next to the filter chips and select **Save to this view**. When only the columns changed, click **Update view** in the query bar instead.

Hover a view in the dropdown to manage it:

* <Icon icon="thumbtack" />: set or unset it as the default view. The default view opens automatically on the Traces page.
* <Icon icon="ellipsis" /> > **Edit**: change its name or privacy.
* <Icon icon="ellipsis" /> > **Share**: copy a link that opens the view with its filters.
* <Icon icon="ellipsis" /> > **Delete**: delete the view.

Select **Default view** to return to the standard columns with no saved filters.

<Note>
  Views saved on the previous Traces page were moved to the new page. Filters that the new page cannot express were adjusted or removed.
</Note>

Manage saved Views programmatically through the [Views API](/ai-studio/observability/views-api).

## Review Traces

Click <kbd><Icon icon="list-check" /> Review</kbd> in the toolbar to open the review screen and step through traces one by one. Applying one or more [filters](#filtering-traces) first narrows the review queue to matching traces; with no filter active, Review steps through the current list.

<Frame caption="The review screen for Traces.">
  <img src="https://mintcdn.com/orqai/l_rJNig3OsTi7WLR/images/traces-review.png?fit=max&auto=format&n=l_rJNig3OsTi7WLR&q=85&s=20e668fa79a20e2fdf48da072a82d26d" alt="Traces toolbar with Reload and Review buttons. The Review button is highlighted." width="1376" height="764" data-path="images/traces-review.png" />
</Frame>

The screen follows the same three-panel layout as [Annotation Queues](/ai-studio/observability/annotation-queues#use-annotation-queues):

* **Left**: Inputs and Metrics for the selected span.
* **Center**: Full trace conversation.
* **Right**: [Annotation](/ai-studio/observability/annotations) controls for manual review. Select <Icon icon="circle-plus" /> in the Annotations panel header to [create a new annotation](/ai-studio/observability/annotations#create-annotations) without leaving the screen.

Annotations applied here are written back to the span and are queryable via the [**Orq MCP**](/ai-studio/integrations/code-assistants/orq-mcp).

## Correct an Evaluator Result

Hover an Evaluator result to reveal a <Icon icon="pencil" />, and select it to open a popover with:

* **Value**: the corrected result, matching the Evaluator's own output type (a toggle for boolean Evaluators, a text or number field otherwise).
* **Explanation**: an optional comment.

Select **Correct** to submit, or **Update** to replace an existing correction. The correction appears under the original result as **Corrected to \<value>**, along with the explanation and the reviewer's name.

<Frame caption="Correcting an Evaluator result in the Traces review screen.">
  <img src="https://mintcdn.com/orqai/nflqfhu6mcOarrbT/images/evaluation-correction.gif?s=f5ab855dba2c6ea6987aac1f296bf368" alt="Evaluators panel listing agent_jailbreak_detection and agent_response_relevance, both marked No, showing the pencil icon used to open the correction popover." width="468" height="588" data-path="images/evaluation-correction.gif" />
</Frame>

Corrections are written back to the Trace like any other annotation. This gives a basis to compare an Evaluator's own results against reviewer corrections over time, using that signal (for example through the [**Orq MCP**](/ai-studio/integrations/code-assistants/orq-mcp)) to see where an Evaluator's configuration may need adjustment.

<Info>
  This corrects the Evaluator's *result*, not the AI response text. For rewriting the response itself, use the Logs [**Add a Text Correction**](/ai-studio/observability/annotations#use-annotations) flow.
</Info>

<Info>
  See [Correct an Evaluator Result](/ai-studio/observability/annotations#use-annotations) in the API & SDK tab for the API/SDK equivalent.
</Info>

## Threads

<Card title="Threads" icon="messages" href="/ai-studio/observability/threads">
  Visualize conversation history as Threads to follow the full sequence of messages across an agent session.
</Card>

## Reference

<Card title="Token and Cost Tracking" icon="coins" href="/ai-studio/observability/token-cost-tracking">
  How token usage is captured and cost is calculated per LLM request.
</Card>

<Card title="Span Attributes" icon="tag" href="/ai-studio/observability/span-attributes">
  Complete reference for all `orq.*` span attributes emitted on traces, webhook payloads, and trace exports.
</Card>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.