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

# Integrate with LangSmith

### What is LangSmith

LangSmith is a platform for building production-grade LLM applications. It is used for developing, collaborating, testing, deploying, and monitoring LLM applications.

> [!NOTE]
>
> For more details, please refer to [LangSmith](https://www.langchain.com/langsmith).

### How to Configure LangSmith

#### 1. Register/Login to [LangSmith](https://www.langchain.com/langsmith)

#### 2. Create a Project

Create a project in LangSmith. After logging in, click **New Project** on the homepage to create your own project. The **project** will be used to associate with **applications** in Dify for data monitoring.

![Create a Project in LangSmith](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/monitoring/integrate-external-ops-tools/58e20105fcc0771ca2431e8e5dcc42d3.png)

Once created, you can view all created projects in the Projects section.

![View Created Projects in LangSmith](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/monitoring/integrate-external-ops-tools/642c0ff7edfdfe77fba43aa22cc3fa71.png)

#### 3. Create Project Credentials

Find the project settings **Settings** in the left sidebar.

![Project Settings](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/monitoring/integrate-external-ops-tools/c49a1fc769215193928ff0d880422f89.png)

Click **Create API Key** to create project credentials.

![Create a Project API Key](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/monitoring/integrate-external-ops-tools/7082286b0d12af4bc0c84d9a3acf8b1b.png)

Select **Personal Access Token** for subsequent API authentication.

![Create an API Key](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/monitoring/integrate-external-ops-tools/75a69bd4dd02f0ffc0313589ae12fb36.png)

Copy and save the created API key.

![Copy API Key](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/monitoring/integrate-external-ops-tools/723e96a13e8f722d6df714b11ffd0bb1.png)

#### 4. Integrate LangSmith with Dify

Configure LangSmith in the Dify application. Open the application you need to monitor, open **Monitoring** in the side menu, and select **Tracing app performance** on the page.

![Tracing App Performance](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/monitoring/integrate-external-ops-tools/b6c7e5d4c2ca2092d59465cca27bc69c.png)

After clicking **Config**, paste the **API Key** and **Project** into the configuration and save. The key must allow project reads and trace writes. **Endpoint** defaults to `https://api.smith.langchain.com`; a custom API endpoint must use HTTPS.

![Configure LangSmith](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/monitoring/integrate-external-ops-tools/93dfabcadb7b2ff597f54beb5e642124.png)

> [!NOTE]
>
> The configured project name needs to match the project set in LangSmith. If the project does not exist, LangSmith creates it when the first trace arrives, not when the configuration is saved.

Once successfully saved, you can view the monitoring status on the current page.

![View Configuration Status](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/monitoring/integrate-external-ops-tools/43369dc4de8f606c166fae2efab97d73.png)

### View Monitoring Data in LangSmith

Once configured, the debug or production data from applications within Dify can be monitored in LangSmith.

![Debugging Applications in Dify](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/monitoring/integrate-external-ops-tools/a1370fdbb79257cba31a565ac6764802.png)

When you switch to LangSmith, you can view detailed operation logs of Dify applications in the dashboard.

![Viewing Application Data in LangSmith](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/monitoring/integrate-external-ops-tools/2833b2ffa20927b5328e9624b065beea.png)

Detailed LLM operation logs through LangSmith will help you optimize the performance of your Dify application.

![Viewing Application Data in LangSmith](https://assets-docs.dify.ai/dify-enterprise-mintlify/en/guides/monitoring/integrate-external-ops-tools/beeb4ee50c80de8db7400c1f65727c8c.png)

> [!NOTE]
>
> After saving and enabling tracing, run the app again and check for a new trace in the monitoring service. Delivery is asynchronous; saving the configuration alone does not confirm that a trace has arrived.
>
> With both deployment switches off, the new Agent app type and workflows using the [new Agent node](https://enterprise-docs.dify.ai/en/3.14.x/use/nodes/agent.md#new-agent) still send ordinary traces, including available inputs and outputs, but omit the Agent's internal model and tool calls.
>
> To collect those calls, ask your deployment administrator to turn on both deployment switches in the Helm values: `OPS_AGENT_TRACE_ENABLED` and `DIFY_AGENT_APPLICATION_TRACING_ENABLED`. See [LLMOps Trace Delivery](https://enterprise-docs.dify.ai/en/3.14.x/deploy/advanced-configuration/environment-variables.md#llmops-trace-delivery) for details.
>
> Once both deployment switches are on, **Capture content** is off by default for these apps: inputs, outputs, and most metadata are removed, and error text is redacted across the whole workflow. Enable it to send that content. Legacy Agent apps and workflows using only classic Agent nodes retain ordinary tracing.

### Monitoring Data List

The tables below describe ordinary traces. When both deployment switches are on, traces from the new Agent app type and from workflows containing a new Agent node use a new UUIDv7 trace ID, with source and tracing-run IDs retained as `dify.source.id` and `dify.tracing.run_id` attributes. For the new Agent app type, spans named `Agent attempt 1`, `Agent attempt 2`, and so on, with the internal model and tool calls, replace the ordinary `llm` span when **Capture Agent internals** is on. These traces leave out the separate moderation, suggested-question, and naming records.

Dify exports a hierarchy of operations: a message contains an `llm` call, and a Chatflow message contains its workflow and node operations. Native token usage is reported on model calls only.

The root run ID is the workflow run ID in Workflow apps and the message ID in all other app types. Child run IDs are derived. A `parent_run_id` refers to the parent's exported run ID. When you call a Chatflow or Workflow app through the API with an `X-Trace-Id` header, the root run ID is derived as well, and the header's value is retained in metadata.

For Chatflow, the trace root is the `message`, with the user's query as input (or workflow inputs when the query is empty). Its `workflow` child retains the workflow inputs and outputs.

The detail lists below describe Dify's source records and metadata. Only the relevant, available values are exported; the raw records are not sent in full.

#### **Workflow/Chatflow Trace Information**

**Used to track workflows and chatflows**

<table>
  <thead>
    <tr>
      <th>Workflow</th>
      <th>LangSmith Chain</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>workflow\_run\_id (Workflow) / message\_id (Chatflow), without X-Trace-Id</td>
      <td>id (root run)</td>
    </tr>

    <tr>
      <td>user\_id</td>
      <td>extra.metadata.user\_id</td>
    </tr>

    <tr>
      <td>workflow (Workflow) / message (Chatflow)</td>
      <td>name</td>
    </tr>

    <tr>
      <td>start\_time</td>
      <td>start\_time</td>
    </tr>

    <tr>
      <td>end\_time</td>
      <td>end\_time</td>
    </tr>

    <tr>
      <td>Workflow inputs / Chatflow query (workflow inputs if empty)</td>
      <td>inputs</td>
    </tr>

    <tr>
      <td>outputs</td>
      <td>outputs</td>
    </tr>

    <tr>
      <td>Model token consumption (LLM calls)</td>
      <td>outputs.usage\_metadata</td>
    </tr>

    <tr>
      <td>metadata</td>
      <td>extra.metadata</td>
    </tr>

    <tr>
      <td>error</td>
      <td>error</td>
    </tr>

    <tr>
      <td>Session ID</td>
      <td>extra.metadata.session\_id</td>
    </tr>

    <tr>
      <td>Parent span (when present)</td>
      <td>parent\_run\_id</td>
    </tr>
  </tbody>
</table>

**Workflow Trace Info**

* workflow\_id - Unique identifier of the workflow
* conversation\_id - Conversation ID
* workflow\_run\_id - ID of the current run
* tenant\_id - Tenant ID
* elapsed\_time - Time taken for the current run
* status - Run status
* version - Workflow version
* total\_tokens - Total tokens used in the current run
* file\_list - List of processed files
* triggered\_from - Source that triggered the current run
* workflow\_run\_inputs - Input data for the current run
* workflow\_run\_outputs - Output data for the current run
* error - Errors encountered during the current run
* query - Query used during the run
* workflow\_app\_log\_id - Workflow application log ID
* message\_id - Associated message ID
* start\_time - Start time of the run
* end\_time - End time of the run
* workflow node executions - Information about workflow node executions
* Metadata
  * workflow\_id - Unique identifier of the workflow
  * conversation\_id - Conversation ID
  * workflow\_run\_id - ID of the current run
  * tenant\_id - Tenant ID
  * elapsed\_time - Time taken for the current run
  * status - Run status
  * version - Workflow version
  * total\_tokens - Total tokens used in the current run
  * file\_list - List of processed files
  * triggered\_from - Source that triggered the current run

#### **Message Trace Information**

**Used to track LLM-related conversations**

<table>
  <thead>
    <tr>
      <th>Chat</th>
      <th>LangSmith Chain / LLM</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>message\_id</td>
      <td>id (root run)</td>
    </tr>

    <tr>
      <td>end\_user\_session\_id</td>
      <td>extra.metadata.end\_user\_session\_id</td>
    </tr>

    <tr>
      <td>message</td>
      <td>name</td>
    </tr>

    <tr>
      <td>start\_time</td>
      <td>start\_time</td>
    </tr>

    <tr>
      <td>end\_time</td>
      <td>end\_time</td>
    </tr>

    <tr>
      <td>inputs</td>
      <td>inputs</td>
    </tr>

    <tr>
      <td>outputs</td>
      <td>outputs</td>
    </tr>

    <tr>
      <td>Model token consumption (LLM calls)</td>
      <td>outputs.usage\_metadata</td>
    </tr>

    <tr>
      <td>metadata</td>
      <td>extra.metadata</td>
    </tr>

    <tr>
      <td>error</td>
      <td>error</td>
    </tr>

    <tr>
      <td>Session ID</td>
      <td>extra.metadata.session\_id</td>
    </tr>
  </tbody>
</table>

**Message Trace Info**

* message\_id - Message ID
* message\_data - Message data
* end\_user\_session\_id - User session ID
* conversation\_model - Conversation mode
* message\_tokens - Number of tokens in the message
* answer\_tokens - Number of tokens in the answer
* total\_tokens - Total number of tokens in the message and answer
* error - Error information
* inputs - Input data
* outputs - Output data
* file\_list - List of processed files
* start\_time - Start time
* end\_time - End time
* conversation\_mode - Conversation mode
* Metadata
  * conversation\_id - Conversation ID
  * ls\_provider - Model provider
  * ls\_model\_name - Model ID
  * status - Message status
  * from\_end\_user\_id - ID of the sending user
  * from\_account\_id - ID of the sending account
  * agent\_based - Whether the message is agent-based
  * workflow\_run\_id - Workflow run ID
  * from\_source - Message source

#### **Moderation Trace Information**

**Used to track conversation moderation**

<table>
  <thead>
    <tr>
      <th>Moderation</th>
      <th>LangSmith Tool</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>user\_id</td>
      <td>extra.metadata.user\_id</td>
    </tr>

    <tr>
      <td>moderation</td>
      <td>name</td>
    </tr>

    <tr>
      <td>start\_time</td>
      <td>start\_time</td>
    </tr>

    <tr>
      <td>end\_time</td>
      <td>end\_time</td>
    </tr>

    <tr>
      <td>inputs</td>
      <td>inputs</td>
    </tr>

    <tr>
      <td>action, flagged</td>
      <td>outputs</td>
    </tr>

    <tr>
      <td>metadata</td>
      <td>extra.metadata</td>
    </tr>

    <tr>
      <td>message\_id</td>
      <td>parent\_run\_id</td>
    </tr>
  </tbody>
</table>

**Moderation Trace Info**

* message\_id - Message ID
* user\_id: User ID
* workflow\_app\_log\_id - Workflow application log ID
* inputs - Moderation input data
* message\_data - Message data
* flagged - Whether the content is flagged for attention
* action - Specific actions taken
* preset\_response - Preset response
* start\_time - Moderation start time
* end\_time - Moderation end time
* Metadata
  * message\_id - Message ID
  * action - Specific actions taken
  * preset\_response - Preset response

#### **Suggested Question Trace Information**

**Used to track suggested questions**

<table>
  <thead>
    <tr>
      <th>Suggested Question</th>
      <th>LangSmith Tool</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>user\_id</td>
      <td>extra.metadata.user\_id</td>
    </tr>

    <tr>
      <td>suggested\_question</td>
      <td>name</td>
    </tr>

    <tr>
      <td>start\_time</td>
      <td>start\_time</td>
    </tr>

    <tr>
      <td>end\_time</td>
      <td>end\_time</td>
    </tr>

    <tr>
      <td>inputs</td>
      <td>inputs</td>
    </tr>

    <tr>
      <td>suggested\_question</td>
      <td>outputs</td>
    </tr>

    <tr>
      <td>metadata</td>
      <td>extra.metadata</td>
    </tr>

    <tr>
      <td>message\_id</td>
      <td>parent\_run\_id</td>
    </tr>
  </tbody>
</table>

**Message Trace Info**

* message\_id - Message ID
* message\_data - Message data
* inputs - Input content
* outputs - Output content
* start\_time - Start time
* end\_time - End time
* total\_tokens - Number of tokens
* status - Message status
* error - Error information
* from\_account\_id - ID of the sending account
* agent\_based - Whether the message is agent-based
* from\_source - Message source
* model\_provider - Model provider
* model\_id - Model ID
* suggested\_question - Suggested question
* level - Status level
* status\_message - Status message
* Metadata
  * message\_id - Message ID
  * ls\_provider - Model provider
  * ls\_model\_name - Model ID
  * status - Message status
  * from\_end\_user\_id - ID of the sending user
  * from\_account\_id - ID of the sending account
  * workflow\_run\_id - Workflow run ID
  * from\_source - Message source

#### **Dataset Retrieval Trace Information**

**Used to track knowledge base retrieval**

<table>
  <thead>
    <tr>
      <th>Dataset Retrieval</th>
      <th>LangSmith Retriever</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>user\_id</td>
      <td>extra.metadata.user\_id</td>
    </tr>

    <tr>
      <td>dataset\_retrieval</td>
      <td>name</td>
    </tr>

    <tr>
      <td>start\_time</td>
      <td>start\_time</td>
    </tr>

    <tr>
      <td>end\_time</td>
      <td>end\_time</td>
    </tr>

    <tr>
      <td>inputs</td>
      <td>inputs</td>
    </tr>

    <tr>
      <td>documents</td>
      <td>outputs</td>
    </tr>

    <tr>
      <td>metadata</td>
      <td>extra.metadata</td>
    </tr>

    <tr>
      <td>message\_id</td>
      <td>parent\_run\_id</td>
    </tr>
  </tbody>
</table>

**Dataset Retrieval Trace Info**

* message\_id - Message ID
* inputs - Input content
* documents - Document data
* start\_time - Start time
* end\_time - End time
* message\_data - Message data
* Metadata
  * message\_id - Message ID
  * ls\_provider - Model provider
  * ls\_model\_name - Model ID
  * status - Message status
  * from\_end\_user\_id - ID of the sending user
  * from\_account\_id - ID of the sending account
  * agent\_based - Whether the message is agent-based
  * workflow\_run\_id - Workflow run ID
  * from\_source - Message source

#### **Tool Trace Information**

**Used to track tool invocation**

<table>
  <thead>
    <tr>
      <th>Tool</th>
      <th>LangSmith Tool</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>user\_id</td>
      <td>extra.metadata.user\_id</td>
    </tr>

    <tr>
      <td>tool\_name</td>
      <td>name</td>
    </tr>

    <tr>
      <td>start\_time</td>
      <td>start\_time</td>
    </tr>

    <tr>
      <td>end\_time</td>
      <td>end\_time</td>
    </tr>

    <tr>
      <td>tool\_inputs</td>
      <td>inputs</td>
    </tr>

    <tr>
      <td>tool\_outputs</td>
      <td>outputs</td>
    </tr>

    <tr>
      <td>metadata</td>
      <td>extra.metadata</td>
    </tr>

    <tr>
      <td>message\_id</td>
      <td>parent\_run\_id</td>
    </tr>
  </tbody>
</table>

#### **Tool Trace Info**

* message\_id - Message ID
* tool\_name - Tool name
* start\_time - Start time
* end\_time - End time
* tool\_inputs - Tool inputs
* tool\_outputs - Tool outputs
* message\_data - Message data
* error - Error information, if any
* inputs - Inputs for the message
* outputs - Outputs of the message
* tool\_config - Tool configuration
* time\_cost - Time cost
* tool\_parameters - Tool parameters
* file\_url - URL of the associated file
* Metadata
  * message\_id - Message ID
  * tool\_name - Tool name
  * tool\_inputs - Tool inputs
  * tool\_outputs - Tool outputs
  * tool\_config - Tool configuration
  * time\_cost - Time cost
  * error - Error information, if any
  * tool\_parameters - Tool parameters
  * message\_file\_id - Message file ID
  * created\_by\_role - Role of the creator
  * created\_user\_id - User ID of the creator

**Generate Name Trace Information**

**Used to track conversation title generation**

<table>
  <thead>
    <tr>
      <th>Generate Name</th>
      <th>LangSmith Tool</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>user\_id</td>
      <td>extra.metadata.user\_id</td>
    </tr>

    <tr>
      <td>generate\_name</td>
      <td>name</td>
    </tr>

    <tr>
      <td>start\_time</td>
      <td>start\_time</td>
    </tr>

    <tr>
      <td>end\_time</td>
      <td>end\_time</td>
    </tr>

    <tr>
      <td>inputs</td>
      <td>inputs</td>
    </tr>

    <tr>
      <td>outputs</td>
      <td>outputs</td>
    </tr>

    <tr>
      <td>metadata</td>
      <td>extra.metadata</td>
    </tr>
  </tbody>
</table>

**Generate Name Trace Info**

* conversation\_id - Conversation ID
* inputs - Input data
* outputs - Generated conversation name
* start\_time - Start time
* end\_time - End time
* tenant\_id - Tenant ID
* Metadata
  * conversation\_id - Conversation ID
  * tenant\_id - Tenant ID


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