> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-codex-docs-audit-20260719-0149.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).
</Warning>

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

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

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

  <Step title="Export your Langtrace and OpenAI API keys">
    <CodeGroup>
      ```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"
      ```
    </CodeGroup>
  </Step>

  <Step title="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.
  </Step>

  <Step title="Run the example">
    Run the corrected file:

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

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