# @grafana/faro-transport-otlp-http 中文文档

规范地址：https://npmcn.com/package/%40grafana/faro-transport-otlp-http/

版本：2\.14\.0
npm 元数据更新时间：2026-11-09T15:59:09.896Z
中文译文更新时间：2026-11-16T21:54:12.182Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40grafana/faro-transport-otlp-http
原文对照：https://npmcn.com/package/%40grafana/faro-transport-otlp-http/?lang=original
项目主页：https://github.com/grafana/faro-web-sdk
源码仓库：https://github.com/grafana/faro-web-sdk

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：284 kB，68 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：3 个
- 首次发布：2023-04-26T09:37:33.175Z
- 最新版本发布：2026-11-09T15:59:09.449Z
- 近 30 天下载量：76027（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：95（近 12 个月 26 个）

## 中文简介

将法罗数据模型转换为Otlp数据模型的法罗迁移.

## 安装

```sh
npm install @grafana/faro-transport-otlp-http
```

也可以使用：`pnpm add @grafana/faro-transport-otlp-http`、`yarn add @grafana/faro-transport-otlp-http`、`bun add @grafana/faro-transport-otlp-http`

## README

# @grafana/faro-transport-otlp-http (法语)

法罗运输将法罗模型转换为开放遥测模型.

❗️_3⁄4 ̄ ̧漯B_:这个包是实验性的,可能会频繁地被打破. 冒险使用

❗️_3⁄4 ̄ ̧漯B_: Grafana 接收器尚未支持此格式 。\\\\\\\\\\

❗️_3⁄4 ̄ ̧漯B_: 法罗不支持OpenTeleometry的单独度量衡格式. 这意味着法罗不收集"开放遥测"规格所定义的量子. 例如,法罗没有度量类型,例如高格或苏姆或直方图等 就像开放遥测一样 Faro 将计量值存储为日志行 `Measurements`。 。 。 . 在遵守《计量法》的同时将计量法翻译成计量法是不可行的 开放遥测光谱. 因此,我们不转换它们,它们仍然作为日志类型发送

## 安装

```ts
import { getWebInstrumentations, initializeFaro } from '@grafana/faro-react';
import { OtlpHttpTransport } from '@grafana/faro-transport-otlp-http';

initializeFaro({
  // ...
  instrumentations: [
    // Load the default Web instrumentations
    ...getWebInstrumentations(),
  ],
  transports: [
    new OtlpHttpTransport({
      apiKey: env.faro.apiKey,
      logsURL: 'https://example.com/v1/logs',
      tracesURL: 'https://example.com/v1/traces',
    }),
  ],
});
```

## 使用量

Faro OtlpHttp Transport将Faro模型转换为Otlp schema,因此可以将Faro数据发送到 兼容的 Otel 接收器.

### 可选 `body` 类型日志中的属性 `Measurement` 财务报告和审定财务报表 `Exception`

这个 `body` 字段是 Otel 日志光谱定义的可选字段. 因为这样,我们只把身体属性添加到只有身体价值的信号上. 除了这些信号之外 `Measurement` 财务报告和审定财务报表 `Exception`

这会引起一些Otel Collectionor组件出问题.

法罗提供 `createErrorLogBody` 财务报告和审定财务报表 `createMeasurementLogBody` 可以使用的函数 为这些日志创建正文字符串. 两个属性都是 `otlpTransform` 对象在 `OtlpHttpTransportOptions`。 。 。 .

作为参数,每个函数都得到目前正在转换的日志的传输项. 您可以使用此对象的值来构建自定义字符串 .

#### 示例

```ts
initializeFaro({
  // ...
  instrumentations: [
    // Load the default Web instrumentations
    ...getWebInstrumentations(),
  ],
  transports: [
    new OtlpHttpTransport({
      apiKey: env.faro.apiKey,
      logsURL: 'https://example.com/v1/logs',
      tracesURL: 'https://example.com/v1/traces',

      // customize logs transformation
      otlpTransform: {
        // create custom body string for measurement logs
        createMeasurementLogBody(item) {
          // Note: It's not advisable to built big strings which contain redundant data because
          // it ads unnecessary bytes to the requests and your storage solution
          // This example is to show how we can use the transport-item to built a custom string
          const { payload } = item;
          const [measurementName, measurementValue] = Object.entries(payload.values)[0] ?? [];
          const body = `faro.signal.measurement: type=${payload.type} name=${measurementName} value=${measurementValue}`;
          return body;
        },
        // create custom body string for error logs
        createErrorLogBody(item) {
          // Note: It's not advisable to built big strings which contain redundant data because
          // it ads unnecessary bytes to the requests and your storage solution
          // This example is to show how we can use the transport-item to built a custom string
          const { payload } = item;
          const body = `faro.signal.error: type=${payload.type} message=${payload.value}`;
          return body;
        },
      },
    }),
  ],
});
```

### 配置选项

-   `apiKey?: string`: 将添加为 `x-api-key` 头曰.
-   `bufferSize?: number`: 总共请求缓冲多少次.
-   `concurrency?: number`: 要同时执行的请求数.
-   `defaultRateLimitBackoffMs?: number` 尝试请求前需要退后多少毫秒 如果速率限制响应不包含重试后页眉。 中间事件将被放弃, 未缓冲
-   `requestOptions?: OtlpTransportRequestOptions`: 当 发送数据.
-   `tracesURL?: string`: 发送 Traces 到的结束点 .
-   `logsURL?: string`: 发送日志的终点.
-   `otlpTransform?:`:自定义部分日志转换.
-   `otlpTransform.createErrorLogBody?: (item: TransportItem<ExceptionEvent>) => string`数字 : 创建错误日志的自定义正文. `otlpTransform.createMeasurementLogBody?: (item: TransportItem<MeasurementEvent>) => string;`数字 : 创建计量日志的自定义正文.

## 常见问题

### @grafana/faro-transport-otlp-http 是什么？

将法罗数据模型转换为Otlp数据模型的法罗迁移\.

### 如何安装 @grafana/faro-transport-otlp-http？

在项目目录运行 npm install @grafana/faro-transport-otlp-http，或使用 pnpm add / yarn add / bun add。

### @grafana/faro-transport-otlp-http 支持 TypeScript 吗？

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

### @grafana/faro-transport-otlp-http 支持 ESM 还是 CommonJS？

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

### @grafana/faro-transport-otlp-http 可以商用吗？

@grafana/faro-transport-otlp-http 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @grafana/faro-transport-otlp-http 的下载量有多少？

根据 npm 官方下载统计，@grafana/faro-transport-otlp-http 在 2026/10/17 – 2026/11/15 这 30 天内被下载 76,027 次，日均约 2,534 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @grafana/faro-transport-otlp-http 还在维护吗？

最新版本 2\.14\.0 发布于 2026/11/09（7 天前）；至今共发布 95 个版本，其中过去 12 个月发布了 26 个；首次发布于 2023/04/26。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

