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

# Graphsignal 集成

> 使用 LangChain Python 集成 Graphsignal。

本页面介绍了如何使用 [Graphsignal](https://app.graphsignal.com) 来追踪和监控 LangChain。Graphsignal 可以为您的应用程序提供全面的可见性。它提供按链和工具的延迟分解、带完整上下文的异常、数据监控、计算/GPU 利用率、OpenAI 成本分析等功能。

## 安装和设置

* 使用 `pip install graphsignal` 安装 Python 库
* 创建一个免费的 [Graphsignal 账户](https://graphsignal.com)
* 获取 API 密钥并将其设置为环境变量（`GRAPHSIGNAL_API_KEY`）

## 追踪和监控

Graphsignal 会自动对链进行instrumentation并开始追踪和监控。追踪和指标随后可在您的 [Graphsignal 仪表板](https://app.graphsignal.com) 中查看。

通过提供部署名称来初始化追踪器：

```python theme={null}
import graphsignal

graphsignal.configure(deployment='my-langchain-app-prod')
```

要额外追踪任何函数或代码，您可以使用装饰器或上下文管理器：

```python theme={null}
@graphsignal.trace_function
def handle_request():
    chain.run("some initial text")
```

```python theme={null}
with graphsignal.start_trace('my-chain'):
    chain.run("some initial text")
```

可选地，启用分析功能以记录每个追踪的函数级统计信息。

```python theme={null}
with graphsignal.start_trace(
        'my-chain', options=graphsignal.TraceOptions(enable_profiling=True)):
    chain.run("some initial text")
```

请参阅 [快速入门](https://graphsignal.com/docs/guides/quick-start/) 指南以获取完整的设置说明。

***

> 官方原文：[src/oss/python/integrations/providers/graphsignal.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/python/integrations/providers/graphsignal.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


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