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

# Langtrace Integration

> Auto-instrument a YFinance stock-price agent with langtrace.init() from the Langtrace Python SDK.

Demonstrates instrumenting an Agno agent with Langtrace.

> [!WARNING]
>
> This example initializes Langtrace after importing Agno model modules, so automatic instrumentation may not attach. Create a Langtrace project and generate an API key before running the example. See [Langtrace Python SDK setup](https://github.com/Scale3-Labs/langtrace-python-sdk#quick-start).

```python langtrace_op.py theme={null}
"""
Langtrace Integration
=====================

Demonstrates instrumenting an Agno agent with Langtrace.
"""

# Must precede other imports
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools
from langtrace_python_sdk import langtrace  # type: ignore

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
langtrace.init()


# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
    name="Stock Price Agent",
    model=OpenAIChat(id="gpt-5.2"),
    tools=[YFinanceTools()],
    instructions="You are a stock price agent. Answer questions in the style of a stock analyst.",
)


# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    agent.print_response("What is the current price of Tesla?")
```

## Run the Example

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

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno langtrace-python-sdk openai yfinance
```

**2. Export your Langtrace and OpenAI API keys**

```bash Mac/Linux theme={null}
export LANGTRACE_API_KEY="your_langtrace_api_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:LANGTRACE_API_KEY="your_langtrace_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**3. Save and fix the initialization order**

Save the code above as `langtrace_op.py`, then move the `langtrace_python_sdk` import and `langtrace.init()` before every Agno and OpenAI import.

**4. Run the example**

Run the corrected file:

```bash theme={null}
python langtrace_op.py
```

Full source: [cookbook/observability/langtrace\_op.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/observability/langtrace_op.py)


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