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

# Langtrace

## 概览

本示例演示如何使用 Langtrace 为 Agno 代理进行插桩，以实现追踪和监控。

## 代码

```python theme={null}
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools
from langtrace_python_sdk import langtrace
from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span

# 初始化 Langtrace
langtrace.init()

# 创建并配置代理
agent = Agent(
    name="Stock Price Agent",
    model=OpenAIChat(id="gpt-4o-mini"),
    tools=[YFinanceTools()],
    instructions="You are a stock price agent. Answer questions in the style of a stock analyst.",
    debug_mode=True,
)

# 使用代理
agent.print_response("What is the current price of Tesla?")
```

## 用法

<Steps>
  <Step title="安装依赖">
    ```bash theme={null}
    pip install agno openai langtrace-python-sdk
    ```
  </Step>

  <Step title="设置环境变量">
    ```bash theme={null}
    export LANGTRACE_API_KEY=<your-key>
    ```
  </Step>

  <Step title="运行代理">
    <CodeGroup>
      ```bash Mac theme={null}
      python cookbook/observability/langtrace_op.py
      ```

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

## 注意事项

* **初始化**: 在使用代理之前，请调用 `langtrace.init()` 来初始化 Langtrace。
