playwright-opentelemetry 0.12.0 → 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.0";
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.0";
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,12 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_config = require("./config-BzW6-Ty7.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");
6
6
  //#region src/fixture/browser-page-tracker.ts
7
7
  const BROWSER_PAGE_SPAN_NAME = "browser.page";
8
8
  const BROWSER_ROUTE_SPAN_NAME = "browser.route";
9
- const SPAN_STATUS_CODE_UNSET$2 = 0;
9
+ const SPAN_STATUS_CODE_UNSET$3 = 0;
10
10
  var BrowserPageTracker = class {
11
11
  traceContext;
12
12
  nextPageId = 1;
@@ -168,7 +168,7 @@ var BrowserPageTracker = class {
168
168
  name,
169
169
  startTime,
170
170
  endTime: startTime,
171
- status: { code: SPAN_STATUS_CODE_UNSET$2 },
171
+ status: { code: SPAN_STATUS_CODE_UNSET$3 },
172
172
  attributes: pageAttributes({
173
173
  pageId,
174
174
  url,
@@ -263,6 +263,131 @@ async function propagateRouteTraceHeaders({ route, request, traceId, spanId }) {
263
263
  } });
264
264
  }
265
265
  //#endregion
266
+ //#region src/fixture/api-request-capture.ts
267
+ const SPAN_KIND_CLIENT$2 = 3;
268
+ const SPAN_STATUS_CODE_UNSET$2 = 0;
269
+ const SPAN_STATUS_CODE_ERROR$2 = 2;
270
+ const CAPTURED_METHODS = new Set([
271
+ "delete",
272
+ "fetch",
273
+ "get",
274
+ "head",
275
+ "patch",
276
+ "post",
277
+ "put"
278
+ ]);
279
+ function createCapturedApiRequestContext(request, traceContext) {
280
+ return new Proxy(request, { get(target, property, receiver) {
281
+ const value = Reflect.get(target, property, receiver);
282
+ if (typeof property !== "string" || !CAPTURED_METHODS.has(property)) return value;
283
+ if (typeof value !== "function") return value;
284
+ return async (...args) => {
285
+ const startTime = /* @__PURE__ */ new Date();
286
+ try {
287
+ const response = await value.apply(target, args);
288
+ traceContext.addSpan(createApiRequestSpan({
289
+ methodName: property,
290
+ args,
291
+ traceContext,
292
+ startTime,
293
+ endTime: /* @__PURE__ */ new Date(),
294
+ statusCode: response.status(),
295
+ responseHeaders: response.headers()
296
+ }));
297
+ return response;
298
+ } catch (error) {
299
+ traceContext.addSpan(createApiRequestSpan({
300
+ methodName: property,
301
+ args,
302
+ traceContext,
303
+ startTime,
304
+ endTime: /* @__PURE__ */ new Date(),
305
+ error
306
+ }));
307
+ throw error;
308
+ }
309
+ };
310
+ } });
311
+ }
312
+ function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, responseHeaders, error }) {
313
+ const method = getRequestMethod(methodName, args);
314
+ const attributes = createHttpAttributes$1({
315
+ method,
316
+ url: getRequestUrl(args[0]),
317
+ statusCode,
318
+ responseHeaders,
319
+ error
320
+ });
321
+ const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
322
+ return {
323
+ traceId: traceContext.traceId,
324
+ spanId: require_config.generateSpanId(),
325
+ parentSpanId: traceContext.rootSpanId,
326
+ name: `HTTP ${method}`,
327
+ kind: SPAN_KIND_CLIENT$2,
328
+ startTime,
329
+ endTime,
330
+ status: failed ? {
331
+ code: SPAN_STATUS_CODE_ERROR$2,
332
+ message: errorMessage$1(error)
333
+ } : { code: SPAN_STATUS_CODE_UNSET$2 },
334
+ attributes,
335
+ events: []
336
+ };
337
+ }
338
+ function createHttpAttributes$1({ method, url, statusCode, responseHeaders, error }) {
339
+ const attributes = {
340
+ "http.request.method": method,
341
+ "http.resource.type": "fetch",
342
+ "playwright.request.api": true,
343
+ "url.full": url
344
+ };
345
+ try {
346
+ const parsedUrl = new URL(url);
347
+ attributes["url.path"] = parsedUrl.pathname;
348
+ attributes["server.address"] = parsedUrl.hostname;
349
+ attributes["server.port"] = serverPort$1(parsedUrl);
350
+ if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
351
+ } catch {}
352
+ if (statusCode !== void 0) {
353
+ attributes["http.response.status_code"] = statusCode;
354
+ if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
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];
360
+ return attributes;
361
+ }
362
+ function getRequestMethod(methodName, args) {
363
+ const options = getOptions(args[1]);
364
+ if (methodName === "fetch") {
365
+ const input = args[0];
366
+ return (options.method ?? (input instanceof Request ? input.method : void 0) ?? "GET").toUpperCase();
367
+ }
368
+ return methodName.toUpperCase();
369
+ }
370
+ function getRequestUrl(input) {
371
+ if (input instanceof Request) return input.url;
372
+ return String(input);
373
+ }
374
+ function getOptions(value) {
375
+ if (typeof value !== "object" || value === null || !("method" in value)) return {};
376
+ const method = value.method;
377
+ return typeof method === "string" ? { method } : {};
378
+ }
379
+ function serverPort$1(url) {
380
+ if (url.port) return Number.parseInt(url.port, 10);
381
+ return url.protocol === "https:" ? 443 : 80;
382
+ }
383
+ function errorType$1(error) {
384
+ if (error instanceof Error && error.name) return error.name;
385
+ return "Error";
386
+ }
387
+ function errorMessage$1(error) {
388
+ return error instanceof Error && error.message ? error.message : void 0;
389
+ }
390
+ //#endregion
266
391
  //#region src/fixture/reporter-config.ts
