@arizeai/openinference-instrumentation-langchain

中文文档
4.1.5发布于 2026/10/24Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 29.7万

OpenInference Instrumentation for LangChain.js

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Using a Custom Tracer Provider
  4. Compatibility
  5. Deprecations

OpenInference Instrumentation for LangChain.js

This module provides automatic instrumentation for LangChain.js. which may be used in conjunction with @opentelemetry/sdk-trace-node.

Installation

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

Usage

To load the Langchain instrumentation, manually instrument the @langchain/core/callbacks/manager module. The callbacks manager must be manually instrumented due to the non-traditional module structure in @langchain/core. Additional instrumentations can be registered as usual using the registerInstrumentations function.

import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { LangChainInstrumentation } from "@arizeai/openinference-instrumentation-langchain";
import * as CallbackManagerModule from "@langchain/core/callbacks/manager";

const provider = new NodeTracerProvider();
provider.register();

const lcInstrumentation = new LangChainInstrumentation();
// LangChain must be manually instrumented as it doesn't have a traditional module structure
lcInstrumentation.manuallyInstrument(CallbackManagerModule);

For more information on OpenTelemetry Node.js SDK, see the OpenTelemetry Node.js SDK documentation.

Using a Custom Tracer Provider

You can specify a custom tracer provider when creating the LangChain instrumentation. This is useful when you want to use a non-global tracer provider or have more control over the tracing configuration.

import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { Resource } from "@opentelemetry/resources";
import { SEMRESATTRS_PROJECT_NAME } from "@arizeai/openinference-semantic-conventions";
import { LangChainInstrumentation } from "@arizeai/openinference-instrumentation-langchain";
import * as CallbackManagerModule from "@langchain/core/callbacks/manager";

// Create a custom tracer provider
const customTracerProvider = new NodeTracerProvider({
  resource: new Resource({
    [SEMRESATTRS_PROJECT_NAME]: "my-langchain-project",
  }),
});

// Pass the custom tracer provider to the instrumentation
const lcInstrumentation = new LangChainInstrumentation({
  tracerProvider: customTracerProvider,
});

// Manually instrument the LangChain module
lcInstrumentation.manuallyInstrument(CallbackManagerModule);

Alternatively, you can set the tracer provider after creating the instrumentation:

const lcInstrumentation = new LangChainInstrumentation();
lcInstrumentation.setTracerProvider(customTracerProvider);

Compatibility

@langchain/core Version@arizeai/openinference-instrumentation-langchain Version
^1.0.0^4.0.0
^0.3.0^4.0.0

This package is only tested against the 1.X versions of @langchain/core. Older versions may work but are not officially supported. For full compatibility for the 0.X versions of LangChain.js, a dedicated package called openinference-instrumentation-langchain-v0 is available.

Deprecations

LangChain v0.1 was deprecated on 2025-03-02 due to security vulnerabilities in the core package.

版本与发布记录

@arizeai/openinference-instrumentation-langchain 共发布 61 个版本,首次发布于 2024/04/16;过去 12 个月发布了 28 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.1.5latest2026/10/2414 天前
4.1.42026/10/021 个月前
4.1.32026/10/021 个月前
4.1.22026/10/011 个月前
4.1.12026/09/191 个月前
4.1.02026/09/161 个月前

关于 @arizeai/openinference-instrumentation-langchain 的常见问题

@arizeai/openinference-instrumentation-langchain 是什么?

OpenInference Instrumentation for LangChain.js

如何安装 @arizeai/openinference-instrumentation-langchain?

在项目目录运行 npm install @arizeai/openinference-instrumentation-langchain,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@langchain/core(^1.0.0 || ^0.3.0 || ^0.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@arizeai/openinference-instrumentation-langchain 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@arizeai/openinference-instrumentation-langchain 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@arizeai/openinference-instrumentation-langchain 可以商用吗?

@arizeai/openinference-instrumentation-langchain 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@arizeai/openinference-instrumentation-langchain 的下载量有多少?

根据 npm 官方下载统计,@arizeai/openinference-instrumentation-langchain 在 2026/10/07 – 2026/11/05 这 30 天内被下载 297,023 次,日均约 9,901 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@arizeai/openinference-instrumentation-langchain 还在维护吗?

最新版本 4.1.5 发布于 2026/10/24(14 天前);至今共发布 61 个版本,其中过去 12 个月发布了 28 个;首次发布于 2024/04/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。