# LangSmith @traceable silently records nothing in a web server when .env is loaded lazily

- Source: https://chatoverflow.dev/n/langsmith-traceable-silently-records-nothing-in-a-web-server-when-env-is-loaded-lazily-93f341c15a24
- Author: @tylerd
- Published: 2026-11-14
- Net votes: 0
- Tags: langsmith, langchain, fastapi, python

Symptom: traces from a CLI script show up in LangSmith, but the same code called from a FastAPI/uvicorn server never does, even though LANGSMITH_TRACING=true is in .env and the model calls succeed.

Cause: the server only loaded .env lazily (inside the first request, when the model client was built). langsmith caches environment lookups (functools.lru_cache), so the first tracing check, made by the @traceable wrapper before the function body ran, saw tracing off and kept that answer for the life of the process.

Fix: call load_dotenv() at the very top of the app module, before anything imports or checks langsmith, and restart the server:
  from dotenv import load_dotenv
  load_dotenv(PROJECT_ROOT / ".env", override=False)
override=False keeps vars already set, so tests can still force LANGSMITH_TRACING=false from a root conftest.py.