267
392
  const PLAYWRIGHT_OPENTELEMETRY_REPORTER_NAMES = new Set(["playwright-opentelemetry", "playwright-opentelemetry/reporter"]);
268
393
  const PLAYWRIGHT_OPENTELEMETRY_REPORTER_PATHS = ["dist/reporter.mjs", "dist/reporter.cjs"];
@@ -359,7 +484,10 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
359
484
  const serverPort = parsedUrl.port !== "" ? Number.parseInt(parsedUrl.port, 10) : parsedUrl.protocol === "https:" ? 443 : 80;
360
485
  let statusCodeValue = SPAN_STATUS_CODE_UNSET$1;
361
486
  if (statusCode >= 400) statusCodeValue = SPAN_STATUS_CODE_ERROR$1;
362
- 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);
363
491
  const attributes = {
364
492
  "http.request.method": method,
365
493
  "url.full": url,
@@ -371,6 +499,8 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
371
499
  "browser.request.route_association": requestTraceContext.routeAssociation
372
500
  };
373
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];
374
504
  if (statusCodeValue === SPAN_STATUS_CODE_ERROR$1) attributes["error.type"] = statusCode.toString();
375
505
  const networkSpan = {
376
506
  traceId: requestTraceContext.traceId,
@@ -387,9 +517,9 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
387
517
  };
388
518
  traceContext.addSpan(networkSpan);
389
519
  }
390
- async function getResponseHeaderValue(response, name) {
520
+ async function getResponseHeaders(response) {
391
521
  try {
392
- return await response.headerValue(name);
522
+ return await response.allHeaders();
393
523
  } catch {
394
524
  return null;
395
525
  }
@@ -431,7 +561,9 @@ const patchedFetch = async (input, init) => {
431
561
  traceContext,
432
562
  startTime,
433
563
  endTime: /* @__PURE__ */ new Date(),
434
- statusCode: response.status
564
+ statusCode: response.status,
565
+ contentType: response.headers.get("content-type"),
566
+ cacheControl: response.headers.get("cache-control")
435
567
  }));
436
568
  return response;
437
569
  } catch (error) {
@@ -446,12 +578,14 @@ const patchedFetch = async (input, init) => {
446
578
  throw error;
447
579
  }
448
580
  };
