playwright-opentelemetry 0.12.1 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,89 @@
1
- # `playwright-opentelemetry`
1
+ # playwright-opentelemetry
2
2
 
3
- A combination of a Playwright reporter and a fixture that allows you to create opentelemetry spans for playwright end-to-end tests.
3
+ **Trace your Playwright tests across the entire stack.**
4
4
 
5
- For more information on getting started, check out the main [readme](../README.md).
5
+ [![npm version](https://img.shields.io/npm/v/playwright-opentelemetry)](https://www.npmjs.com/package/playwright-opentelemetry)
6
+ [![license](https://img.shields.io/npm/l/playwright-opentelemetry)](https://github.com/endformdev/playwright-opentelemetry/blob/main/LICENSE)
7
+
8
+ A Playwright **reporter** and **fixture** that record each test attempt as OpenTelemetry spans, capture the browser activity around it, and propagate W3C trace context (`traceparent`) from browser requests into your instrumented backend. The result is one connected trace, rooted at a named test, reaching from the Playwright step through the browser request into every instrumented service the user journey touched.
9
+
10
+ ![One test attempt, traced from the Playwright step through the browser request into the backend span that failed](https://raw.githubusercontent.com/endformdev/playwright-opentelemetry/main/docs/assets/hero-trace.png)
11
+
12
+ ```text
13
+ Playwright test
14
+ -> test step
15
+ -> browser request + traceparent
16
+ -> application request
17
+ -> service call
18
+ -> database query
19
+ ```
20
+
21
+ - The **reporter** turns each retained test attempt into a root `playwright.test` span, with steps, hooks, fixtures, and actions as child `playwright.test.step` spans.
22
+ - The **fixture** records page navigations, browser requests, `request` fixture activity, worker `fetch` activity, console messages, and uncaught page errors under a `playwright-browser` service, and injects the `traceparent` header that makes backend spans children of the test.
23
+
24
+ ## Quick start
25
+
26
+ ```bash
27
+ npm install --save-dev playwright-opentelemetry
28
+ ```
29
+
30
+ ```ts
31
+ // playwright.config.ts
32
+ import { defineConfig } from "@playwright/test";
33
+ import type {
34
+ PlaywrightOpentelemetryConfig,
35
+ PlaywrightOpentelemetryUseOptions,
36
+ } from "playwright-opentelemetry/fixture";
37
+
38
+ const playwrightOpentelemetry: PlaywrightOpentelemetryConfig = {
39
+ // Send to any OTLP destination, or set OTEL_EXPORTER_OTLP_ENDPOINT
40
+ otlpEndpoint: {
41
+ url: "https://api.eu1.honeycomb.io/v1/traces",
42
+ headers: { "x-honeycomb-team": "your-api-key" },
43
+ },
44
+ // Or write a local OpenTelemetry trace ZIP instead of, or alongside, OTLP.
45
+ storeTraceZip: true,
46
+ };
47
+
48
+ export default defineConfig<PlaywrightOpentelemetryUseOptions>({
49
+ reporter: [["playwright-opentelemetry/reporter"]],
50
+ use: {
51
+ playwrightOpentelemetry,
52
+ // Screenshots come from Playwright's retained trace.
53
+ trace: "retain-on-failure",
54
+ },
55
+ });
56
+ ```
57
+
58
+ Switch your tests to the instrumented fixture:
59
+
60
+ ```ts
61
+ import { expect } from "@playwright/test";
62
+ import { test } from "playwright-opentelemetry/fixture";
63
+
64
+ test("has title", async ({ page }) => {
65
+ await page.goto("https://playwright.dev/");
66
+
67
+ await expect(page).toHaveTitle(/Playwright/);
68
+ });
69
+ ```
70
+
71
+ View the resulting trace in the [hosted trace viewer](https://trace.endform.dev), or locally:
72
+
73
+ ```bash
74
+ npx @playwright-opentelemetry/trace-viewer
75
+ ```
76
+
77
+ ## Documentation
78
+
79
+ Full documentation, including trace retention options, screenshot capture, multiple OTLP destinations, output formats, and the self-hostable Trace API, lives in the [project README](https://github.com/endformdev/playwright-opentelemetry#usage).
6
80
 
7
81
  ## Developing the reporter / fixture
8
82
 
9
83
  - `pnpm dev` starts a dev server that outputs `dist/index.mjs`
10
84
  - `pnpm build` otherwise creates a one-off compiled build
11
85
  - `pnpm test:e2e` uses the compiled reporter output
86
+
87
+ ## License
88
+
89
+ [Apache-2.0](https://github.com/endformdev/playwright-opentelemetry/blob/main/LICENSE), built by [Endform](https://endform.dev).
@@ -21,7 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
  //#endregion
23
23
  //#region package.json
24
- var version = "0.12.1";
24
+ var version = "0.12.2";
25
25
  const PLAYWRIGHT_TRACE_API_SOURCE_HEADER = "x-playwright-otel-source";
26
26
  const PLAYWRIGHT_TRACE_API_SOURCE_REPORTER = "reporter";
27
27
  function withPlaywrightTraceApiHeaders(headers) {
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.12.1";
2
+ var version = "0.12.2";
3
3
  const PLAYWRIGHT_TRACE_API_SOURCE_HEADER = "x-playwright-otel-source";
4
4
  const PLAYWRIGHT_TRACE_API_SOURCE_REPORTER = "reporter";
5
5
  function withPlaywrightTraceApiHeaders(headers) {
package/dist/fixture.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_config = require("./config-CE5ph46B.cjs");
2
+ const require_config = require("./config-B4WTFCIw.cjs");
3
3
  let node_path = require("node:path");
4
4
  node_path = require_config.__toESM(node_path, 1);
5
5
  let _playwright_test = require("@playwright/test");
@@ -291,7 +291,8 @@ function createCapturedApiRequestContext(request, traceContext) {
291
291
  traceContext,
292
292
  startTime,
293
293
  endTime: /* @__PURE__ */ new Date(),
294
- statusCode: response.status()
294
+ statusCode: response.status(),
295
+ responseHeaders: response.headers()
295
296
  }));
296
297
  return response;
297
298
  } catch (error) {
@@ -308,12 +309,13 @@ function createCapturedApiRequestContext(request, traceContext) {
308
309
  };
309
310
  } });
310
311
  }
311
- function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, error }) {
312
+ function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, responseHeaders, error }) {
312
313
  const method = getRequestMethod(methodName, args);
313
314
  const attributes = createHttpAttributes$1({
314
315
  method,
315
316
  url: getRequestUrl(args[0]),
316
317
  statusCode,
318
+ responseHeaders,
317
319
  error
318
320
  });
319
321
  const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
@@ -333,7 +335,7 @@ function createApiRequestSpan({ methodName, args, traceContext, startTime, endTi
333
335
  events: []
334
336
  };
335
337
  }
336
- function createHttpAttributes$1({ method, url, statusCode, error }) {
338
+ function createHttpAttributes$1({ method, url, statusCode, responseHeaders, error }) {
337
339
  const attributes = {
338
340
  "http.request.method": method,
339
341
  "http.resource.type": "fetch",
@@ -351,6 +353,10 @@ function createHttpAttributes$1({ method, url, statusCode, error }) {
351
353
  attributes["http.response.status_code"] = statusCode;
352
354
  if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
353
355
  } else if (error !== void 0) attributes["error.type"] = errorType$1(error);
356
+ const contentType = responseHeaders?.["content-type"];
357
+ const cacheControl = responseHeaders?.["cache-control"];
358
+ if (contentType) attributes["http.response.header.content-type"] = [contentType];
359
+ if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
354
360
  return attributes;
355
361
  }
356
362
  function getRequestMethod(methodName, args) {
@@ -478,7 +484,10 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
478
484
  const serverPort = parsedUrl.port !== "" ? Number.parseInt(parsedUrl.port, 10) : parsedUrl.protocol === "https:" ? 443 : 80;
479
485
  let statusCodeValue = SPAN_STATUS_CODE_UNSET$1;
480
486
  if (statusCode >= 400) statusCodeValue = SPAN_STATUS_CODE_ERROR$1;
481
- const resourceType = detectResourceType(await getResponseHeaderValue(response, "content-type"), url);
487
+ const responseHeaders = await getResponseHeaders(response);
488
+ const contentType = responseHeaders?.["content-type"] ?? null;
489
+ const cacheControl = responseHeaders?.["cache-control"];
490
+ const resourceType = detectResourceType(contentType, url);
482
491
  const attributes = {
483
492
  "http.request.method": method,
484
493
  "url.full": url,
@@ -490,6 +499,8 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
490
499
  "browser.request.route_association": requestTraceContext.routeAssociation
491
500
  };
492
501
  if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
502
+ if (contentType) attributes["http.response.header.content-type"] = [contentType];
503
+ if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
493
504
  if (statusCodeValue === SPAN_STATUS_CODE_ERROR$1) attributes["error.type"] = statusCode.toString();
494
505
  const networkSpan = {
495
506
  traceId: requestTraceContext.traceId,
@@ -506,9 +517,9 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
506
517
  };
507
518
  traceContext.addSpan(networkSpan);
508
519
  }
509
- async function getResponseHeaderValue(response, name) {
520
+ async function getResponseHeaders(response) {
510
521
  try {
511
- return await response.headerValue(name);
522
+ return await response.allHeaders();
512
523
  } catch {
513
524
  return null;
514
525
  }
@@ -550,7 +561,9 @@ const patchedFetch = async (input, init) => {
550
561
  traceContext,
551
562
  startTime,
552
563
  endTime: /* @__PURE__ */ new Date(),
553
- statusCode: response.status
564
+ statusCode: response.status,
565
+ contentType: response.headers.get("content-type"),
566
+ cacheControl: response.headers.get("cache-control")
554
567
  }));
555
568
  return response;
556
569
  } catch (error) {
@@ -565,12 +578,14 @@ const patchedFetch = async (input, init) => {
565
578
  throw error;
566
579
  }
567
580
  };
568
- function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, error }) {
581
+ function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, contentType, cacheControl, error }) {
569
582
  const method = getFetchMethod(input, init);
570
583
  const attributes = createHttpAttributes({
571
584
  method,
572
585
  url: getFetchUrl(input),
573
586
  statusCode,
587
+ contentType,
588
+ cacheControl,
574
589
  error
575
590
  });
576
591
  const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
@@ -590,7 +605,7 @@ function createFetchSpan({ input, init, traceContext, startTime, endTime, status
590
605
  events: []
591
606
  };
592
607
  }
593
- function createHttpAttributes({ method, url, statusCode, error }) {
608
+ function createHttpAttributes({ method, url, statusCode, contentType, cacheControl, error }) {
594
609
  const attributes = {
595
610
  "http.request.method": method,
596
611
  "http.resource.type": "fetch",
@@ -607,6 +622,8 @@ function createHttpAttributes({ method, url, statusCode, error }) {
607
622
  attributes["http.response.status_code"] = statusCode;
608
623
  if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
609
624
  } else if (error !== void 0) attributes["error.type"] = errorType(error);
625
+ if (contentType) attributes["http.response.header.content-type"] = [contentType];
626
+ if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
610
627
  return attributes;
611
628
  }
612
629
  function getFetchMethod(input, init) {
package/dist/fixture.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as createTestTraceContext, n as BROWSER_SERVICE_NAME, o as flushFixtureSpans, p as generateSpanId, s as registerExpectedTrace, t as resolvePlaywrightOpentelemetryConfig } from "./config-CoP8kphA.mjs";
1
+ import { a as createTestTraceContext, n as BROWSER_SERVICE_NAME, o as flushFixtureSpans, p as generateSpanId, s as registerExpectedTrace, t as resolvePlaywrightOpentelemetryConfig } from "./config-DamCC4Fv.mjs";
2
2
  import path from "node:path";
3
3
  import { test as test$1 } from "@playwright/test";
4
4
  export * from "@playwright/test";
@@ -290,7 +290,8 @@ function createCapturedApiRequestContext(request, traceContext) {
290
290
  traceContext,
291
291
  startTime,
292
292
  endTime: /* @__PURE__ */ new Date(),
293
- statusCode: response.status()
293
+ statusCode: response.status(),
294
+ responseHeaders: response.headers()
294
295
  }));
295
296
  return response;
296
297
  } catch (error) {
@@ -307,12 +308,13 @@ function createCapturedApiRequestContext(request, traceContext) {
307
308
  };
308
309
  } });
