> ## 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

With **Traces**, dive into the workflow of each model generation and understand the inner workings of an LLM call on **orq.ai**.

Traces correspond to events within the generations. Events within a [Deployment](/docs/deployments/creating) can be various:

* [Evaluators](/docs/evaluators/overview) & [Guardrails](/docs/deployments/creating#evaluators-and-guardrails)

* Retrieval using [Knowledge Base](/docs/knowledge/overview)

  * [Embeddings](/docs/knowledge/overview#embedding-models)
  * [Chunking](/docs/knowledge/overview#datasource-and-chunking)

* [Caching](/docs/deployments/creating#cache)

* [Retries and Fallbacks](/docs/deployments/creating#primary-model-retries-and-fallback)

## Creating Traces

Traces are automatically generated when using Orq.ai 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="/docs/proxy/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}

  with Orq(api_key=os.getenv("ORQ_API_KEY")) as orq:
      doc = process_document("doc-123")
      context = fetch_relevant_context("user query")

      response = orq.deployments.invoke(
          key="summarizer",
          context={"environments": ["production"]},
          inputs={"text": doc["status"], "context": context}
      )

      formatted = format_response(response.choices[0].message.content, {"doc_id": "doc-123"})
  ```

  ```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}

  async def main():
      async with Orq(api_key=os.getenv("ORQ_API_KEY")) as orq:
          doc = await process_document("doc-123")
          context = await fetch_relevant_context("user query")

          response = await orq.deployments.invoke_async(
              key="summarizer",
              context={"environments": ["production"]},
              inputs={"text": doc["status"], "context": context}
          )

          formatted = await format_response(response.choices[0].message.content, {"doc_id": "doc-123"})

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

<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, head to the **AI Studio** and to the **Traces** section.

<Frame caption="Visualizing traces">
  <img src="https://mintcdn.com/orqai/RkJWWMPdjGkbJjB4/images/traces.png?fit=max&auto=format&n=RkJWWMPdjGkbJjB4&q=85&s=43da59dd5639d18886a85ef35ee8fa74" alt="Visualizing traces" width="1685" height="1180" data-path="images/traces.png" />
</Frame>

Explore traces for each action taken during a generation:

* The left column shows the list of Traces available.
* By selecting a trace, the middle column opens, showing the **hierarchy** of events shown in order of execution.
* By selecting a single trace, the right column opens, showing details for the specific step.

### 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.

    <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 **Human Reviews** directly on individual spans. Human Reviews defined in the project are available on all spans automatically. Learn more in [Human Review](/docs/projects/human-review).
    </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>

### Viewing Errors

Traces that encountered an error are marked with a red <Icon icon="circle-exclamation" color="red" /> **error** status badge in the list. Use the **Status** filter to scope the list to errors only and identify failing traces quickly.

<Frame caption="Traces list filtered to error status.">
  <img src="https://mintcdn.com/orqai/o4CxH4xK7MCteqsT/images/traces-errors.png?fit=max&auto=format&n=o4CxH4xK7MCteqsT&q=85&s=6f095b26f13fa639d57c18ef53ca40a4" alt="Traces list filtered to show only erroring traces, with red error badges on each row and a Status filter chip applied." width="1982" height="1278" 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 **Metadata** to narrow down failures to a particular environment or deployment.

### Filtering Traces

Click <Icon icon="filter" /> next to the search bar to open the filter menu. Select a category to expand a searchable list of values and check one or more to apply.

<Frame caption="Trace filter categories.">
  <img src="https://mintcdn.com/orqai/o4CxH4xK7MCteqsT/images/trace-filters.png?fit=max&auto=format&n=o4CxH4xK7MCteqsT&q=85&s=abbf754f0ccc3564f9f2ce2c205a10ab" alt="Trace filters" width="733" height="727" data-path="images/trace-filters.png" />
</Frame>

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

The following filter categories are available:

| Filter           | Description                                              |
| ---------------- | -------------------------------------------------------- |
| **Annotations**  | Filter by annotation labels applied to traces.           |
| **Evals**        | Filter by evaluator results attached to traces.          |
| **Identity**     | Filter by the identity that triggered the trace.         |
| **Metadata**     | Filter by metadata fields attached to traces.            |
| **Model**        | Filter by the model used in the trace.                   |
| **Name**         | Filter by trace name.                                    |
| **Project**      | Filter by the project the trace belongs to.              |
| **Provider**     | Filter by the model provider.                            |
| **Span ID**      | Filter by a specific span identifier.                    |
| **Status**       | Filter by the status of the trace (e.g. error, success). |
| **Thread ID**    | Filter by the thread the trace belongs to.               |
| **Total Cost**   | Filter by the total cost of the trace.                   |
| **Total Tokens** | Filter by the total token count of the trace.            |
| **Trace ID**     | Filter by a specific trace identifier.                   |

Multiple filters can be combined. To remove a filter, click <Icon icon="xmark" /> next to it in the filter bar.

### Configuring Column

Columns can be enabled and toggled to display more available data in the traces list.

<Frame caption="The above fields are displayable on the traces list.">
  <img src="https://mintcdn.com/orqai/RkJWWMPdjGkbJjB4/images/trace-columns.png?fit=max&auto=format&n=RkJWWMPdjGkbJjB4&q=85&s=617de8eca0ffe42a698f4623c21c99b1" alt="The above fields are displayable on the traces list." width="354" height="550" data-path="images/trace-columns.png" />
</Frame>

### Creating Custom Views

Save frequently used filter combinations as reusable views:

1. Set the desired filters
2. Click **All Rows** (top right)
3. Select **Create New View**
4. Enter a title for the view
5. Optionally check **Set view private** (default is shared with project members)
6. The filtered view is saved and accessible from the **All Rows** dropdown

<Tip>
  A custom view filtering for all <Icon icon="circle-exclamation" color="red" /> **Errors** is available by default.

  <Frame caption="Available views">
    <img src="https://mintcdn.com/orqai/o4CxH4xK7MCteqsT/images/traces-view-error.png?fit=max&auto=format&n=o4CxH4xK7MCteqsT&q=85&s=90bf888ec5da38c4e9d233673822c242" alt="Traces view dropdown showing a default Errors view alongside any custom saved views." width="403" height="297" data-path="images/traces-view-error.png" />
  </Frame>
</Tip>

## Threads

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