JavaScript · Instrumentation
@arizeai/openinference-instrumentation-langchain
OpenInference Instrumentation for LangChain.js
- Version
- 4.2.2
- Instruments
@langchain/core ^1.0.0 || ^0.3.0 || ^0.2.0
Install
npm install @arizeai/openinference-instrumentation-langchainUsage
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";
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
isPatched
functionSource ↗function isPatched(): booleanfunction 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
new LangChainInstrumentation
constructorSource ↗new LangChainInstrumentation(
options?: {
instrumentationConfig?: InstrumentationConfig;
traceConfig?: TraceConfigOptions;
tracerProvider?: TracerProvider;
},
): LangChainInstrumentationParameters
| Name | Type | Description |
|---|---|---|
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): voidsetTracerProvider
methodSource ↗setTracerProvider(tracerProvider: TracerProvider): voidSets TraceProvider to this plugin