playwright-opentelemetry 0.18.1 → 0.19.0

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/dist/fixture.mjs CHANGED
@@ -1,13 +1,15 @@
1
- import { T as generateSpanId, a as supportsScreencastScreenshots, b as writeFixtureHandoffFile, d as flushFixtureSpans, f as registerExpectedTrace, g as SCREENSHOTS_HANDOFF_FILE, m as shouldRetainPlaywrightTrace, o as resolvePlaywrightOpentelemetryConfig, p as couldRetainPlaywrightTrace, r as createScreenshotsZip, s as BROWSER_SERVICE_NAME, t as SCREENSHOTS_ATTACHMENT_NAME, u as createTestTraceContext, x as filterRetainedDestinations } from "./screenshots-zip-CU1X4mzh.mjs";
1
+ import { D as filterRetainedDestinations, E as writeFixtureHandoffFile, P as traceparentHeader, S as SCREENSHOTS_HANDOFF_FILE, _ as registerExpectedTrace, a as supportsScreencastScreenshots, b as API_REQUESTS_HANDOFF_FILE, c as RECORDED_RESPONSE_HEADERS, d as resolvePlaywrightOpentelemetryConfig, f as BROWSER_SERVICE_NAME, g as flushFixtureSpans, h as createTestTraceContext, j as generateSpanId, o as API_REQUESTS_ATTACHMENT_NAME, r as createScreenshotsZip, s as API_REQUEST_WRAPPER_FILE, t as SCREENSHOTS_ATTACHMENT_NAME, v as couldRetainPlaywrightTrace, y as shouldRetainPlaywrightTrace } from "./screenshots-zip-oICwRNl5.mjs";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { test as test$1 } from "@playwright/test";
5
+ import { fileURLToPath } from "node:url";
6
+ import vm from "node:vm";
5
7
  import os from "node:os";
6
8
  export * from "@playwright/test";
7
9
  //#region src/fixture/browser-page-tracker.ts
8
10
  const BROWSER_PAGE_SPAN_NAME = "browser.page";
9
11
  const BROWSER_ROUTE_SPAN_NAME = "browser.route";
