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

# 追踪 n8n 工作流

> 了解如何在 LangSmith 中追踪 n8n AI 工作流。

[n8n](https://n8n.io/) 是一个工作流自动化平台，包含基于 LangChain 构建的高级 AI 功能。您可以将 n8n 实例连接到 LangSmith，以记录和监控 AI 工作流的运行。

<Note>
  LangSmith 追踪功能仅适用于**自托管的 n8n 实例**。
</Note>

## 前提条件

* 一个 [LangSmith 账户](https://smith.langchain.com/) 和 [API 密钥](/langsmith/create-account-api-key)
* 一个自托管的 n8n 实例

## 设置追踪

1. 在托管 n8n 实例的环境中设置以下环境变量，设置方式与您的其他 [n8n 配置](https://docs.n8n.io/hosting/configuration/configuration-methods/) 相同。

   必需的环境变量：

   * `LANGCHAIN_TRACING_V2` — 设置为 `true` 以启用追踪。
   * `LANGCHAIN_API_KEY` — 您的 LangSmith API 密钥。

   可选的环境变量：

   * `LANGCHAIN_ENDPOINT` — LangSmith API 端点。默认为 `https://api.smith.langchain.com`。如果使用自托管的 LangSmith 实例或欧盟区域，请设置此变量。
   * `LANGCHAIN_PROJECT` — 追踪的项目名称。默认为 `"default"`。
   * `LANGCHAIN_CALLBACKS_BACKGROUND` — 设置为 `true` 进行异步追踪上传（默认），或 `false` 进行同步上传。（默认值：`true`）

2. 重启您的 n8n 实例以使环境变量生效。

## 在 LangSmith 中查看追踪

运行 AI 工作流后：

1. 打开 [LangSmith](https://smith.langchain.com/)。
2. 选择您的项目。如果您刚刚创建账户，在发送第一条追踪后会出现 `"default"` 项目。
3. 找到与您工作流执行对应的追踪记录。

## 其他资源

* [n8n LangSmith 集成指南](https://docs.n8n.io/advanced-ai/langchain/langsmith/)
* [n8n 高级 AI 文档](https://docs.n8n.io/advanced-ai/)

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\langsmith\trace-with-n8n.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
