@aergonaut/playwright-opentelemetry-reporter

中文文档
0.2.0发布于 2025/01/02MITTypeScriptESM + CJS近 30 天下载 5.5万

OpenTelemetry reporter for Playwright Test

原始使用文档
文档目录9 节
  1. Installation
  2. Dependencies
  3. Initialize the SDK
  4. Configure Playwright
  5. Usage
  6. Generated Spans
  7. Span Statuses
  8. Attaching Span Attributes
  9. License

Playwright OpenTelemetry Reporter

Simple reporter that generates OpenTelemetry traces from Playwright test runs. You can then export these traces to your vendor of choice.

Example of trace in Honeycomb

Installation

Dependencies

Install the package with your favorite package manager:

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

You will also need to install the OpenTelemetry Node SDK and any other packages required by your vendor to export traces.

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

Initialize the SDK

To collect traces, you must initialize the OpenTelemetry SDK before Playwright begins running your tests. The easiest way to do this is through globalSetup. For example:

// 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();
  };
}

N.b. ensure your globalSetup functions returns a function that calls sdk.shutdown(). This will ensure that traces are exported before Playwright exits.

Configure Playwright

Configure Playwright to use your global-setup.ts and the reporter:

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

Usage

Generated Spans

This reporter generates spans for each test case and for each test step within each test case. Step spans are nested according to Playwright's internal organization. Practically, this means that work in before and after hooks will be grouped under nested spans, as will work to set up fixtures, etc.

Span Statuses

The reporter will set status on test spans and step spans according to the status of each test or step.

For step spans, if an error occurs during the step (e.g. a locator times out, or a click fails), the span's status will be set to ERROR and the error message will be recorded on the span.

For test spans, the span will only be set to ERROR if the test fails unexpectedly. Tests which are skipped or which pass will be UNSET. Similarly, expected errors (e.g. declared with test.fail) will also be UNSET.

Attaching Span Attributes

You can attach attributes to the test span by using Playwright test annotations. Your annotation type must start with the prefix pw_otel_reporter. in order to be attached to the span. Anything after the prefix will be used as the attribute name, and the description will be used as the attribute value.

To make constructing the type easier, you can use the annotationLabel function.

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

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

License

MIT.

版本与发布记录

@aergonaut/playwright-opentelemetry-reporter 共发布 1 个版本,首次发布于 2025/01/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.0latest2025/01/021.8 年前

关于 @aergonaut/playwright-opentelemetry-reporter 的常见问题

@aergonaut/playwright-opentelemetry-reporter 是什么?

OpenTelemetry reporter for Playwright Test

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