Skip to main content

Overview

This guide shows you how to integrate Latitude Telemetry into an existing application that uses LangChain. After completing these steps:
  • Each LangChain run can be captured as a log in Latitude.
  • Logs are attached to a specific prompt and version in Latitude.
  • You can annotate, evaluate, and debug your chains from the Latitude dashboard.
You keep using LangChain as usual — Telemetry observes runs via the LangChain callback system.

Requirements

Before you start, make sure you have:
  • A Latitude account and API key.
  • At least one prompt created in Latitude.
  • A Node.js-based project that uses LangChain.

Steps

1

Install requirements

Add the Latitude Telemetry package to your project:
npm add @latitude-data/telemetry @opentelemetry/api
2

Initialize Latitude Telemetry with LangChain

Create a LatitudeTelemetry instance and pass the LangChain callback manager module as an instrumentation.
import { LatitudeTelemetry } from '@latitude-data/telemetry'
import * as LangchainCallbacks from '@langchain/core/callbacks/manager'

export const telemetry = new LatitudeTelemetry('your-latitude-api-key', {
  instrumentations: {
    langchain: {
      callbackManagerModule: LangchainCallbacks, // Enables tracing via LangChain callbacks
    },
  },
})
3

Wrap your LangChain-powered feature

Wrap the code that runs your LangChain chain with a Telemetry prompt span, and execute the chain inside that span.
import { context } from '@opentelemetry/api'
import { BACKGROUND } from '@latitude-data/telemetry'
import { createAgent } from "langchain";

export async function generateSupportReply(input: string) {
  const $prompt = telemetry.prompt(BACKGROUND(), {
    promptUuid: 'your-prompt-uuid',
    versionUuid: 'your-version-uuid',
  })

  await context
    .with($prompt.context, async () => {
      const agent = createAgent({ model: 'claude-sonnet-4-5' });
      const result = await agent.invoke({
        messages: [
            {
                role: "user",
                content: prompt,
            },
        ],
    });

      // Use result here...
    })
    .then(() => $prompt.end())
    .catch((error) => $prompt.fail(error as Error))
    .finally(() => telemetry.flush())
}

Seeing your logs in Latitude

Once you’ve wrapped your LangChain-powered feature, you can see your logs in Latitude.
  1. Go to the Traces section of your prompt in Latitude.
  2. You should see new entries every time your chain is executed, including:
    • Chain input/output
    • Provider calls made within the chain (when instrumented)
    • Latency and error information