# @aergonaut/playwright-opentelemetry-reporter 中文文档

规范地址：https://npmcn.com/package/%40aergonaut/playwright-opentelemetry-reporter/

版本：0\.2\.0
npm 元数据更新时间：2025-01-02T06:22:23.565Z
中文译文更新时间：2026-11-05T18:52:14.159Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40aergonaut/playwright-opentelemetry-reporter
原文对照：https://npmcn.com/package/%40aergonaut/playwright-opentelemetry-reporter/?lang=original
项目主页：https://github.com/aergonaut/playwright-opentelemetry-reporter#readme
源码仓库：https://github.com/aergonaut/playwright-opentelemetry-reporter

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

- 包体积（解压后）：45.4 kB，24 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=10
- 运行依赖：1 个
- peer 依赖：@playwright/test \>=1\.36\.0
- 首次发布：2025-01-02T06:22:22.578Z
- 最新版本发布：2025-01-02T06:22:22.891Z
- 近 30 天下载量：54547（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：1（近 12 个月 0 个）

## 中文简介

用于 Playwright 测试的 OpenTelemeter 记录器

## 安装

```sh
npm install @aergonaut/playwright-opentelemetry-reporter
```

也可以使用：`pnpm add @aergonaut/playwright-opentelemetry-reporter`、`yarn add @aergonaut/playwright-opentelemetry-reporter`、`bun add @aergonaut/playwright-opentelemetry-reporter`

## README

# 剧作家 OpenTeleometry 记录器

从 Playwright 测试运行中生成 OpenTelection 痕迹的简单记者. 然后导出这些痕迹到您的 选择的供应商.

![Example of trace in Honeycomb](https://npmcn.com/package/%40aergonaut/playwright-opentelemetry-reporter/docs/images/honeycomb-trace-example.png)

## 安装

### 依赖关系

用您最喜欢的软件包管理器安装软件包 :

```
$ npm install @aergonaut/playwright-opentelemetry-reporter --save-dev
```

您还需要安装 OpenTeleometry 节点 SDK 以及您的供应商为导出痕迹而需要的任何其他软件包 .

```
$ npm install @opentelemetry/sdk-trace-node --save-dev
```

### 初始化 SDK

要收集痕迹,您必须在 Playwright 开始运行测试前初始化 OpenTelemotry SDK 。 最简单 这样做的方法是结束的 `globalSetup`。例如:

```ts
// global-setup.ts
const sdk = new NodeSDK({
  traceExporter: new OTLPTraceExporter(),
  metricReader: new PeriodicExportingMetricReader({
    exporter: new ConsoleMetricExporter(),
  }),
});

export default async function globalSetup(_config: FullConfig) {
  sdk.start();

  return async () => {
    await sdk.shutdown();
  };
}
```

注意确保您 `globalSetup` 函数返回调用函数 `sdk.shutdown()`这将确保追踪 在 Playwright 退出前导出 .

### 配置剧作家

配置使用您的播放机 `global-setup.ts` 和记者:

```ts
// playwright.config.ts
export default defineConfig({
  globalSetup: require.resolve("./global-setup.ts"),
  reporter: "@aergonaut/playwright-opentelemetry-reporter",
})
```

## 使用量

### 生成的 Spans

这个记者为每个测试案例和每个测试案例的每个测试步骤生成跨度. 步长相接 根据Playwright的内部组织. 实际上,这意味着在钩子前后的工作 以嵌入地段分类,以及建立固定物等的工作.

### 扩展状态

记者会根据每个测试或步骤的状态,设定测试跨度和跨度的状况.

对于步骤跨度,如果在步骤中发生出错(如定位出错或点击出错),则该跨度状态将 设置为 `ERROR` 而错误消息将被记录在跨度上.

对于测试跨度,该跨度只能被设定为 `ERROR` 如果测试失败 _没想到_。测试哪些被跳过或哪些 传球 `UNSET`。类似地,预期错误(例如,以 `test.fail`)也将是 `UNSET`。 。 。 .

### 附加扩展属性

您可以使用 Playwright 附加属性到测试跨度 [测试说明](https://playwright.dev/docs/test-annotations)。您的注释 `type` 必须从前缀开始 `pw_otel_reporter.` 以便附着在长度。 前缀后的任何内容都将被用作属性名, ,描述将用作属性值.

来建造 `type` 比较容易,你可以使用 `annotationLabel` 函数.

```ts
import { annotationLabel } from "@aergonaut/playwright-opentelemetry-reporter";

test("example test", async ({ page }) => {
  // ...
  test.info().annotations.push({
    type: annotationLabel("my_annotation"),
    description: "My custom annotation!",
  });
});
```

## 许可证

麻省理工学院.

## 常见问题

### @aergonaut/playwright-opentelemetry-reporter 是什么？

用于 Playwright 测试的 OpenTelemeter 记录器

### 如何安装 @aergonaut/playwright-opentelemetry-reporter？

在项目目录运行 npm install @aergonaut/playwright-opentelemetry-reporter，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@playwright/test（\>=1\.36\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @aergonaut/playwright-opentelemetry-reporter 支持 TypeScript 吗？

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

### @aergonaut/playwright-opentelemetry-reporter 支持 ESM 还是 CommonJS？

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

### @aergonaut/playwright-opentelemetry-reporter 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=10。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @aergonaut/playwright-opentelemetry-reporter 可以商用吗？

@aergonaut/playwright-opentelemetry-reporter 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @aergonaut/playwright-opentelemetry-reporter 的下载量有多少？

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

### @aergonaut/playwright-opentelemetry-reporter 还在维护吗？

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

