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.mjsto patchlangsmithat startup without code changes. - Manual instrumentation: Wrap
langsmithnamespaces explicitly using Braintrust’s wrapper functions.
- Auto-instrumentation
- Manual instrumentation
Initialize Braintrust, then run your app with Braintrust’s import hook to patch The auto-instrumentation example uses plain JavaScript so
langsmith at runtime. Requires langsmith v0.3.30 or later.1
Initialize Braintrust and call LangSmith
2
Run with the import hook
node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects. Compile your TypeScript to JavaScript and run the compiled file with the import hook, or run TypeScript directly with a TypeScript loader.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 outputsRunTreeoperations andClientAPI calls (createRun,updateRun,batchIngestRuns) as spans- Run type mapped to span type:
llmandembedding→ LLM spans,toolandretriever→ 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_tokenfromnew_tokenevents in run history- Model name and provider from
ls_model_nameandls_providermetadata 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.