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

> 集成 Agno 和 Langtrace 以发送跟踪信息并深入了解您的代理性能。

## 集成 Agno 和 Langtrace

Langtrace 提供了一个强大的平台来跟踪和监控 AI 模型调用。通过将 Agno 与 Langtrace 集成，您可以深入了解代理的性能和行为。

## 先决条件

1. **安装依赖项**

   确保已安装必要的包：

   ```bash theme={null}
   pip install langtrace-python-sdk
   ```

2. **创建 Langtrace 账户**

   * 在 [Langtrace](https://app.langtrace.ai/) 注册一个账户。
   * 从 Langtrace 仪表板获取您的 API 密钥。

3. **设置环境变量**

   使用 Langtrace API 密钥配置您的环境：

   ```bash theme={null}
   export LANGTRACE_API_KEY=<your-key>
   ```

## 将跟踪信息发送到 Langtrace

此示例演示了如何为 Agno 代理添加 Langtrace 的仪器。

```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?")
```

## 注意事项

* **环境变量**: 确保您的环境变量已正确设置 API 密钥。
* **初始化**: 在使用代理之前，请调用 `langtrace.init()` 来初始化 Langtrace。

通过遵循这些步骤，您可以有效地将 Agno 与 Langtrace 集成，从而实现对 AI 代理的全面可观察性和监控。