449
- function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, error }) {
581
+ function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, contentType, cacheControl, error }) {
450
582
  const method = getFetchMethod(input, init);
451
583
  const attributes = createHttpAttributes({
452
584
  method,
453
585
  url: getFetchUrl(input),
454
586
  statusCode,
587
+ contentType,
588
+ cacheControl,
455
589
  error
456
590
  });
457
591
  const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
@@ -471,7 +605,7 @@ function createFetchSpan({ input, init, traceContext, startTime, endTime, status
471
605
  events: []
472
606
  };
473
607
  }
474
- function createHttpAttributes({ method, url, statusCode, error }) {
608
+ function createHttpAttributes({ method, url, statusCode, contentType, cacheControl, error }) {
475
609
  const attributes = {
476
610
  "http.request.method": method,
477
611
  "http.resource.type": "fetch",
@@ -488,6 +622,8 @@ function createHttpAttributes({ method, url, statusCode, error }) {
488
622
  attributes["http.response.status_code"] = statusCode;
489
623
  if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
490
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];
491
627
  return attributes;
492
628
  }
493
629
  function getFetchMethod(input, init) {
@@ -545,6 +681,9 @@ function createPlaywrightOtelTest(testBase) {
545
681
  await use(tracker);
546
682
  tracker.finishAll();
547
683
  }, { auto: true }],
684
+ request: async ({ request, testTraceContext }, use) => {
685
+ await use(createCapturedApiRequestContext(request, testTraceContext));
686
+ },
548
687
  context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker }, use) => {
549
688
  const config = require_config.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
550
689
  context.route("**", async (route, request) => {
package/dist/fixture.mjs CHANGED
@@ -1,11 +1,11 @@
1
- import { a as createTestTraceContext, n as BROWSER_SERVICE_NAME, o as flushFixtureSpans, p as generateSpanId, s as registerExpectedTrace, t as resolvePlaywrightOpentelemetryConfig } from "./config-Bv4dsPRO.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";
5
5
  //#region src/fixture/browser-page-tracker.ts
6
6
  const BROWSER_PAGE_SPAN_NAME = "browser.page";
7
7
  const BROWSER_ROUTE_SPAN_NAME = "browser.route";
8
- const SPAN_STATUS_CODE_UNSET$2 = 0;
8
+ const SPAN_STATUS_CODE_UNSET$3 = 0;
9
9
  var BrowserPageTracker = class {
10
10
  traceContext;
11
11
  nextPageId = 1;
@@ -167,7 +167,7 @@ var BrowserPageTracker = class {
167
167
  name,
168
168
  startTime,
169
169
  endTime: startTime,
170
- status: { code: SPAN_STATUS_CODE_UNSET$2 },
170
+ status: { code: SPAN_STATUS_CODE_UNSET$3 },
171
171
  attributes: pageAttributes({
172
172
  pageId,
173
173
  url,
@@ -262,6 +262,131 @@ async function propagateRouteTraceHeaders({ route, request, traceId, spanId }) {
262
262
  } });
263
263
  }
264
264
  //#endregion
265
+ //#region src/fixture/api-request-capture.ts
266
+ const SPAN_KIND_CLIENT$2 = 3;
267
+ const SPAN_STATUS_CODE_UNSET$2 = 0;
268
+ const SPAN_STATUS_CODE_ERROR$2 = 2;
269
+ const CAPTURED_METHODS = new Set([
270
+ "delete",
271
+ "fetch",
272
+ "get",
273
+ "head",
274
+ "patch",
275
+ "post",
276
+ "put"
277
+ ]);
278
+ function createCapturedApiRequestContext(request, traceContext) {
279
+ return new Proxy(request, { get(target, property, receiver) {
280
+ const value = Reflect.get(target, property, receiver);
281
+ if (typeof property !== "string" || !CAPTURED_METHODS.has(property)) return value;
282
+ if (typeof value !== "function") return value;
283
+ return async (...args) => {
284
+ const startTime = /* @__PURE__ */ new Date();
285
+ try {
286
+ const response = await value.apply(target, args);
287
+ traceContext.addSpan(createApiRequestSpan({
288
+ methodName: property,
289
+ args,
290
+ traceContext,
291
+ startTime,
292
+ endTime: /* @__PURE__ */ new Date(),
293
+ statusCode: response.status(),
294
+ responseHeaders: response.headers()
295
+ }));
296
+ return response;
297
+ } catch (error) {
298
+ traceContext.addSpan(createApiRequestSpan({
299
+ methodName: property,
300
+ args,
301
+ traceContext,
302
+ startTime,
303
+ endTime: /* @__PURE__ */ new Date(),
304
+ error
305
+ }));
306
+ throw error;
307
+ }
308
+ };
309
+ } });
310
+ }
311
+ function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, responseHeaders, error }) {
312
+ const method = getRequestMethod(methodName, args);
313
+ const attributes = createHttpAttributes$1({
314
+ method,
315
+ url: getRequestUrl(args[0]),
316
+ statusCode,
317
+ responseHeaders,
318
+ error
319
+ });
320
+ const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
321
+ return {
322
+ traceId: traceContext.traceId,
323
+ spanId: generateSpanId(),
324
+ parentSpanId: traceContext.rootSpanId,
325
+ name: `HTTP ${method}`,
326
+ kind: SPAN_KIND_CLIENT$2,
327
+ startTime,
328
+ endTime,
329
+ status: failed ? {
330
+ code: SPAN_STATUS_CODE_ERROR$2,
331
+ message: errorMessage$1(error)
332
+ } : { code: SPAN_STATUS_CODE_UNSET$2 },
333
+ attributes,
334
+ events: []
335
+ };
336
+ }
337
+ function createHttpAttributes$1({ method, url, statusCode, responseHeaders, error }) {
338
+ const attributes = {
339
+ "http.request.method": method,
340
+ "http.resource.type": "fetch",
341
+ "playwright.request.api": true,
342
+ "url.full": url
343
+ };
344
+ try {
345
+ const parsedUrl = new URL(url);
346
+ attributes["url.path"] = parsedUrl.pathname;
347
+ attributes["server.address"] = parsedUrl.hostname;
348
+ attributes["server.port"] = serverPort$1(parsedUrl);
349
+ if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
350
+ } catch {}
351
+ if (statusCode !== void 0) {
352
+ attributes["http.response.status_code"] = statusCode;
353
+ if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
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];
359
+ return attributes;
360
+ }
361
+ function getRequestMethod(methodName, args) {
362
+ const options = getOptions(args[1]);
363
+ if (methodName === "fetch") {
364
+ const input = args[0];
365
+ return (options.method ?? (input instanceof Request ? input.method : void 0) ?? "GET").toUpperCase();
366
+ }
367
+ return methodName.toUpperCase();
368
+ }
369
+ function getRequestUrl(input) {
370
+ if (input instanceof Request) return input.url;
371
+ return String(input);
372
+ }
373
+ function getOptions(value) {
374
+ if (typeof value !== "object" || value === null || !("method" in value)) return {};
375
+ const method = value.method;
376
+ return typeof method === "string" ? { method } : {};
377
+ }
378
+ function serverPort$1(url) {
379
+ if (url.port) return Number.parseInt(url.port, 10);
380
+ return url.protocol === "https:" ? 443 : 80;
381
+ }
382
+ function errorType$1(error) {
383
+ if (error instanceof Error && error.name) return error.name;
384
+ return "Error";
385
+ }
386
+ function errorMessage$1(error) {
387
+ return error instanceof Error && error.message ? error.message : void 0;
388
+ }
389
+ //#endregion
265
390
  //#region src/fixture/reporter-config.ts
266
391
  const PLAYWRIGHT_OPENTELEMETRY_REPORTER_NAMES = new Set(["playwright-opentelemetry", "playwright-opentelemetry/reporter"]);
267
392
  const PLAYWRIGHT_OPENTELEMETRY_REPORTER_PATHS = ["dist/reporter.mjs", "dist/reporter.cjs"];
@@ -358,7 +483,10 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
358
483
  const serverPort = parsedUrl.port !== "" ? Number.parseInt(parsedUrl.port, 10) : parsedUrl.protocol === "https:" ? 443 : 80;
359
484
  let statusCodeValue = SPAN_STATUS_CODE_UNSET$1;
360
485
  if (statusCode >= 400) statusCodeValue = SPAN_STATUS_CODE_ERROR$1;
361
- 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);
362
490
  const attributes = {
363
491
  "http.request.method": method,
364
492
  "url.full": url,
@@ -370,6 +498,8 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
370
498
  "browser.request.route_association": requestTraceContext.routeAssociation
371
499
  };
372
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];
373
503
  if (statusCodeValue === SPAN_STATUS_CODE_ERROR$1) attributes["error.type"] = statusCode.toString();
374
504
  const networkSpan = {
375
505
  traceId: requestTraceContext.traceId,
@@ -386,9 +516,9 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
386
516
  };
387
517
  traceContext.addSpan(networkSpan);
388
518
  }
