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

# 将 LangSmith 遥测数据导出至您的可观测性后端

<Warning>
  **本节仅适用于 Kubernetes 部署。**
</Warning>

自托管 LangSmith 实例会生成日志、指标和追踪形式的遥测数据。本节将展示如何访问这些数据并将其导出至可观测性收集器或后端。

本节假设您已设置监控基础设施，或者您将设置此基础设施并希望了解如何配置 LangSmith 以从中收集数据。

基础设施包括：

* 收集器，例如 [OpenTelemetry](https://opentelemetry.io/docs/collector/)、[FluentBit](https://docs.fluentbit.io/manual) 或 [Prometheus](https://prometheus.io/)。
* 可观测性后端，例如 [Datadog](https://www.datadoghq.com/) 或 [Grafana](https://grafana.com/) 生态系统。

# 日志：[OTel 示例](/langsmith/langsmith-collector#logs)

LangSmith 自托管部署中的所有服务都会将日志写入其节点文件系统和标准输出。要访问这些日志，您需要设置收集器以从文件系统或标准输出读取。大多数流行的收集器都支持从文件系统读取日志。

* **OpenTelemetry**：[文件日志接收器](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/filelogreceiver)
* **FluentBit**：[尾部输入](https://docs.fluentbit.io/manual/pipeline/inputs/tail)
* **Datadog**：[Kubernetes 日志收集](https://docs.datadoghq.com/containers/kubernetes/log/?tab=datadogoperator)

# 指标：[OTel 示例](/langsmith/langsmith-collector#metrics)

## LangSmith 服务

以下 LangSmith 服务在端点以 Prometheus 指标格式公开指标。前端目前不公开指标。

* **后端**：`http://<langsmith_release_name>-backend.<namespace>.svc.cluster.local:1984/metrics`
* **平台后端**：`http://<langsmith_release_name>-platform-backend.<namespace>.svc.cluster.local:1986/metrics`
* **Playground**：`http://<langsmith_release_name>-playground.<namespace>.svc.cluster.local:1988/metrics`
* **（仅限 LangSmith 控制平面）主机后端**：`http://<langsmith_release_name>-host-backend.<namespace>.svc.cluster.local:1985/metrics`

您可以使用 [Prometheus](https://prometheus.io/docs/prometheus/latest/getting_started/#configure-prometheus-to-monitor-the-sample-targets) 或 [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/prometheusreceiver) 收集器来抓取这些端点，并将指标导出到您选择的后端。

## 前端 Nginx

前端服务在以下端点公开其 Nginx 指标：`langsmith-frontend.langsmith.svc.cluster.local:80/nginx_status`。您可以自行抓取这些指标，或者启动一个 [Prometheus Nginx 导出器](https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-nginx-exporter)。

<Warning>
  **以下部分仅适用于集群内数据库。如果您使用外部数据库，则需要配置指标的公开和获取。**
</Warning>

## Postgres + Redis

如果您使用集群内的 Postgres/Redis 实例，可以使用 Prometheus 导出器从您的实例公开指标。您可以部署 [Postgres 导出器](https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-postgres-exporter) 和/或 [Redis 导出器](https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-redis-exporter)。

## Clickhouse

集群内的 Clickhouse 已配置为无需导出器即可公开指标。您可以使用收集器在 `http://<langsmith_release_name>-clickhouse.<namespace>.svc.cluster.local:9363/metrics` 抓取指标。

# 追踪：[OTel 示例](/langsmith/langsmith-collector#traces)

LangSmith 后端、平台后端、Playground 和 LangSmith 队列部署已进行插桩以发出 [Otel](https://opentelemetry.io/do/langsmith/observability-concepts/signals/traces/) 追踪。追踪功能默认关闭，可以通过在您的 `langsmith_config.yaml`（或等效文件）中添加以下配置为所有 LangSmith 服务启用：

```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
config:
  tracing:
    enabled: true
    endpoint: "<your_collector_endpoint>"
    useTls: true # / false
    env: "ls_self_hosted" # 此值将设置为您的跨度中的 "env" 属性
    exporter: "http" # 必须为 http 或 grpc
```

***

<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\export-backend.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>
