跳到主要内容
此 Helm 存储库包含用于生成 LangSmith UI 当前不支持直接输出的查询(例如,在单个查询中获取多个组织的跟踪计数)。 此命令接受一个包含嵌入式名称和密码的 postgres 连接字符串(可以从对 secrets manager 的调用中传入),并从输入文件执行查询。在下面的示例中,我们使用 `support_queries/postgres` 目录中的 `pg_get_trace_counts_daily.sql` 输入文件。

先决条件

请确保您已准备好以下工具/项目。
  1. kubectl
  2. PostgreSQL 客户端
  3. PostgreSQL 数据库连接
    • 主机
    • 端口
    • 用户名
      • 如果使用捆绑版本,这是 `postgres`
    • 密码
      • 如果使用捆绑版本,这是 `postgres`
    • 数据库名称
      • 如果使用捆绑版本,这是 `postgres`
  4. 您将运行迁移脚本的机器到 PostgreSQL 数据库的连接。
    • 如果您正在使用捆绑版本,您可能需要将 postgresql 服务端口转发到您的本地机器。
    • 运行 `kubectl port-forward svc/langsmith-postgres 5432:5432` 将 postgresql 服务端口转发到您的本地机器。
  5. 运行支持查询的脚本
    • 您可以从此处下载该脚本

运行查询脚本

运行以下命令以运行所需的查询
sh run_support_query_pg.sh <postgres_url> --input path/to/query.sql
例如,如果您使用捆绑版本并进行端口转发,命令可能如下所示
sh run_support_query_pg.sh "postgres://postgres:postgres@localhost:5432/postgres" --input support_queries/pg_get_trace_counts_daily.sql
这将按工作区 ID 和组织 ID 输出每日跟踪计数。要将其提取到文件中,请添加 `--output path/to/file.csv` 标志。

导出使用数据

导出使用数据需要运行 Helm Chart 版本 0.11.4 或更高版本。

获取客户信息

在运行导出脚本之前,您需要从 LangSmith API 中检索客户信息。此信息是导出脚本所需的输入。
curl https://<langsmith_url>/api/v1/info
# if configured with a subdomain / path prefix:
curl http://<langsmith_url/prefix/api/v1/info
这将返回包含您的客户信息的 JSON 响应。
{
  "version": "0.11.4",
  "license_expiration_time": "2026-08-18T19:14:34Z",
  "customer_info": {
    "customer_id": "<id>",
    "customer_name": "<name>"
  }
}
从此响应中提取 `customer_id` 和 `customer_name` 作为导出脚本的输入。

使用 jq 处理 API 响应

您可以使用 jq 来解析 JSON 响应并设置 bash 变量以供脚本使用
# Get the API response and extract customer information
export LANGSMITH_URL="<your_langsmith_url>"
response=$(curl -s $LANGSMITH_URL/api/v1/info)

# Extract customer_id and customer_name using jq
export CUSTOMER_ID=$(echo "$response" | jq -r '.customer_info.customer_id')
export CUSTOMER_NAME=$(echo "$response" | jq -r '.customer_info.customer_name')

# Verify the variables are set
echo "Customer ID: $CUSTOMER_ID"
echo "Customer Name: $CUSTOMER_NAME"
然后,您可以在导出脚本或其他命令中使用这些环境变量。 如果您没有 `jq`,请运行以下命令根据 curl 输出设置环境变量:
curl -s $LANGSMITH_URL/api/v1/info
export CUSTOMER_ID="<id>"
export CUSTOMER_NAME="<name>"

初始导出

这些脚本将使用数据导出到 CSV 文件,以便报告给 LangChain。它们还通过分配回填 ID 和时间戳来跟踪导出。 要导出 LangSmith 跟踪使用情况:
# Get customer information from the API
export LANGSMITH_URL="<your_langsmith_url>"
export response=$(curl -s $LANGSMITH_URL/api/v1/info)
export CUSTOMER_ID=$(echo "$response" | jq -r '.customer_info.customer_id') && echo "Customer ID: $CUSTOMER_ID"
export CUSTOMER_NAME=$(echo "$response" | jq -r '.customer_info.customer_name') && echo "Customer name: $CUSTOMER_NAME"

# Run the export script with customer information as variables
sh run_support_query_pg.sh <postgres_url> \
  --input support_queries/postgres/pg_usage_traces_backfill_export.sql \
  --output ls_export.csv \
  -v customer_id=$CUSTOMER_ID \
  -v customer_name=$CUSTOMER_NAME
导出 LangSmith 使用情况
sh run_support_query_pg.sh <postgres_url> \
  --input support_queries/postgres/pg_usage_nodes_backfill_export.sql \
  --output lgp_export.csv \
  -v customer_id=$CUSTOMER_ID \
  -v customer_name=$CUSTOMER_NAME

状态更新

这些脚本更新安装中使用事件的状态,以反映这些事件已由 LangChain 成功处理。 这些脚本需要传入相应的 `backfill_id`,这将由您的 LangChain 代表确认。 要更新 LangSmith 跟踪使用情况:
sh run_support_query_pg.sh <postgres_url> --input support_queries/postgres/pg_usage_traces_backfill_update.sql --output export.csv -v backfill_id=<backfill_id>
更新 LangSmith 使用情况
sh run_support_query_pg.sh <postgres_url> --input support_queries/postgres/pg_usage_nodes_backfill_update.sql --output export.csv -v backfill_id=<backfill_id>

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.