本页面介绍如何使用 Graphsignal to trace and monitor LangChain. Graphsignal enables full visibility into your application. It provides latency breakdowns by chains and tools, exceptions with full context, data monitoring, compute/GPU utilization, OpenAI cost analytics, and more.
安装和设置
- - 使用以下方式安装 Python 库
pip install graphsignal - - 创建一个免费的 Graphsignal 账户
- - 获取 API 密钥并将其设置为环境变量 (
GRAPHSIGNAL_API_KEY)
追踪和监控
Graphsignal 自动检测并开始追踪和监控链。随后,追踪和指标可在您的 Graphsignal 仪表板.
通过提供部署名称来初始化追踪器:
graphsignal.configure(deployment='my-langchain-app-prod')
要额外追踪任何函数或代码,您可以使用装饰器或上下文管理器:
@graphsignal.trace_function
def handle_request():
chain.run("some initial text")
with graphsignal.start_trace('my-chain'):
chain.run("some initial text")
可选地,启用性能分析以记录每个追踪的函数级统计信息。
with graphsignal.start_trace(
'my-chain', options=graphsignal.TraceOptions(enable_profiling=True)):
chain.run("some initial text")
请参阅 快速入门 指南以获取完整的设置说明。