@arizeai/openinference-genai

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

将 OpenTeleometry GenAI 跨属性转换为 OpenInference 跨属性的功能

中文使用文档
文档目录5 节
  1. 安装
  2. 使用量
  3. 独立
  4. 块处理器
  5. 实例

打开推论 GenAI

npm version

这个软件包提供一套转换的公用设施 OpenTeleometry GenAI 函数 横跨属性到 OpenInference 横跨属性.

[尖叫声] OpenTeleometry GenAI公约仍在孵化中,可能包括随时突破变化. 此软件包将尝试将 OpenTeleometry GenAI 属性的一个子集转换为 OpenInference 属性的最佳努力. 目前,属性反映了截至2025年10月的定义.

安装

npm install --save @arizeai/openinference-genai

使用量

@arizeai/openinference-genai 可以作为一组独立的帮助器函数, 或与 SpanProcessor 相配合,以便自动将 OpenTeleometry GenAI 跨度转换为 OpenInference 跨度.

独立

您可以通过使用独立的帮助器函数来突变设置的跨度属性 .

[大 Span 突变不为 OpenTelemetery SDK 所支持, 因此确保您是 在跨度寿命的最后一英里进行突变(即在将跨度导出为 SpanProcessor 之前).

import { convertGenAISpanAttributesToOpenInferenceSpanAttributes } from `@arizeai/openinference-genai`

// obtain a span with OpenTelemetry GenAI attributes from your tracing system
const span: ReadableSpan = {/* ... */}

// convert the span attributes to OpenInference attributes
const openinferenceAttributes = convertGenAISpanAttributesToOpenInferenceSpanAttributes(span.attributes)

// add the OpenInference attributes to the span
span.attributes = {...span.attributes, ...openinferenceAttributes}

块处理器

您可以使用自定义的 TraceExporter 将 OpenTelemetry GenAI 跨度自动转换为 OpenInference 跨度 .

见 实例/导出- spans.ts 用于以下样本代码的可运行版本.

通过安装软件包开始

pnpm add @opentelemetry/api @opentelemetry/core @opentelemetry/exporter-trace-otlp-proto @opentelemetry/sdk-trace-base @opentelemetry/sdk-trace-node @opentelemetry/semantic-conventions @opentelemetry/resources @arizeai/openinference-genai

创建自定义 TraceExporter,将 OpenTelemetry GenAI 属性转换为 OpenInference 属性.

// openinferenceOTLPTraceExporter.ts
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import type { ReadableSpan } from "@opentelemetry/sdk-trace-base";
import type { ExportResult } from "@opentelemetry/core";

import { convertGenAISpanAttributesToOpenInferenceSpanAttributes } from "@arizeai/openinference-genai";
import type { Mutable } from "@arizeai/openinference-genai/types";

class OpenInferenceOTLPTraceExporter extends OTLPTraceExporter {
  export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void) {
    const processedSpans = spans.map((span) => {
      const processedAttributes = convertGenAISpanAttributesToOpenInferenceSpanAttributes(
        span.attributes,
      );
      // optionally you can replace the entire attributes object with the
      // processed attributes if you want _only_ the OpenInference attributes
      (span as Mutable<ReadableSpan>).attributes = {
        ...span.attributes,
        ...processedAttributes,
      };
      return span;
    });

    super.export(processedSpans, resultCallback);
  }
}

然后用在你选择的处理器里.

// instrumentation.ts
import { resourceFromAttributes } from "@opentelemetry/resources";
import { NodeTracerProvider, BatchSpanProcessor } from "@opentelemetry/sdk-trace-node";
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";

import { SEMRESATTRS_PROJECT_NAME } from "@arizeai/openinference-semantic-conventions";

import { OpenInferenceOTLPTraceExporter } from "./openinferenceOTLPTraceExporter";

const COLLECTOR_ENDPOINT = process.env.COLLECTOR_ENDPOINT;
const SERVICE_NAME = "openinference-genai-app";

export const provider = new NodeTracerProvider({
  resource: resourceFromAttributes({
    [ATTR_SERVICE_NAME]: SERVICE_NAME,
    [SEMRESATTRS_PROJECT_NAME]: SERVICE_NAME,
  }),
  spanProcessors: [
    new BatchSpanProcessor(
      new OpenInferenceOTLPTraceExporter({
        url: `${COLLECTOR_ENDPOINT}/v1/traces`,
      }),
    ),
  ],
});

provider.register();

实例

见 实例 用于此软件包中更多可执行示例的目录.

要执行示例, 请运行以下命令:

cd js/packages/openinference-genai
pnpm install
pnpm -r build
pnpx tsx examples/export-spans.ts

版本与发布记录

@arizeai/openinference-genai 共发布 22 个版本,首次发布于 2025/10/21;过去 12 个月发布了 21 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.1latest2026/10/2414 天前
0.4.02026/10/021 个月前
0.3.112026/10/011 个月前
0.3.102026/09/191 个月前
0.3.92026/09/151 个月前
0.3.82026/09/101 个月前

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

@arizeai/openinference-genai 是什么?

将 OpenTeleometry GenAI 跨属性转换为 OpenInference 跨属性的功能

如何安装 @arizeai/openinference-genai?

在项目目录运行 npm install @arizeai/openinference-genai,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@opentelemetry/api(>=1.9.0)、@opentelemetry/semantic-conventions(>=1.41.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@arizeai/openinference-genai 支持 TypeScript 吗?

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

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

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

@arizeai/openinference-genai 可以商用吗?

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

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

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

@arizeai/openinference-genai 还在维护吗?

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