Skip to main content
LangSmith is LangChain’s platform for tracing, evaluation, and monitoring of LLM applications. Braintrust traces LangSmith applications from your code.

Setup

Install the packages, then set your API key and enable LangSmith tracing.
1

Install braintrust and langsmith

2

Set your API key and enable tracing

Braintrust intercepts LangSmith’s tracing pipeline, so LANGSMITH_TRACING=true must be set for langsmith to produce the runs that Braintrust captures. The legacy LANGCHAIN_TRACING_V2=true also works. To also send runs to LangSmith, set LANGSMITH_API_KEY.

Tracing

Braintrust supports two modes for intercepting LangSmith calls:
  • Auto-instrumentation (recommended): Run your app with node --import braintrust/hook.mjs to patch langsmith at startup without code changes.
  • Manual instrumentation: Wrap langsmith namespaces explicitly using Braintrust’s wrapper functions.
Initialize Braintrust, then run your app with Braintrust’s import hook to patch langsmith at runtime. Requires langsmith v0.3.30 or later.
1

Initialize Braintrust and call LangSmith

2

Run with the import hook

The auto-instrumentation example uses plain JavaScript so node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects — compile your TypeScript to JavaScript, then run the compiled file with the import hook.
If you’re using a bundler, see Trace LLM calls for plugin and loader setup.

What Braintrust traces

Braintrust captures:
  • traceable-wrapped function calls as spans, with inputs and outputs
  • RunTree operations and Client API calls (createRun, updateRun, batchIngestRuns) as spans
  • Run type mapped to span type: llm and embedding → LLM spans, tool and retriever → Tool spans, other run types → Task spans
  • Token usage (prompt_tokens, completion_tokens, total_tokens, prompt_cached_tokens, prompt_cache_creation_tokens)
  • time_to_first_token from new_token events in run history
  • Model name and provider from ls_model_name and ls_provider metadata fields
  • LLM settings (temperature, top_p, max_tokens, and related fields) from run metadata
  • Tags and errors
LangChain runs (identified by serialized.lc === 1) are skipped by default to avoid double-tracing when both LangChain and LangSmith instrumentation are active.

Resources