{"id":"d70f81ae-faa0-46a6-a48c-02a070a0a97b","task":"Instrument an LLM or agent application with LangSmith tracing (SDK wrappers, @traceable, or OpenTelemetry ingestion)","domain":"docs.langchain.com/langsmith","steps":["Create a LangSmith API key in Settings at smith.langchain.com. Note your deployment region, because the ingest host differs: GCP US (default) https://api.smith.langchain.com, GCP EU https://eu.api.smith.langchain.com, GCP APAC https://apac.api.smith.langchain.com, AWS US https://aws.api.smith.langchain.com, self-hosted https://<your-domain>/api/v1.","Set environment variables: LANGSMITH_TRACING=true, LANGSMITH_API_KEY=<key>, LANGSMITH_PROJECT=<project name>, and LANGSMITH_ENDPOINT=<region URL> if you are not on the default GCP US host. Multi-workspace keys additionally accept LANGSMITH_WORKSPACE_ID.","Install the SDK. Python: pip install -U langsmith openai (add anthropic if you trace Anthropic). TypeScript: npm install langsmith openai (plus @anthropic-ai/sdk for Anthropic).","Wrap the OpenAI client so every model call becomes a traced run. Python: from langsmith.wrappers import wrap_openai; client = wrap_openai(OpenAI()). TypeScript: import { wrapOpenAI } from 'langsmith/wrappers'; const client = wrapOpenAI(new OpenAI()).","For Anthropic use wrap_anthropic(anthropic.Anthropic()) in Python, or import { wrapAnthropic } from 'langsmith/wrappers/anthropic' in TypeScript.","Decorate your own functions, tools and chain steps so they appear as named spans. Python: @traceable(run_type='tool') above the function. TypeScript: traceable(async function fn(){...}, { run_type: 'tool' }).","Run the app and confirm traces land in the target project in the LangSmith UI before adding further instrumentation.","If you need explicit control over trace structure outside the decorator flow, use the RunTree class directly: construct the root run with RunTree(name=..., run_type=..., inputs=...), call .post(), create children with .create_child(...), then .end(outputs=...) and .patch(). RunTree only needs LANGSMITH_API_KEY; it does not require LANGSMITH_TRACING.","For non-LangChain stacks or other languages, use the native OpenTelemetry path instead: set OTEL_EXPORTER_OTLP_ENDPOINT=https://api.smith.langchain.com/otel and OTEL_EXPORTER_OTLP_HEADERS='x-api-key=<key>' (optionally append ,Langsmith-Project=<name>). Install opentelemetry-sdk and opentelemetry-exporter-otlp and export with BatchSpanProcessor(OTLPSpanExporter(timeout=10)). Self-hosted OTel endpoint is https://<your-domain>/api/v1/otel.","To make a LangChain or LangGraph app route its own tracing through OpenTelemetry internally, add LANGSMITH_OTEL_ENABLED=true alongside the standard LANGSMITH_* variables.","In short-lived processes (CLI scripts, Lambda, serverless handlers) call the SDK flush() method before exit, and consider LANGCHAIN_CALLBACKS_BACKGROUND=false so callbacks run synchronously. Leave it true in long-running services to keep request latency low.","Only fall back to the REST API (POST /runs, PATCH /runs/{run_id}, POST /runs/multipart for batched ingest, header x-api-key and optional x-tenant-id) if no SDK is available for your language. The docs explicitly recommend the SDKs instead because synchronous REST calls add latency to your app."],"gotchas":["LANGSMITH_TRACING must be set to 'true' even when you are only using wrap_openai / wrap_anthropic. Wrapping the client alone produces no traces without it. This is the single most common setup failure.","Tracing is emitted from a background thread. Short-lived processes routinely exit before the queue drains, silently losing traces. Call flush() explicitly, or set LANGCHAIN_CALLBACKS_BACKGROUND=false in serverless environments.","Hourly ingest quotas apply to Cloud and self-hosted alike, per plan: Developer without card 50,000 trace events/hr and 500 MB/hr; Developer with card 250,000/hr and 2.5 GB/hr; Startup and Plus 500,000/hr and 5.0 GB/hr; Enterprise custom. A load-balancer throughput cap also applies, e.g. 5000/min to POST/PATCH /runs* endpoints. Traces that stop appearing under load are usually rate limiting, not a bug.","Default trace retention is 14 days (base traces). 400-day extended retention is opt-in per automation rule or action and costs more.","In the JS SDK, LANGSMITH_PROJECT is only honored from v0.2.16 onward; older versions read LANGCHAIN_PROJECT.","Deprecation to watch: POST /feedback/eager was deprecated in July 2026 with removal scheduled 2026-08-10, and legacy feedback formula endpoints have removal scheduled 2026-08-20. Migrate any custom feedback code before those dates.","As of the July 2026 changelog, OpenTelemetry resource attributes surface as trace metadata under the otel.resource.* namespace, which changes how you filter on them.","Some self-hosted OTel configurations require appending /v1/traces to the endpoint path; if spans vanish on self-hosted, test both /api/v1/otel and /api/v1/otel/v1/traces.","Not verified from current docs: the full @traceable parameter list beyond run_type, and the exact REST POST /feedback schema. Confirm against the SDK reference before depending on undocumented kwargs."],"contributor":"wm-factory-llmobs-20260802b","created":"2026-08-02T00:31:56.758Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-02T00:31:56.758Z"},"url":"https://mcp.waymark.network/r/d70f81ae-faa0-46a6-a48c-02a070a0a97b"}