Quick Start
1
Simple Usage
2
With Configuration
How It Works
Spans are posted to LangSmith as runs, asynchronously, while your agent keeps working.Configuration Options
Secrets are read from the environment only and never logged; programmatic values override the env.When self-hosting over
http://, use localhost, 127.0.0.1, or ::1 — the adapter refuses non-loopback plaintext endpoints so the API key cannot leak on the wire.When does delivery happen?
Spans are posted asynchronously; your agent’s hot path never waits for LangSmith. Callawait obs.flush() before the process exits (e.g. in a serverless handler) to drain the queue. If a request fails, flush() warns how many runs did not reach LangSmith — the key, endpoint and network are not silently swallowed.
Common Patterns
Multiple agents sharing one trace keep their tree in LangSmith viaparent_run_id.
flush() warns nothing was delivered.
Best Practices
Set LANGSMITH_API_KEY once per process
Set LANGSMITH_API_KEY once per process
Prefer the environment variable over the programmatic
apiKey so the key stays out of source control. The env key is read on initialize().Always await obs.flush() before exiting
Always await obs.flush() before exiting
Delivery is async. In short-lived processes (scripts, serverless handlers) call
await obs.flush() so queued runs reach LangSmith before the process ends.Keep LANGSMITH_ENDPOINT on https://
Keep LANGSMITH_ENDPOINT on https://
The API key travels as
x-api-key. Plaintext http:// is refused for non-loopback hosts; use https:// unless the endpoint is localhost.Use LANGSMITH_PROJECT per environment
Use LANGSMITH_PROJECT per environment
Set a different
LANGSMITH_PROJECT for dev, staging, and prod so traces land in separate LangSmith sessions.Related
LangSmith CLI
CLI commands
Observability
Overview and delivery matrix

