Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Environment:Langchain ai Langchain LangSmith Tracing Config

From Leeroopedia
Knowledge Sources
Domains Infrastructure, Observability
Last Updated 2026-02-11 14:00 GMT

Overview

Environment variable configuration for LangSmith tracing and observability in LangChain applications.

Description

LangChain integrates with LangSmith for tracing, debugging, and monitoring LLM applications. Tracing is controlled via environment variables that are checked in the callback manager. The Makefile explicitly unsets these variables during test execution to prevent accidental trace collection.

Usage

Enable this configuration when you want production observability or debugging of LangChain chains. Tracing captures input/output, latency, token usage, and error data for every Runnable invocation. Explicitly disabled during unit tests.

System Requirements

Category Requirement Notes
Network HTTPS outbound to api.smith.langchain.com Or self-hosted LangSmith
SDK langsmith >= 0.3.45, < 1.0.0 Bundled with langchain-core

Dependencies

Python Packages

  • `langsmith` >= 0.3.45, < 1.0.0 (bundled as core dependency)

Credentials

For Tracing:

  • `LANGCHAIN_TRACING_V2`: Set to `"true"` to enable LangSmith tracing.
  • `LANGCHAIN_API_KEY` or `LANGSMITH_API_KEY`: LangSmith API key for authentication.
  • `LANGCHAIN_PROJECT`: Project name for organizing traces (optional).
  • `LANGSMITH_TRACING`: Alternative flag for enabling tracing.

Deprecated:

  • `LANGCHAIN_TRACING`: Legacy v1 tracing flag. Setting this raises an error directing users to v2.
  • `LANGCHAIN_HANDLER`: Legacy handler flag.

Security:

  • `LANGCHAIN_ENV`: Set to `"local_test"` to allow test hostnames in SSRF protection (development only).

Quick Install

# Enable tracing
export LANGCHAIN_TRACING_V2="true"
export LANGCHAIN_API_KEY="ls-..."
export LANGCHAIN_PROJECT="my-project"

Code Evidence

Tracing detection from `libs/core/langchain_core/callbacks/manager.py:91-93`:

tracing_v2_is_enabled = env_var_is_set("LANGCHAIN_TRACING_V2") or env_var_is_set(
    "LANGSMITH_TRACING"
)

Variables unset during tests from `libs/core/Makefile:14-18`:

test:
	LANGCHAIN_TRACING_V2="" LANGCHAIN_API_KEY="" LANGSMITH_API_KEY="" \
	LANGSMITH_TRACING="" LANGCHAIN_PROJECT="" \
	uv run --group test pytest ...

Env var utility from `libs/core/langchain_core/utils/env.py:9-23`:

def env_var_is_set(env_var: str) -> bool:
    return env_var in os.environ and os.environ[env_var] not in {
        "",
        "0",
        "false",
        "False",
    }

Common Errors

Error Message Cause Solution
`LangChainDeprecationWarning: LANGCHAIN_TRACING` Using legacy v1 tracing variable Switch to `LANGCHAIN_TRACING_V2="true"`
`ConnectionError` during tracing LangSmith endpoint unreachable Verify network access to api.smith.langchain.com
Traces not appearing Tracing env vars empty or set to "false"/"0" Ensure `LANGCHAIN_TRACING_V2="true"` (not "True" or "1")

Compatibility Notes

  • Test Isolation: All tracing variables are explicitly unset in Makefiles to prevent test runs from sending traces.
  • SSRF Protection: The `LANGCHAIN_ENV="local_test"` flag relaxes hostname validation for development.
  • Dual Flags: Both `LANGCHAIN_TRACING_V2` and `LANGSMITH_TRACING` enable tracing; either is sufficient.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment