Claude Code 是迄今为止最令人印象深刻和实用的 AI 编码工具之一。Claude Code 会发出事件以进行监控和可观测性。LangSmith 可以收集并显示这些事件,为您提供 Claude Code 在后台运行的完整详细日志。
快速入门
您可以通过在运行 Claude Code 的环境中设置以下环境变量,将 LangSmith 追踪与 Claude Code 集成。
# Enables Claude Code to emit OTEL events
export CLAUDE_CODE_ENABLE_TELEMETRY=1
# Sets the output format to use Open Telemetry Protocol
export OTEL_LOGS_EXPORTER=otlp
# LangSmith ingests JSON format events
export OTEL_EXPORTER_OTLP_LOGS_PROTOCOL=http/json
# Claude Code Logs are translated to Spans by LangSmith
export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://api.smith.langchain.com/otel/v1/claude_code
# Pass your API key and desired tracing project through headers
export OTEL_EXPORTER_OTLP_HEADERS="x-api-key=<api-key>,Langsmith-Project=<project-name>"
# Set this to true in order to log the input user prompts
export OTEL_LOG_USER_PROMPTS=1
# Once these are set, start Claude Code, and events will be traced to LangSmith
claude
Claude Code 发出 开放遥测标准事件 用于监控使用情况,但这不包括发送给 LLM 的实际提示和消息。
如果您是自托管 LangSmith,请将基本端点替换为您的 LangSmith API 端点,并添加 /api/v1。例如:OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://ai-company.com/api/v1/otel/v1/claude_code