Skip to main content
If you’re using a popular AI framework like LangChain, LangGraph, or OpenTelemetry, Braintrust provides native integrations that automatically capture traces from your application.

When to use frameworks

Use framework integrations when:
  • You’re already using LangChain, LangGraph, or similar frameworks
  • You want automatic tracing without wrapping individual clients
  • Your application uses complex chains, agents, or multi-step workflows
Use AI provider wrappers when:
  • You’re making direct API calls without a framework
  • You want simpler, more lightweight instrumentation

LangChain

LangChain is a framework for building applications with language models. Braintrust integrates using callback handlers to automatically trace chains, agents, and LLM calls. See the LangChain integration guide for complete documentation.
1

Install packages

# pnpm
pnpm add braintrust @braintrust/langchain-js @langchain/core
# npm
npm install braintrust @braintrust/langchain-js @langchain/core
2

Add callback handler

Add the Braintrust callback handler to your LangChain application:
import { BraintrustCallbackHandler } from "@braintrust/langchain-js";
import { ChatOpenAI } from "@langchain/openai";
import { initLogger } from "braintrust";

initLogger({ projectName: "My Project" });

const handler = new BraintrustCallbackHandler();

async function main() {
  const model = new ChatOpenAI({ modelName: "gpt-4o" });

  // Pass the handler to capture traces
  await model.invoke("What is the capital of France?", {
    callbacks: [handler],
  });
}

main();
The callback handler captures chains, agents, retrievers, and individual LLM calls automatically.

OpenTelemetry

OpenTelemetry is an open standard for distributed tracing. Braintrust acts as an OpenTelemetry backend, accepting spans from any OTel-instrumented application. See the OpenTelemetry integration guide for complete documentation.
1

Install packages

# pnpm
pnpm add braintrust @braintrust/otel @opentelemetry/api @opentelemetry/sdk-node
# npm
npm install braintrust @braintrust/otel @opentelemetry/api @opentelemetry/sdk-node
2

Configure span processor

Route OpenTelemetry spans to Braintrust:
import { NodeSDK } from "@opentelemetry/sdk-node";
import { BraintrustSpanProcessor } from "@braintrust/otel";

const sdk = new NodeSDK({
  serviceName: "my-service",
  spanProcessor: new BraintrustSpanProcessor({
    parent: "project_name:your-project-name",
  }),
});

sdk.start();
3

Set environment variables

Set these environment variables:
.env
BRAINTRUST_API_KEY=your-api-key
BRAINTRUST_PARENT=project_name:my-project

Other frameworks

Braintrust provides integrations for many popular frameworks: See the integrations overview for all supported frameworks.

Next steps