309
310
  }
310
- function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, error }) {
311
+ function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, responseHeaders, error }) {
311
312
  const method = getRequestMethod(methodName, args);
312
313
  const attributes = createHttpAttributes$1({
313
314
  method,
314
315
  url: getRequestUrl(args[0]),
315
316
  statusCode,
317
+ responseHeaders,
316
318
  error
317
319
  });
318
320
  const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
@@ -332,7 +334,7 @@ function createApiRequestSpan({ methodName, args, traceContext, startTime, endTi
332
334
  events: []
333
335
  };
334
336
  }
335
- function createHttpAttributes$1({ method, url, statusCode, error }) {
337
+ function createHttpAttributes$1({ method, url, statusCode, responseHeaders, error }) {
336
338
  const attributes = {
337
339
  "http.request.method": method,
338
340
  "http.resource.type": "fetch",
@@ -350,6 +352,10 @@ function createHttpAttributes$1({ method, url, statusCode, error }) {
350
352
  attributes["http.response.status_code"] = statusCode;
351
353
  if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
352
354
  } else if (error !== void 0) attributes["error.type"] = errorType$1(error);
355
+ const contentType = responseHeaders?.["content-type"];
356
+ const cacheControl = responseHeaders?.["cache-control"];
357
+ if (contentType) attributes["http.response.header.content-type"] = [contentType];
358
+ if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
353
359
  return attributes;
354
360
  }
355
361
  function getRequestMethod(methodName, args) {
@@ -477,7 +483,10 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
477
483
  const serverPort = parsedUrl.port !== "" ? Number.parseInt(parsedUrl.port, 10) : parsedUrl.protocol === "https:" ? 443 : 80;
478
484
  let statusCodeValue = SPAN_STATUS_CODE_UNSET$1;
479
485
  if (statusCode >= 400) statusCodeValue = SPAN_STATUS_CODE_ERROR$1;
480
- const resourceType = detectResourceType(await getResponseHeaderValue(response, "content-type"), url);
486
+ const responseHeaders = await getResponseHeaders(response);
487
+ const contentType = responseHeaders?.["content-type"] ?? null;
488
+ const cacheControl = responseHeaders?.["cache-control"];
489
+ const resourceType = detectResourceType(contentType, url);
481
490
  const attributes = {
482
491
  "http.request.method": method,
483
492
  "url.full": url,
@@ -489,6 +498,8 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
489
498
  "browser.request.route_association": requestTraceContext.routeAssociation
490
499
  };
491
500
  if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
501
+ if (contentType) attributes["http.response.header.content-type"] = [contentType];
502
+ if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
492
503
  if (statusCodeValue === SPAN_STATUS_CODE_ERROR$1) attributes["error.type"] = statusCode.toString();
493
504
  const networkSpan = {
494
505
  traceId: requestTraceContext.traceId,
@@ -505,9 +516,9 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
505
516
  };
506
517
  traceContext.addSpan(networkSpan);
507
518
  }
508
- async function getResponseHeaderValue(response, name) {
519
+ async function getResponseHeaders(response) {
509
520
  try {
510
- return await response.headerValue(name);
521
+ return await response.allHeaders();
511
522
  } catch {
512
523
  return null;
513
524
  }
@@ -549,7 +560,9 @@ const patchedFetch = async (input, init) => {
549
560
  traceContext,
550
561
  startTime,
551
562
  endTime: /* @__PURE__ */ new Date(),
552
- statusCode: response.status
563
+ statusCode: response.status,
564
+ contentType: response.headers.get("content-type"),
565
+ cacheControl: response.headers.get("cache-control")
553
566
  }));
554
567
  return response;
555
568
  } catch (error) {
@@ -564,12 +577,14 @@ const patchedFetch = async (input, init) => {
564
577
  throw error;
565
578
  }
566
579
  };
567
- function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, error }) {
580
+ function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, contentType, cacheControl, error }) {
568
581
  const method = getFetchMethod(input, init);
569
582
  const attributes = createHttpAttributes({
570
583
  method,
571
584
  url: getFetchUrl(input),
572
585
  statusCode,
586
+ contentType,
587
+ cacheControl,
573
588
  error
574
589
  });
575
590
  const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
@@ -589,7 +604,7 @@ function createFetchSpan({ input, init, traceContext, startTime, endTime, status
589
604
  events: []
590
605
  };
591
606
  }
592
- function createHttpAttributes({ method, url, statusCode, error }) {
607
+ function createHttpAttributes({ method, url, statusCode, contentType, cacheControl, error }) {
593
608
  const attributes = {
594
609
  "http.request.method": method,
595
610
  "http.resource.type": "fetch",
@@ -606,6 +621,8 @@ function createHttpAttributes({ method, url, statusCode, error }) {
606
621
  attributes["http.response.status_code"] = statusCode;
607
622
  if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
608
623
  } else if (error !== void 0) attributes["error.type"] = errorType(error);
624
+ if (contentType) attributes["http.response.header.content-type"] = [contentType];
625
+ if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
609
626
  return attributes;
610
627
  }
611
628
  function getFetchMethod(input, init) {
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/index.ts
2
- var src_default = require("./reporter-C5uzPmZH.cjs").PlaywrightOpentelemetryReporter;
2
+ var src_default = require("./reporter-BWjx2-ui.cjs").PlaywrightOpentelemetryReporter;
3
3
  //#endregion
4
4
  module.exports = src_default;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-CeFtIXbG.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-DGix718W.mjs";
2
2
  //#region src/index.ts
3
3
  var src_default = PlaywrightOpentelemetryReporter;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- const require_config = require("./config-CE5ph46B.cjs");
1
+ const require_config = require("./config-B4WTFCIw.cjs");
2
2
  let node_path = require("node:path");
3
3
  node_path = require_config.__toESM(node_path, 1);
4
4
  let node_fs_promises = require("node:fs/promises");
@@ -1,4 +1,4 @@
1
- import { c as shouldRetainPlaywrightTrace, d as PLAYWRIGHT_TRACE_API_SOURCE_REPORTER, f as buildOtlpRequest, g as withPlaywrightTraceApiHeaders, h as sendSpans, i as TRACE_CONTEXT_ATTACHMENT_NAME, l as filterRetainedDestinations, m as generateTraceId, p as generateSpanId, r as FIXTURE_SPANS_ATTACHMENT_NAME, t as resolvePlaywrightOpentelemetryConfig, u as PLAYWRIGHT_TRACE_API_SOURCE_HEADER } from "./config-CoP8kphA.mjs";
1
+ import { c as shouldRetainPlaywrightTrace, d as PLAYWRIGHT_TRACE_API_SOURCE_REPORTER, f as buildOtlpRequest, g as withPlaywrightTraceApiHeaders, h as sendSpans, i as TRACE_CONTEXT_ATTACHMENT_NAME, l as filterRetainedDestinations, m as generateTraceId, p as generateSpanId, r as FIXTURE_SPANS_ATTACHMENT_NAME, t as resolvePlaywrightOpentelemetryConfig, u as PLAYWRIGHT_TRACE_API_SOURCE_HEADER } from "./config-DamCC4Fv.mjs";
2
2
  import path from "node:path";
3
3
  import fs from "node:fs/promises";
4
4
  import { BlobReader, BlobWriter, TextWriter, ZipReader, ZipWriter } from "@zip.js/zip.js";
package/dist/reporter.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/reporter/index.ts
2
- var reporter_default = require("./reporter-C5uzPmZH.cjs").PlaywrightOpentelemetryReporter;
2
+ var reporter_default = require("./reporter-BWjx2-ui.cjs").PlaywrightOpentelemetryReporter;
3
3
  //#endregion
4
4
  module.exports = reporter_default;
package/dist/reporter.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-CeFtIXbG.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-DGix718W.mjs";
2
2
  //#region src/reporter/index.ts
3
3
  var reporter_default = PlaywrightOpentelemetryReporter;
4
4
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright-opentelemetry",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "description": "A reporter for Playwright that can export traces and spans in opentelemetry format.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -10,7 +10,8 @@
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "https://github.com/endformdev/playwright-opentelemetry"
13
+ "url": "git+https://github.com/endformdev/playwright-opentelemetry.git",
14
+ "directory": "reporter"
14
15
  },
15
16
  "author": "Oliver Stenbom <oliver@endform.dev>",
16
17
  "keywords": [