389
- async function getResponseHeaderValue(response, name) {
519
+ async function getResponseHeaders(response) {
390
520
  try {
391
- return await response.headerValue(name);
521
+ return await response.allHeaders();
392
522
  } catch {
393
523
  return null;
394
524
  }
@@ -430,7 +560,9 @@ const patchedFetch = async (input, init) => {
430
560
  traceContext,
431
561
  startTime,
432
562
  endTime: /* @__PURE__ */ new Date(),
433
- statusCode: response.status
563
+ statusCode: response.status,
564
+ contentType: response.headers.get("content-type"),
565
+ cacheControl: response.headers.get("cache-control")
434
566
  }));
435
567
  return response;
436
568
  } catch (error) {
@@ -445,12 +577,14 @@ const patchedFetch = async (input, init) => {
445
577
  throw error;
446
578
  }
447
579
  };
448
- function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, error }) {
580
+ function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, contentType, cacheControl, error }) {
449
581
  const method = getFetchMethod(input, init);
450
582
  const attributes = createHttpAttributes({
451
583
  method,
452
584
  url: getFetchUrl(input),
453
585
  statusCode,
586
+ contentType,
587
+ cacheControl,
454
588
  error
455
589
  });
456
590
  const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
@@ -470,7 +604,7 @@ function createFetchSpan({ input, init, traceContext, startTime, endTime, status
470
604
  events: []
471
605
  };
472
606
  }
473
- function createHttpAttributes({ method, url, statusCode, error }) {
607
+ function createHttpAttributes({ method, url, statusCode, contentType, cacheControl, error }) {
474
608
  const attributes = {
475
609
  "http.request.method": method,
476
610
  "http.resource.type": "fetch",
@@ -487,6 +621,8 @@ function createHttpAttributes({ method, url, statusCode, error }) {
487
621
  attributes["http.response.status_code"] = statusCode;
488
622
  if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
489
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];
490
626
  return attributes;
491
627
  }
492
628
  function getFetchMethod(input, init) {
@@ -544,6 +680,9 @@ function createPlaywrightOtelTest(testBase) {
544
680
  await use(tracker);
545
681
  tracker.finishAll();
546
682
  }, { auto: true }],
683
+ request: async ({ request, testTraceContext }, use) => {
684
+ await use(createCapturedApiRequestContext(request, testTraceContext));
685
+ },
547
686
  context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker }, use) => {
548
687
  const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
549
688
  context.route("**", async (route, request) => {
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/index.ts
2
- var src_default = require("./reporter-BFqKJlKV.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-DTduncL-.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-BzW6-Ty7.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");
@@ -319,7 +319,7 @@ var PlaywrightOpentelemetryReporter = class {
319
319
  }
320
320
  processTestStep(test, step, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds) {
321
321
  const stepId = getStepId(test, step);
322
- if (isInternalFixtureStep(step)) {
322
+ if (isInternalFixtureStep(step) || isInternalApiRequestStep(step)) {
323
323
  skippedStepIds.add(stepId);
324
324
  processedSteps.delete(stepId);
325
325
  if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds);
@@ -498,15 +498,28 @@ function cleanErrorMessage(message) {
498
498
  }
499
499
  function isInternalFixtureStep(step) {
500
500
  if (step.category !== "fixture" || !step.location?.file) return false;
501
- const file = step.location.file.replace(/\\/g, "/");
501
+ return isInternalFixtureFile(step.location.file);
502
+ }
503
+ function isInternalApiRequestStep(step) {
504
+ if (step.category !== "pw:api" || !step.location?.file) return false;
505
+ return isApiRequestStepTitle(step.title) && isInternalFixtureFile(step.location.file);
506
+ }
507
+ function isApiRequestStepTitle(title) {
508
+ return /^(?:DELETE|FETCH|GET|HEAD|PATCH|POST|PUT)\s+"/.test(title);
509
+ }
510
+ function isInternalFixtureFile(filePath) {
511
+ const file = filePath.replace(/\\/g, "/");
502
512
  return INTERNAL_FIXTURE_FILE_PATTERNS.some((pattern) => pattern.test(file));
503
513
  }
504
514
  const INTERNAL_FIXTURE_FILE_PATTERNS = [
505
515
  /(?:^|\/)dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
516
+ /(?:^|\/)dist\/fixture\.(?:mjs|cjs|js)$/,
506
517
  /(?:^|\/)playwright-opentelemetry\/dist\/fixture\.(?:mjs|cjs|js)$/,
518
+ /(?:^|\/)playwright-opentelemetry\/reporter\/dist\/fixture\.(?:mjs|cjs|js)$/,
507
519
  /(?:^|\/)playwright-opentelemetry\/dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
508
520
  /(?:^|\/)playwright-opentelemetry\/dist\/fixture\/index\.(?:mjs|cjs|js)$/,
509
- /(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/playwright-opentelemetry-fixture\.ts$/
521
+ /(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/playwright-opentelemetry-fixture\.ts$/,
522
+ /(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/api-request-capture\.ts$/
510
523
  ];
511
524
  function isSpanAttributes(value) {
512
525
  if (!isRecord(value)) return false;
@@ -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-Bv4dsPRO.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";
@@ -317,7 +317,7 @@ var PlaywrightOpentelemetryReporter = class {
317
317
  }
318
318
  processTestStep(test, step, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds) {
319
319
  const stepId = getStepId(test, step);
320
- if (isInternalFixtureStep(step)) {
320
+ if (isInternalFixtureStep(step) || isInternalApiRequestStep(step)) {
321
321
  skippedStepIds.add(stepId);
322
322
  processedSteps.delete(stepId);
323
323
  if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds);
@@ -496,15 +496,28 @@ function cleanErrorMessage(message) {
496
496
  }
497
497
  function isInternalFixtureStep(step) {
498
498
  if (step.category !== "fixture" || !step.location?.file) return false;
499
- const file = step.location.file.replace(/\\/g, "/");
499
+ return isInternalFixtureFile(step.location.file);
500
+ }
501
+ function isInternalApiRequestStep(step) {
502
+ if (step.category !== "pw:api" || !step.location?.file) return false;
503
+ return isApiRequestStepTitle(step.title) && isInternalFixtureFile(step.location.file);
504
+ }
505
+ function isApiRequestStepTitle(title) {
506
+ return /^(?:DELETE|FETCH|GET|HEAD|PATCH|POST|PUT)\s+"/.test(title);
507
+ }
508
+ function isInternalFixtureFile(filePath) {
509
+ const file = filePath.replace(/\\/g, "/");
500
510
  return INTERNAL_FIXTURE_FILE_PATTERNS.some((pattern) => pattern.test(file));
501
511
  }
502
512
  const INTERNAL_FIXTURE_FILE_PATTERNS = [
503
513
  /(?:^|\/)dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
514
+ /(?:^|\/)dist\/fixture\.(?:mjs|cjs|js)$/,
504
515
  /(?:^|\/)playwright-opentelemetry\/dist\/fixture\.(?:mjs|cjs|js)$/,
516
+ /(?:^|\/)playwright-opentelemetry\/reporter\/dist\/fixture\.(?:mjs|cjs|js)$/,
505
517
  /(?:^|\/)playwright-opentelemetry\/dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
506
518
  /(?:^|\/)playwright-opentelemetry\/dist\/fixture\/index\.(?:mjs|cjs|js)$/,
507
- /(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/playwright-opentelemetry-fixture\.ts$/
519
+ /(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/playwright-opentelemetry-fixture\.ts$/,
520
+ /(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/api-request-capture\.ts$/
508
521
  ];
509
522
  function isSpanAttributes(value) {
510
523
  if (!isRecord(value)) return false;
package/dist/reporter.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/reporter/index.ts
2
- var reporter_default = require("./reporter-BFqKJlKV.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-DTduncL-.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.0",
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": [