feat(tracing): integrate langsmith-go for LLM request tracing#612
feat(tracing): integrate langsmith-go for LLM request tracing#612anhle128 wants to merge 7 commits intonextlevelbuilder:mainfrom
Conversation
Implement LangSmith trace export integration: - exporter.go: Core LangSmith API client with batch run submission - mapping.go: Token count mapping (input/output → prompt/completion) Supports API URL configuration and per-project trace isolation.
Implement build-tag gated initialization: - gateway_langsmith.go: Initialize and wire LangSmith exporter (with -tags langsmith) - gateway_langsmith_noop.go: No-op stub for default builds Allows optional LangSmith integration without coupling to core gateway.
Config changes: - Add LangSmith struct with api_key, project, api_url fields - Load from LANGSMITH_* env vars with config file overlay - Mask API key in sensitive output Collector changes: - Add exporter management via AddExporter interface - Graceful shutdown of all exporters - Pre-initialized exporter list Initializes LangSmith exporter on gateway startup per config.
Buffer child "running" spans for deferred single-shot POST instead of two-phase POST+PATCH which fails LangSmith validation (RunUpdate lacks ParentRunID). Track run ID mappings via runMap for proper dotted_order hierarchy across batches. Remap root span IDs to TraceID to satisfy LangSmith's run_id == trace_id constraint. Closes nextlevelbuilder#611
🔍 Code Review — PR #612Nice work @anhle128! LangSmith integration cho LLM observability — feature mà team cần từ lâu. ✅ What's Good1. Kiến trúc sạch sẽ
2. LangSmith-specific constraints handled đúng
3. Background pruning
4. Config + env var support
5. Test plan chi tiết
|
Summary
Closes #611
Integrate langsmith-go SDK to export LLM call traces to LangSmith for AI-specific observability.
langsmithexport.ExporterimplementingSpanExporter+SpanUpdateExporterinterfacesllm,tool,chain) with properdotted_orderhierarchyparent_run_id)TraceIDto satisfy LangSmithrun_id == trace_idconstraintLangSmithConfigwith env var support (LANGSMITH_API_KEY,LANGSMITH_PROJECT,LANGSMITH_ENDPOINT)-tags langsmith) — zero dependency footprint on default buildsFiles changed
internal/tracing/langsmithexport/exporter.go,mapping.gointernal/config/config.go,config_load.go,config_secrets.gocmd/gateway_langsmith.go,cmd/gateway_langsmith_noop.gocmd/gateway.go,internal/tracing/collector.goConfiguration
Test plan
go build ./...— compiles, no langsmith-go dependencygo build -tags langsmith ./...— compiles and linksLANGSMITH_API_KEYand verify runs appear in LangSmith UIllmruns with model, tokens, costtoolruns with tool name and input/outputchainruns wrapping child runs