@grafana/faro-transport-otlp-http

中文文档
2.14.0发布于 2026/11/09Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 7.6万

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

中文使用文档
文档目录4 节
  1. 安装
  2. 使用量
  3. 可选 body 类型日志中的属性 Measurement 财务报告和审定财务报表 Exception
  4. 配置选项

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

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

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

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

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

安装

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。 。 。 .

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

示例

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 共发布 95 个版本,首次发布于 2023/04/26;过去 12 个月发布了 26 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.14.0latest2026/11/097 天前
2.13.02026/10/2225 天前
2.12.12026/09/221 个月前
2.12.02026/09/181 个月前
2.11.02026/08/272 个月前
2.10.02026/08/182 个月前

关于 @grafana/faro-transport-otlp-http 的常见问题

@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 和提交记录判断。