Skip to main content

Documentation Index

Fetch the complete documentation index at: https://www.adaline.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

LangChain

Use the Adaline LangChain callback handler to send LangChain runs into Adaline without changing the chain logic itself. The integration attaches at the callback layer and maps model, chain, tool, and retriever events into Adaline traces and spans.

Prerequisites

Before you start, make sure you have:
  • An Adaline account.
  • A workspace API key — create one under Settings → API keys.
  • Your project ID — copy it from Monitor → Copy Project ID.
See Integrate your AI agent for a full walkthrough. Set both as environment variables before running the examples on this page:
export ADALINE_API_KEY="your-api-key"
export ADALINE_PROJECT_ID="your-project-id"

Install

npm install @adaline/client @adaline/langchain @langchain/core @langchain/openai

Initialize Adaline

Create an Adaline client, then initialize a monitor for the target project.
import { Adaline } from "@adaline/client";

const adaline = new Adaline({ apiKey: process.env.ADALINE_API_KEY! });
const monitor = adaline.initMonitor({ projectId: process.env.ADALINE_PROJECT_ID! });
For production guidance — buffering, batching, retries, serverless flushing, and graceful shutdown — see Instrument with the Adaline SDK.

Attach the LangChain callback handler

Add the Adaline callback handler to the LangChain call path. Your application code can keep using the same chain, model, tool, and retriever APIs.
import { AdalineLangChainCallbackHandler } from "@adaline/langchain";

const handler = new AdalineLangChainCallbackHandler({ monitor });

Basic example

This example keeps the integration intentionally small: one ChatOpenAI call with the Adaline callback handler attached.
import { ChatOpenAI } from "@langchain/openai";
import { AdalineLangChainCallbackHandler } from "@adaline/langchain";

const handler = new AdalineLangChainCallbackHandler({ monitor });

const model = new ChatOpenAI({
  modelName: "gpt-4o-mini",
  maxTokens: 20,
  callbacks: [handler],
});

const result = await model.invoke("Say hello in one word.");
await monitor.flush();

Use an existing parent trace or span

If you already created a trace or span in Adaline, you can attach LangChain work underneath it instead of letting the handler create a new root trace.
const parentTrace = monitor.logTrace({
  name: "langchain-run",
  referenceId: "langchain-run-1",
});

const handler = new AdalineLangChainCallbackHandler({
  monitor,
  parentTrace,
});
Pass either parentTrace / parent_trace or parentSpan / parent_span, but not both.

Global handler

LangChain can also use a global Adaline handler instead of passing callbacks manually on every invocation.
import {
  AdalineLangChainCallbackHandler,
  setGlobalHandler,
} from "@adaline/langchain";

setGlobalHandler(new AdalineLangChainCallbackHandler({ monitor }));
Use clearGlobalHandler() or clear_global_handler() to remove it.

What the handler captures

The callback handler is designed to map LangChain run trees into Adaline observations, including:
  • chain runs
  • chat model and LLM runs
  • tool runs
  • retriever runs
  • nested child runs under a shared parent run
This page focuses on how to wire the handler in. The exact span shape depends on which LangChain components your application uses and which callbacks they emit.

Next steps

Instrument with the Adaline SDK

Monitor lifecycle, buffering and batching, retries, serverless flushing, and graceful shutdown.

SDK reference

Full class and type reference for the TypeScript and Python SDKs.

All integrations

Browse every framework and AI-provider integration Adaline supports.

View your logs

Open Adaline to see traces and spans land in your project.