JavaScript APIlangchain-v0

Core

Instrumentation

Integrations

JavaScript · Instrumentation

@arizeai/openinference-instrumentation-langchain-v0

OpenInference Instrumentation for LangChain.js Version 0.X

Version
0.1.8
Instruments
@langchain/core ^0.3.0

Install

npm install @arizeai/openinference-instrumentation-langchain-v0

Usage

Register the instrumentation once, at startup, before the library is imported. The LangChainInstrumentation reference below lists its options.

import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { LangChainInstrumentation } from "@arizeai/openinference-instrumentation-langchain-v0";

const provider = new NodeTracerProvider({
  // ...a span processor that exports to Phoenix or any OTLP backend.
});
provider.register();

registerInstrumentations({
  instrumentations: [new LangChainInstrumentation()],
});

If the library is imported first (as ES modules often are), patch it directly with manuallyInstrument().

@arizeai/openinference-instrumentation-langchain-v0

isPatched

functionSource ↗
function isPatched(): boolean

function to check if instrumentation is enabled / disabled

LangChainInstrumentation

classSource ↗
class LangChainInstrumentation extends InstrumentationBase<CallbackManagerModule>

An auto instrumentation class for LangChain that creates OpenInference Compliant spans for LangChain

Properties

NameType
tracerTracer

new LangChainInstrumentation

constructorSource ↗
new LangChainInstrumentation(
  options?: {
    instrumentationConfig?: InstrumentationConfig;
    traceConfig?: TraceConfigOptions;
    tracerProvider?: TracerProvider;
  },
): LangChainInstrumentation

Parameters

NameTypeDescription
instrumentationConfig?InstrumentationConfig

The config for the instrumentation

traceConfig?TraceConfigOptions

The OpenInference trace configuration. Can be used to mask or redact sensitive information on spans.

tracerProvider?TracerProvider

An optional custom trace provider to be used for tracing. If not provided, a tracer will be created using the global tracer provider. This is useful if you want to use a non-global tracer provider.

manuallyInstrument

methodSource ↗
manuallyInstrument(module: __module): void

setTracerProvider

methodSource ↗
setTracerProvider(tracerProvider: TracerProvider): void

Sets TraceProvider to this plugin