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

# Traceloop Integration

> Wraps an agent run in a Traceloop @workflow-decorated function so the run appears under a parent workflow span.

Demonstrates wrapping Agno calls in Traceloop workflow spans.

```python traceloop_op.py theme={null}
"""
Traceloop Integration
=====================

Demonstrates wrapping Agno calls in Traceloop workflow spans.
"""

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from traceloop.sdk import Traceloop
from traceloop.sdk.decorators import workflow

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
Traceloop.init(app_name="agno_workflows")


# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
    name="AnalysisAgent",
    model=OpenAIChat(id="gpt-5.2"),
    debug_mode=True,
)


@workflow(name="data_analysis_pipeline")
def analyze_data(query: str) -> str:
    """Custom workflow that wraps agent execution."""
    response = agent.run(query)
    return response.content


# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    # The workflow decorator creates a parent span
    result = analyze_data("Analyze the benefits of observability in AI systems")
    print(result)
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno openai traceloop-sdk
    ```
  </Step>

  <Step title="Export your API keys">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export OPENAI_API_KEY="your_openai_api_key_here"
      export TRACELOOP_API_KEY="your_traceloop_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      $Env:TRACELOOP_API_KEY="your_traceloop_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the example">
    Save the code above as `traceloop_op.py`, then run:

    ```bash theme={null}
    python traceloop_op.py
    ```
  </Step>
</Steps>

Full source: [cookbook/observability/traceloop\_op.py](https://github.com/agno-agi/agno/blob/main/cookbook/observability/traceloop_op.py)