10
- const SPAN_STATUS_CODE_UNSET$3 = 0;
12
+ const SPAN_STATUS_CODE_UNSET$2 = 0;
11
13
  var BrowserPageTracker = class {
12
14
  traceContext;
13
15
  nextPageId = 0;
@@ -179,7 +181,7 @@ var BrowserPageTracker = class {
179
181
  name,
180
182
  startTime,
181
183
  endTime: startTime,
182
- status: { code: SPAN_STATUS_CODE_UNSET$3 },
184
+ status: { code: SPAN_STATUS_CODE_UNSET$2 },
183
185
  attributes: pageAttributes({
184
186
  pageId,
185
187
  documentIndex,
@@ -271,18 +273,14 @@ function storeRequestTraceContext({ request, traceContext, parentSpanId, routeAs
271
273
  * @param options - The propagator options
272
274
  */
273
275
  async function propagateRouteTraceHeaders({ route, request, traceId, spanId }) {
274
- const traceHeader = `00-${traceId}-${spanId}-01`;
275
276
  await route.fallback({ headers: {
276
277
  ...request.headers(),
277
- traceparent: traceHeader
278
+ traceparent: traceparentHeader(traceId, spanId)
278
279
  } });
279
280
  }
280
281
  //#endregion
281
282
  //#region src/fixture/api-request-capture.ts
282
- const SPAN_KIND_CLIENT$2 = 3;
283
- const SPAN_STATUS_CODE_UNSET$2 = 0;
284
- const SPAN_STATUS_CODE_ERROR$2 = 2;
285
- const CAPTURED_METHODS = new Set([
283
+ const CAPTURED_METHODS = [
286
284
  "delete",
287
285
  "fetch",
288
286
  "get",
@@ -290,117 +288,219 @@ const CAPTURED_METHODS = new Set([
290
288
  "patch",
291
289
  "post",
292
290
  "put"
293
- ]);
294
- function createCapturedApiRequestContext(request, traceContext) {
295
- return new Proxy(request, { get(target, property, receiver) {
296
- const value = Reflect.get(target, property, receiver);
297
- if (typeof property !== "string" || !CAPTURED_METHODS.has(property)) return value;
298
- if (typeof value !== "function") return value;
299
- return async (...args) => {
300
- const startTime = /* @__PURE__ */ new Date();
301
- try {
302
- const response = await value.apply(target, args);
303
- traceContext.addSpan(createApiRequestSpan({
304
- methodName: property,
305
- args,
306
- traceContext,
307
- startTime,
308
- endTime: /* @__PURE__ */ new Date(),
309
- statusCode: response.status(),
310
- responseHeaders: response.headers()
311
- }));
312
- return response;
313
- } catch (error) {
314
- traceContext.addSpan(createApiRequestSpan({
315
- methodName: property,
316
- args,
317
- traceContext,
318
- startTime,
319
- endTime: /* @__PURE__ */ new Date(),
320
- error
321
- }));
322
- throw error;
323
- }
291
+ ];
292
+ const STATE_KEY = Symbol.for("playwright-opentelemetry.api-request-capture");
293
+ const WRAPPED = Symbol.for("playwright-opentelemetry.api-request-wrapper");
294
+ const state = globalThis[STATE_KEY] ??= { depth: 0 };
295
+ /**
296
+ * Wraps a Playwright method without changing where Playwright says the call
297
+ * came from. A step's location is the first stack frame outside Playwright,
298
+ * so a wrapper written in this file would become the location of every step
299
+ * it wraps. Playwright skips the frames of Node's own modules, and this
300
+ * wrapper is compiled with such a file name. `begin` and `end` are not on the
301
+ * stack while `original` runs.
302
+ */
303
+ const createWrapper = vm.compileFunction(`return function (...args) {
304
+ const call = begin(args);
305
+ let result;
306
+ try {
307
+ result = Reflect.apply(original, this, args);
308
+ } catch (error) {
309
+ end(call, undefined);
310
+ throw error;
311
+ }
312
+ return end(call, result);
313
+ };`, [
314
+ "original",
315
+ "begin",
316
+ "end"
317
+ ], { filename: API_REQUEST_WRAPPER_FILE });
318
+ /**
319
+ * Records the calls made on every `APIRequestContext` of this process, by
320
+ * wrapping the methods of the class they share. The test still gets
321
+ * Playwright's own objects. Does nothing while no recording is active.
322
+ */
323
+ function captureApiRequests(requestContext) {
324
+ try {
325
+ wrapRequestMethods(requestContext);
326
+ } catch {}
327
+ }
328
+ function wrapRequestMethods(requestContext) {
329
+ const prototype = Object.getPrototypeOf(requestContext);
330
+ if (!prototype || prototype === Object.prototype) return;
331
+ for (const methodName of CAPTURED_METHODS) {
332
+ const original = prototype[methodName];
333
+ if (typeof original !== "function" || isWrapped(original)) continue;
334
+ prototype[methodName] = markWrapped(createWrapper(original, (args) => beginCall(methodName, args), endCall));
335
+ }
336
+ }
337
+ /**
338
+ * The class of `APIRequestContext` can only be reached through an instance:
339
+ * finds it when `playwright.request.newContext()` creates the first one, which
340
+ * is also how Playwright creates the `request` fixture.
341
+ */
342
+ function captureNewApiRequestContexts(apiRequest) {
343
+ const target = apiRequest;
344
+ const original = target.newContext;
345
+ if (typeof original !== "function" || isWrapped(original)) return;
346
+ target.newContext = markWrapped(createWrapper(original, () => void 0, (_call, result) => {
347
+ if (!isPromiseLike(result)) return result;
348
+ return result.then((requestContext) => {
349
+ captureApiRequests(requestContext);
350
+ return requestContext;
351
+ });
352
+ }));
353
+ }
354
+ function startApiRequestRecording(options) {
355
+ const recording = {
356
+ ...options,
357
+ requests: []
358
+ };
359
+ const previous = state.recording;
360
+ state.recording = recording;
361
+ return { stop() {
362
+ if (state.recording === recording) state.recording = previous;
363
+ return recording.requests;
364
+ } };
365
+ }
366
+ function beginCall(methodName, args) {
367
+ state.depth++;
368
+ const recording = state.recording;
369
+ if (state.depth > 1 || !recording) return;
370
+ try {
371
+ const call = {
372
+ method: requestMethod(methodName, args),
373
+ url: requestUrl(args[0]),
374
+ startTime: (/* @__PURE__ */ new Date()).toISOString(),
375
+ location: callSite(recording.rootDir)
324
376
  };
325
- } });
377
+ if (recording.traceId) {
378
+ const spanId = generateSpanId();
379
+ if (addTraceparent(args, traceparentHeader(recording.traceId, spanId))) call.spanId = spanId;
380
+ }
381
+ recording.requests.push(call);
382
+ return call;
383
+ } catch {
384
+ return;
385
+ }
326
386
  }
327
- function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, responseHeaders, error }) {
328
- const method = getRequestMethod(methodName, args);
329
- const attributes = createHttpAttributes$1({
330
- method,
331
- url: getRequestUrl(args[0]),
332
- statusCode,
333
- responseHeaders,
334
- error
387
+ function endCall(call, result) {
388
+ state.depth--;
389
+ if (!call || !isPromiseLike(result)) return result;
390
+ return result.then((response) => {
391
+ recordResponse(call, response);
392
+ return response;
393
+ }, (error) => {
394
+ call.endTime = (/* @__PURE__ */ new Date()).toISOString();
395
+ call.errorType = error instanceof Error && error.name ? error.name : "Error";
396
+ throw error;
335
397
  });
336
- const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
337
- return {
338
- traceId: traceContext.traceId,
339
- spanId: generateSpanId(),
340
- parentSpanId: traceContext.rootSpanId,
341
- name: `HTTP ${method}`,
342
- kind: SPAN_KIND_CLIENT$2,
343
- startTime,
344
- endTime,
345
- status: failed ? {
346
- code: SPAN_STATUS_CODE_ERROR$2,
347
- message: errorMessage$1(error)
348
- } : { code: SPAN_STATUS_CODE_UNSET$2 },
349
- attributes,
350
- events: []
351
- };
352
398
  }
353
- function createHttpAttributes$1({ method, url, statusCode, responseHeaders, error }) {
354
- const attributes = {
355
- "http.request.method": method,
356
- "http.resource.type": "fetch",
357
- "playwright.request.api": true,
358
- "url.full": url
359
- };
399
+ function recordResponse(call, response) {
400
+ call.endTime = (/* @__PURE__ */ new Date()).toISOString();
360
401
  try {
361
- const parsedUrl = new URL(url);
362
- attributes["url.path"] = parsedUrl.pathname;
363
- attributes["server.address"] = parsedUrl.hostname;
364
- attributes["server.port"] = serverPort$1(parsedUrl);
365
- if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
402
+ call.statusCode = response.status();
403
+ call.responseUrl = response.url();
404
+ const headers = response.headers();
405
+ const recorded = {};
406
+ for (const name of RECORDED_RESPONSE_HEADERS) if (typeof headers[name] === "string") recorded[name] = headers[name];
407
+ call.responseHeaders = recorded;
366
408
  } catch {}
367
- if (statusCode !== void 0) {
368
- attributes["http.response.status_code"] = statusCode;
369
- if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
370
- } else if (error !== void 0) attributes["error.type"] = errorType$1(error);
371
- const contentType = responseHeaders?.["content-type"];
372
- const cacheControl = responseHeaders?.["cache-control"];
373
- if (contentType) attributes["http.response.header.content-type"] = [contentType];
374
- if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
375
- return attributes;
376
409
  }
377
- function getRequestMethod(methodName, args) {
378
- const options = getOptions(args[1]);
379
- if (methodName === "fetch") {
380
- const input = args[0];
381
- return (options.method ?? (input instanceof Request ? input.method : void 0) ?? "GET").toUpperCase();
382
- }
383
- return methodName.toUpperCase();
410
+ /**
411
+ * Adds the header to the call's options, which `args` holds and Playwright is
412
+ * about to be called with. Leaves a `traceparent` the test set itself alone.
413
+ */
414
+ function addTraceparent(args, traceparent) {
415
+ const options = args[1];
416
+ if (options !== void 0 && (typeof options !== "object" || !options)) return false;
417
+ const headers = options?.headers ?? (typeof args[0] === "string" ? {} : requestHeaders(args[0]));
418
+ if (typeof headers !== "object" || headers === null || Object.keys(headers).some((name) => name.toLowerCase() === "traceparent")) return false;
419
+ args[1] = {
420
+ ...options,
421
+ headers: {
422
+ ...headers,
423
+ traceparent
424
+ }
425
+ };
426
+ return true;
384
427
  }
385
- function getRequestUrl(input) {
386
- if (input instanceof Request) return input.url;
387
- return String(input);
428
+ function requestHeaders(input) {
429
+ const headers = input?.headers;
430
+ return typeof headers === "function" ? headers.call(input) : void 0;
388
431
  }
389
- function getOptions(value) {
390
- if (typeof value !== "object" || value === null || !("method" in value)) return {};
391
- const method = value.method;
392
- return typeof method === "string" ? { method } : {};
432
+ function requestMethod(methodName, args) {
433
+ if (methodName !== "fetch") return methodName.toUpperCase();
434
+ const options = args[1];
435
+ return (typeof options?.method === "string" ? options.method : callIfFunction(args[0], "method") ?? "GET").toUpperCase();
393
436
  }
394
- function serverPort$1(url) {
395
- if (url.port) return Number.parseInt(url.port, 10);
396
- return url.protocol === "https:" ? 443 : 80;
437
+ /** `fetch()` also takes a Playwright `Request`. */
438
+ function requestUrl(input) {
439
+ return typeof input === "string" ? input : callIfFunction(input, "url") ?? String(input);
397
440
  }
398
- function errorType$1(error) {
399
- if (error instanceof Error && error.name) return error.name;
400
- return "Error";
441
+ function callIfFunction(target, name) {
442
+ const member = target?.[name];
443
+ if (typeof member !== "function") return;
444
+ const value = member.call(target);
445
+ return typeof value === "string" ? value : void 0;
401
446
  }
402
- function errorMessage$1(error) {
403
- return error instanceof Error && error.message ? error.message : void 0;
447
+ const STACK_FRAME_LOCATION = /^\s*at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
448
+ const PLAYWRIGHT_PACKAGE_FILE = /[/\\]node_modules[/\\](?:playwright|playwright-core|@playwright[/\\]test)[/\\]/;
449
+ /**
450
+ * Where the wrapped method was called from: the first frame below the wrapper
451
+ * that Playwright would also take as the step's location.
452
+ */
453
+ function callSite(rootDir) {
454
+ const stackTraceLimit = Error.stackTraceLimit;
455
+ Error.stackTraceLimit = Math.max(stackTraceLimit, 20);
456
+ const stack = (/* @__PURE__ */ new Error()).stack?.split("\n") ?? [];
457
+ Error.stackTraceLimit = stackTraceLimit;
458
+ const wrapperIndex = stack.findIndex((line) => line.includes(API_REQUEST_WRAPPER_FILE));
459
+ if (wrapperIndex === -1) return;
460
+ for (const line of stack.slice(wrapperIndex + 1)) {
461
+ const match = STACK_FRAME_LOCATION.exec(line);
462
+ if (!match) continue;
463
+ const file = match[1].startsWith("file://") ? fileURLToPath(match[1]) : match[1];
464
+ if (!path.isAbsolute(file) || PLAYWRIGHT_PACKAGE_FILE.test(file)) continue;
465
+ return {
466
+ file: path.relative(rootDir, file),
467
+ line: Number(match[2]),
468
+ column: Number(match[3])
469
+ };
470
+ }
471
+ }
472
+ /**
473
+ * Hands the recorded calls to the reporter, if anything keeps this test.
474
+ * Never rejects: a test must not fail because its requests couldn't be
475
+ * stored.
476
+ */
477
+ async function handOffApiRequests(requests, config, options) {
478
+ try {
479
+ const retainsTrace = (trace) => shouldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo);
480
+ const retained = config.storeTraceZip && retainsTrace(config.trace) || [config.otlpDestinations, config.playwrightTraceApiDestinations].some((destinations) => filterRetainedDestinations(destinations, config.trace, retainsTrace).length > 0);
481
+ if (requests.length === 0 || !retained) return;
482
+ const body = JSON.stringify({ requests });
483
+ if (config.attachFixtureData) {
484
+ await options.testInfo.attach(API_REQUESTS_ATTACHMENT_NAME, {
485
+ body,
486
+ contentType: "application/json"
487
+ });
488
+ return;
489
+ }
490
+ await writeFixtureHandoffFile(options.testInfo, API_REQUESTS_HANDOFF_FILE, body);
491
+ } catch (error) {
492
+ console.warn(`Failed to store API requests: ${error instanceof Error ? error.message : String(error)}`);
493
+ }
494
+ }
495
+ function isPromiseLike(value) {
496
+ return typeof value === "object" && value !== null && typeof value.then === "function";
497
+ }
498
+ function isWrapped(method) {
499
+ return method[WRAPPED] === true;
500
+ }
501
+ function markWrapped(wrapper) {
502
+ wrapper[WRAPPED] = true;
503
+ return wrapper;
404
504
  }
405
505
  //#endregion
406
506
  //#region src/fixture/reporter-config.ts
@@ -917,15 +1017,20 @@ const SPAN_STATUS_CODE_UNSET = 0;
917
1017
  const SPAN_STATUS_CODE_ERROR = 2;
918
1018
  let originalFetch;
919
1019
  let activeTraceContext;
920
- function runWithTestFetchCapture(traceContext, callback) {
1020
+ let propagateTraceHeaders = false;
1021
+ function runWithTestFetchCapture(traceContext, callback, options = {}) {
921
1022
  ensureFetchPatched();
922
- const previousTraceContext = activeTraceContext;
1023
+ const previous = {
1024
+ activeTraceContext,
1025
+ propagateTraceHeaders
1026
+ };
923
1027
  activeTraceContext = traceContext;
1028
+ propagateTraceHeaders = options.propagateTraceHeaders === true;
924
1029
  return (async () => {
925
1030
  try {
926
1031
  return await callback();
927
1032
  } finally {
928
- activeTraceContext = previousTraceContext;
1033
+ ({activeTraceContext, propagateTraceHeaders} = previous);
929
1034
  }
930
1035
  })();
931
1036
  }
@@ -938,10 +1043,13 @@ const patchedFetch = async (input, init) => {
938
1043
  const traceContext = activeTraceContext;
939
1044
  if (!traceContext) return originalFetch ? originalFetch(input, init) : globalThis.fetch(input, init);
940
1045
  if (!originalFetch) return globalThis.fetch(input, init);
1046
+ const spanId = generateSpanId();
1047
+ const sentInit = propagateTraceHeaders ? withTraceparent(input, init, traceparentHeader(traceContext.traceId, spanId)) : init;
941
1048
  const startTime = /* @__PURE__ */ new Date();
942
1049
  try {
943
- const response = await originalFetch(input, init);
1050
+ const response = await originalFetch(input, sentInit);
944
1051
  traceContext.addSpan(createFetchSpan({
1052
+ spanId,
945
1053
  input,
946
1054
  init,
947
1055
  traceContext,
@@ -954,6 +1062,7 @@ const patchedFetch = async (input, init) => {
954
1062
  return response;
955
1063
  } catch (error) {
956
1064
  traceContext.addSpan(createFetchSpan({
1065
+ spanId,
957
1066
  input,
958
1067
  init,
959
1068
  traceContext,
@@ -964,7 +1073,28 @@ const patchedFetch = async (input, init) => {
964
1073
  throw error;
965
1074
  }
966
1075
  };
967
- function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, contentType, cacheControl, error }) {
1076
+ /**
1077
+ * Keeps the kind of headers the test passed. Leaves a `traceparent` the test
1078
+ * set itself alone.
1079
+ */
1080
+ function withTraceparent(input, init, traceparent) {
1081
+ const existing = init?.headers ?? (input instanceof Request ? input.headers : void 0);
1082
+ if (new Headers(existing).has("traceparent")) return init;
1083
+ let headers;
1084
+ if (existing instanceof Headers) {
1085
+ headers = new Headers(existing);
1086
+ headers.set("traceparent", traceparent);
1087
+ } else if (Array.isArray(existing)) headers = [...existing, ["traceparent", traceparent]];
1088
+ else headers = {
1089
+ ...existing,
1090
+ traceparent
1091
+ };
1092
+ return {
1093
+ ...init,
1094
+ headers
1095
+ };
1096
+ }
1097
+ function createFetchSpan({ spanId, input, init, traceContext, startTime, endTime, statusCode, contentType, cacheControl, error }) {
968
1098
  const method = getFetchMethod(input, init);
969
1099
  const attributes = createHttpAttributes({
970
1100
  method,
@@ -977,7 +1107,7 @@ function createFetchSpan({ input, init, traceContext, startTime, endTime, status
977
1107
  const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
978
1108
  return {
979
1109
  traceId: traceContext.traceId,
980
- spanId: generateSpanId(),
1110
+ spanId,
981
1111
  parentSpanId: traceContext.rootSpanId,
982
1112
  name: `HTTP ${method}`,
983
1113
  kind: SPAN_KIND_CLIENT,
@@ -1042,11 +1172,19 @@ function createPlaywrightOtelTest(testBase) {
1042
1172
  scope: "worker",
1043
1173
  auto: true
1044
1174
  }],
1175
+ _playwrightOpentelemetryApiRequests: [async ({ playwright }, use) => {
1176
+ captureNewApiRequestContexts(playwright.request);
1177
+ await use();
1178
+ }, {
1179
+ scope: "worker",
1180
+ auto: true
1181
+ }],
1045
1182
  _playwrightOpentelemetryNewContexts: [async ({}, use) => {
1046
1183
  await use(/* @__PURE__ */ new Set());
1047
1184
  }, { scope: "worker" }],
1048
1185
  browser: [async ({ browser, _playwrightOpentelemetryNewContexts }, use) => {
1049
1186
  const onContext = (context) => {
1187
+ captureApiRequests(context.request);
1050
1188
  for (const listener of _playwrightOpentelemetryNewContexts) listener(context);
1051
1189
  };
1052
1190
  browser.on("context", onContext);
@@ -1063,16 +1201,29 @@ function createPlaywrightOtelTest(testBase) {
1063
1201
  testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
1064
1202
  const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
1065
1203
  const traceContext = await createTestTraceContext(testInfo, config);
1204
+ const apiRequests = startApiRequestRecording({
1205
+ rootDir: testInfo.config.rootDir,
1206
+ traceId: config.propagateTraceHeaders ? traceContext.traceId : void 0
1207
+ });
1066
1208
  const registration = registerExpectedTrace(traceContext, config, {
1067
1209
  trace,
1068
1210
  testInfo
1069
1211
  });
1070
- await runWithTestFetchCapture(traceContext, () => use(traceContext));
1212
+ let requests;
1213
+ try {
1214
+ await runWithTestFetchCapture(traceContext, () => use(traceContext), { propagateTraceHeaders: config.propagateTraceHeaders });
1215
+ } finally {
1216
+ requests = apiRequests.stop();
1217
+ }
1071
1218
  await registration;
1072
1219
  await flushFixtureSpans(traceContext, config, {
1073
1220
  trace,
1074
1221
  testInfo
1075
1222
  });
1223
+ await handOffApiRequests(requests, config, {
1224
+ trace,
1225
+ testInfo
1226
+ });
1076
1227
  }, { auto: true }],
1077
1228
  browserPageTracker: [async ({ testTraceContext }, use) => {
1078
1229
  const tracker = new BrowserPageTracker(testTraceContext);
@@ -1111,12 +1262,10 @@ function createPlaywrightOtelTest(testBase) {
1111
1262
  testInfo
1112
1263
  });
1113
1264
  }, { auto: true }],
1114
- request: async ({ request, testTraceContext }, use) => {
1115
- await use(createCapturedApiRequestContext(request, testTraceContext));
1116
- },
1117
1265
  context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker, screencastCapture }, use) => {
1118
1266
  const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
1119
1267
  screencastCapture?.addContext(context);
1268
+ captureApiRequests(context.request);
1120
1269
  const captureRequest = (request) => {
1121
1270
  browserPageTracker.startDocumentNavigation(request);
1122
1271
  const networkParent = browserPageTracker.getNetworkParent(request);
@@ -31,12 +31,12 @@ interface PlaywrightOpentelemetryConfig {
31
31
  */
32
32
  screenshots?: boolean;
33
33
  /**
34
- * Attach the fixture's data (trace context, fixture spans and screenshots)
35
- * to each test result, so it travels with blob reports and the reporter can
36
- * run in `merge-reports` instead of in the test run. Playwright then copies
37
- * that data into its own trace and HTML report. Defaults to false: the
38
- * fixture leaves it in the project's output directory for the reporter,
39
- * which must then run in the same test run.
34
+ * Attach the fixture's data (trace context, fixture spans, API requests and
35
+ * screenshots) to each test result, so it travels with blob reports and the
36
+ * reporter can run in `merge-reports` instead of in the test run. Playwright
37
+ * then copies that data into its own trace and HTML report. Defaults to
38
+ * false: the fixture leaves it in the project's output directory for the
39
+ * reporter, which must then run in the same test run.
40
40
  */
41
41
  attachFixtureData?: boolean;
42
42
  propagateTraceHeaders?: boolean;
@@ -31,12 +31,12 @@ interface PlaywrightOpentelemetryConfig {
31
31
  */
32
32
  screenshots?: boolean;
33
33
  /**
34
- * Attach the fixture's data (trace context, fixture spans and screenshots)
35
- * to each test result, so it travels with blob reports and the reporter can
36
- * run in `merge-reports` instead of in the test run. Playwright then copies
37
- * that data into its own trace and HTML report. Defaults to false: the
38
- * fixture leaves it in the project's output directory for the reporter,
39
- * which must then run in the same test run.
34
+ * Attach the fixture's data (trace context, fixture spans, API requests and
35
+ * screenshots) to each test result, so it travels with blob reports and the
36
+ * reporter can run in `merge-reports` instead of in the test run. Playwright
37
+ * then copies that data into its own trace and HTML report. Defaults to
38
+ * false: the fixture leaves it in the project's output directory for the
39
+ * reporter, which must then run in the same test run.
40
40
  */
41
41
  attachFixtureData?: boolean;
42
42
  propagateTraceHeaders?: boolean;
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/index.ts
2
- var src_default = require("./reporter-BuViICz8.cjs").PlaywrightOpentelemetryReporter;
2
+ var src_default = require("./reporter-DQ0vACOz.cjs").PlaywrightOpentelemetryReporter;
3
3
  //#endregion
4
4
  module.exports = src_default;
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-g9K4ZUC_.cjs";
2
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-C1TwRMjP.cjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-Ttd0SnXX.cjs";
2
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./index-48srAaol.cjs";
3
3
  export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryDestination, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, PlaywrightOpentelemetryReporter as default };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-g9K4ZUC_.mjs";
2
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-C1TwRMjP.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-Ttd0SnXX.mjs";
2
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./index-48srAaol.mjs";
3
3
  export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryDestination, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, PlaywrightOpentelemetryReporter as default };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-_CyyuDJs.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-CxtAJif2.mjs";
2
2
  //#region src/index.ts
3
3
  var src_default = PlaywrightOpentelemetryReporter;
4
4
  //#endregion