LangSmith — tracing not appearing in the dashboard
LangSmith is Anthropic's (LangChain's) tracing and evaluation platform. Traces should appear automatically when environment variables are set — when they do not, the debugging experience gets ugly fast.
Quick fix (TL;DR)
LANGCHAIN_TRACING_V2=true, LANGCHAIN_API_KEY, LANGCHAIN_PROJECT (optional), LANGCHAIN_ENDPOINT (for self-hosted). Fix missing traces by (a) verifying env vars at process start, (b) checking the target project exists and the API key has access, (c) forcing a flush with tracing_v2_enabled() context or client.flush(), and (d) for self-hosted, ensuring the endpoint is reachable and TLS certs valid.Real error messages you'll see
These are the exact strings returned by the LangChain framework and its integrations when this error occurs. Copy-paste-searching any of them should land on this page.
os.environ["LANGCHAIN_TRACING_V2"] = "true" os.environ["LANGCHAIN_API_KEY"] = "ls_..." # But dashboard shows nothing — env vars were set AFTER LangChain import
# You expect traces in "prod-eu-west1" project # But they show up in "default" — LANGCHAIN_PROJECT not set
langsmith.utils.LangSmithConnectionError: HTTPConnectionPool(host='langsmith.internal', port=443): Max retries exceeded... — check LANGCHAIN_ENDPOINT
Reference
LangSmith environment variables
| Variable | Value | Notes |
|---|---|---|
LANGCHAIN_TRACING_V2 | true or 1 | Master switch |
LANGCHAIN_API_KEY | API key from LangSmith | Required for cloud |
LANGCHAIN_PROJECT | Project name (string) | Defaults to "default" if unset |
LANGCHAIN_ENDPOINT | URL | Cloud: default; Self-hosted: your URL |
LANGCHAIN_TRACING_SAMPLING_RATE | 0.0 - 1.0 | For high-volume: sample |
LANGCHAIN_CALLBACKS_BACKGROUND | true/false | Set false to flush synchronously |
Root causes, ranked by frequency
Based on developer reports across LangChain forums, GitHub issues, and Discord community during 2025–2026.
- 26%Env vars set after LangChain import. Env vars must be set before
import langchain_*, not after. - 18%LANGCHAIN_PROJECT not set — traces land in "default". Team looks in prod project, sees nothing.
- 14%API key wrong workspace. Key from workspace A, target project in workspace B.
- 10%Async traces not flushed before process exit. Serverless / short-lived process exits before background upload completes.
- 8%Self-hosted endpoint unreachable. VPC / firewall blocking outbound to internal LangSmith URL.
- 7%Sampling rate accidentally 0. Set to 0.0 during load-test; forgot to reset.
- 7%Callbacks disabled at model level. Chain passed
callbacks=[]explicitly. - 10%Project quota exceeded. Free tier hit monthly limit; traces dropped silently.
Fixes — copy-paste solutions
Set env vars before any LangChain import
LangChain reads tracing config at module import time. Setting env vars in Python code after import langchain_openai is too late. Set them in your shell, .env, or systemd unit file — before Python starts.
# In .env or shell (BEFORE running Python) export LANGCHAIN_TRACING_V2=true export LANGCHAIN_API_KEY=ls_your_key_here export LANGCHAIN_PROJECT=myapp-prod # Self-hosted only: # export LANGCHAIN_ENDPOINT=https://langsmith.internal.example.com # Verify from shell before running Python env | grep LANGCHAIN
# In Python — load .env BEFORE importing langchain from dotenv import load_dotenv load_dotenv() # this must happen FIRST # ONLY THEN import LangChain from langchain_openai import ChatOpenAI from langchain_core.prompts import ChatPromptTemplate # Verify at runtime import os assert os.environ.get("LANGCHAIN_TRACING_V2") == "true", "Tracing not enabled" assert os.environ.get("LANGCHAIN_API_KEY"), "API key not set" print(f"Tracing to project: {os.environ.get('LANGCHAIN_PROJECT', 'default')}") # For docker/systemd, set them in the environment section of the unit # For k8s, use envFrom + a Secret
os.environ[]= often has no effect.Route traces to the correct project explicitly
Set LANGCHAIN_PROJECT per environment. Use tracing_v2_enabled() or callback-level project overrides for per-request routing.
from langchain_core.tracers.context import tracing_v2_enabled from langchain_openai import ChatOpenAI llm = ChatOpenAI(model="gpt-4o-mini") # Default project: whatever LANGCHAIN_PROJECT is set to result = llm.invoke("hello") # Per-block override — route these traces to a specific project with tracing_v2_enabled(project_name="experiments-quality"): result = llm.invoke("hello") # Per-invoke override via config result = llm.invoke("hello", config={"run_name": "smoke-test", "tags": ["smoke", "prod"], "metadata": {"user_id": "u_123"}}) # Environment-based projects import os os.environ["LANGCHAIN_PROJECT"] = { "development": "myapp-dev", "staging": "myapp-staging", "production": "myapp-prod", }[os.environ.get("APP_ENV", "development")] # For agents / chains, tag runs to make filtering easy in LangSmith UI from langchain.agents import AgentExecutor executor.invoke( {"input": "..."}, config={ "tags": ["agent-v2", os.environ.get("APP_ENV")], "metadata": {"user_id": "u_123", "conversation_id": "c_456"}, }, )
tags and metadata on the config are gold in the LangSmith UI — filter and dashboard on these to slice traces by user, cohort, or app version.Flush traces before short-lived processes exit
Background flushing is the default. For serverless functions, cron jobs, or CLI tools, force a synchronous flush before exit so all traces are uploaded.
# Option A: force synchronous callbacks import os os.environ["LANGCHAIN_CALLBACKS_BACKGROUND"] = "false" # every trace flushed immediately # Option B: explicit flush before exit (recommended for serverless) from langsmith import Client def flush_traces(): try: client = Client() client.flush() # blocks until pending traces upload except Exception as e: print(f"LangSmith flush failed: {e}") # For AWS Lambda handler def lambda_handler(event, context): try: response = my_langchain_chain.invoke(event) return {"statusCode": 200, "body": response} finally: flush_traces() # ensure traces upload before Lambda freezes the container # For CLI tools with atexit import atexit atexit.register(flush_traces) # For long-running services (FastAPI, Django) — do NOT force sync # The background sender is fine and adds no latency to your requests
finally blocks is the safe pattern.Prevention checklist
Ship these seven safeguards once and this error stops appearing in your logs.
- Set
LANGCHAIN_TRACING_V2,LANGCHAIN_API_KEY, andLANGCHAIN_PROJECTin the environment, not in Python code after imports. - Use per-environment project names (myapp-dev, myapp-staging, myapp-prod).
- Tag every agent run with app version, environment, and user context.
- For serverless, explicitly flush before exit (
client.flush()or atexit). - For self-hosted, verify the endpoint is reachable from your compute environment.
- Monitor LangSmith ingestion rate for drops — silent quota exhaustion happens.
- Version-pin
langsmithSDK alongside your LangChain packages.
Frequently asked questions
LANGCHAIN_CALLBACKS_BACKGROUND=false, every LLM call blocks briefly on the trace upload, which can add 5-50ms per call.@traceable decorator that works with any Python function. You can trace pure OpenAI SDK calls, custom logic, and any other AI framework by wrapping the entry points.LANGCHAIN_TRACING_SAMPLING_RATE to a fraction (0.0-1.0). Or wrap specific calls in tracing_v2_enabled() / with_config(callbacks=[]) to explicitly include/exclude.Related errors & hubs
Get the weekly AI-error digest
New fixes, provider status recaps, and one deep tutorial — every Tuesday. 8,400+ engineers.