playwright-opentelemetry 0.18.2 → 0.19.1
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 +1 -1
- package/dist/{config-g9K4ZUC_.d.cts → config-48srAaol.d.cts} +6 -6
- package/dist/{config-g9K4ZUC_.d.mts → config-48srAaol.d.mts} +6 -6
- package/dist/fixture.cjs +268 -118
- package/dist/fixture.d.cts +2 -1
- package/dist/fixture.d.mts +2 -1
- package/dist/fixture.mjs +267 -118
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/{reporter-C1TwRMjP.d.cts → reporter-6ybjkG-e.d.cts} +1 -0
- package/dist/{reporter-C1TwRMjP.d.mts → reporter-6ybjkG-e.d.mts} +1 -0
- package/dist/{reporter-D4i206BM.cjs → reporter-BPtfG3Tk.cjs} +164 -14
- package/dist/{reporter-DKhFsfiL.mjs → reporter-BzA8_6iC.mjs} +164 -14
- package/dist/reporter.cjs +1 -1
- package/dist/reporter.d.cts +1 -1
- package/dist/reporter.d.mts +1 -1
- package/dist/reporter.mjs +1 -1
- package/dist/{screenshots-zip-DnK_MAtf.mjs → screenshots-zip-BjAJUhbe.mjs} +60 -4
- package/dist/{screenshots-zip-nJZiEIbI.cjs → screenshots-zip-DN7eCklk.cjs} +101 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Playwright test
|
|
|
19
19
|
```
|
|
20
20
|
|
|
21
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,
|
|
22
|
+
- The **fixture** records page navigations, browser requests, worker `fetch` activity, console messages, and uncaught page errors under a `playwright-browser` service, adds the response of each `request`, `page.request` or other `APIRequestContext` call to the step of that call, and injects into all of those requests the `traceparent` header that makes backend spans children of the test.
|
|
23
23
|
|
|
24
24
|
## Quick start
|
|
25
25
|
|
|
@@ -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
|
|
35
|
-
* to each test result, so it travels with blob reports and the
|
|
36
|
-
* run in `merge-reports` instead of in the test run. Playwright
|
|
37
|
-
* that data into its own trace and HTML report. Defaults to
|
|
38
|
-
* fixture leaves it in the project's output directory for the
|
|
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
|
|
35
|
-
* to each test result, so it travels with blob reports and the
|
|
36
|
-
* run in `merge-reports` instead of in the test run. Playwright
|
|
37
|
-
* that data into its own trace and HTML report. Defaults to
|
|
38
|
-
* fixture leaves it in the project's output directory for the
|
|
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/fixture.cjs
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_screenshots_zip = require("./screenshots-zip-
|
|
2
|
+
const require_screenshots_zip = require("./screenshots-zip-DN7eCklk.cjs");
|
|
3
3
|
let node_fs_promises = require("node:fs/promises");
|
|
4
4
|
node_fs_promises = require_screenshots_zip.__toESM(node_fs_promises, 1);
|
|
5
5
|
let node_path = require("node:path");
|
|
6
6
|
node_path = require_screenshots_zip.__toESM(node_path, 1);
|
|
7
7
|
let _playwright_test = require("@playwright/test");
|
|
8
|
+
let node_url = require("node:url");
|
|
9
|
+
let node_vm = require("node:vm");
|
|
10
|
+
node_vm = require_screenshots_zip.__toESM(node_vm, 1);
|
|
8
11
|
let node_os = require("node:os");
|
|
9
12
|
node_os = require_screenshots_zip.__toESM(node_os, 1);
|
|
10
13
|
//#region src/fixture/browser-page-tracker.ts
|
|
11
14
|
const BROWSER_PAGE_SPAN_NAME = "browser.page";
|
|
12
15
|
const BROWSER_ROUTE_SPAN_NAME = "browser.route";
|
|
13
|
-
const SPAN_STATUS_CODE_UNSET$
|
|
16
|
+
const SPAN_STATUS_CODE_UNSET$2 = 0;
|
|
14
17
|
var BrowserPageTracker = class {
|
|
15
18
|
traceContext;
|
|
16
19
|
nextPageId = 0;
|
|
@@ -182,7 +185,7 @@ var BrowserPageTracker = class {
|
|
|
182
185
|
name,
|
|
183
186
|
startTime,
|
|
184
187
|
endTime: startTime,
|
|
185
|
-
status: { code: SPAN_STATUS_CODE_UNSET$
|
|
188
|
+
status: { code: SPAN_STATUS_CODE_UNSET$2 },
|
|
186
189
|
attributes: pageAttributes({
|
|
187
190
|
pageId,
|
|
188
191
|
documentIndex,
|
|
@@ -274,18 +277,14 @@ function storeRequestTraceContext({ request, traceContext, parentSpanId, routeAs
|
|
|
274
277
|
* @param options - The propagator options
|
|
275
278
|
*/
|
|
276
279
|
async function propagateRouteTraceHeaders({ route, request, traceId, spanId }) {
|
|
277
|
-
const traceHeader = `00-${traceId}-${spanId}-01`;
|
|
278
280
|
await route.fallback({ headers: {
|
|
279
281
|
...request.headers(),
|
|
280
|
-
traceparent:
|
|
282
|
+
traceparent: require_screenshots_zip.traceparentHeader(traceId, spanId)
|
|
281
283
|
} });
|
|
282
284
|
}
|
|
283
285
|
//#endregion
|
|
284
286
|
//#region src/fixture/api-request-capture.ts
|
|
285
|
-
const
|
|
286
|
-
const SPAN_STATUS_CODE_UNSET$2 = 0;
|
|
287
|
-
const SPAN_STATUS_CODE_ERROR$2 = 2;
|
|
288
|
-
const CAPTURED_METHODS = new Set([
|
|
287
|
+
const CAPTURED_METHODS = [
|
|
289
288
|
"delete",
|
|
290
289
|
"fetch",
|
|
291
290
|
"get",
|
|
@@ -293,117 +292,219 @@ const CAPTURED_METHODS = new Set([
|
|
|
293
292
|
"patch",
|
|
294
293
|
"post",
|
|
295
294
|
"put"
|
|
296
|
-
]
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
295
|
+
];
|
|
296
|
+
const STATE_KEY = Symbol.for("playwright-opentelemetry.api-request-capture");
|
|
297
|
+
const WRAPPED = Symbol.for("playwright-opentelemetry.api-request-wrapper");
|
|
298
|
+
const state = globalThis[STATE_KEY] ??= { depth: 0 };
|
|
299
|
+
/**
|
|
300
|
+
* Wraps a Playwright method without changing where Playwright says the call
|
|
301
|
+
* came from. A step's location is the first stack frame outside Playwright,
|
|
302
|
+
* so a wrapper written in this file would become the location of every step
|
|
303
|
+
* it wraps. Playwright skips the frames of Node's own modules, and this
|
|
304
|
+
* wrapper is compiled with such a file name. `begin` and `end` are not on the
|
|
305
|
+
* stack while `original` runs.
|
|
306
|
+
*/
|
|
307
|
+
const createWrapper = node_vm.default.compileFunction(`return function (...args) {
|
|
308
|
+
const call = begin(args);
|
|
309
|
+
let result;
|
|
310
|
+
try {
|
|
311
|
+
result = Reflect.apply(original, this, args);
|
|
312
|
+
} catch (error) {
|
|
313
|
+
end(call, undefined);
|
|
314
|
+
throw error;
|
|
315
|
+
}
|
|
316
|
+
return end(call, result);
|
|
317
|
+
};`, [
|
|
318
|
+
"original",
|
|
319
|
+
"begin",
|
|
320
|
+
"end"
|
|
321
|
+
], { filename: require_screenshots_zip.API_REQUEST_WRAPPER_FILE });
|
|
322
|
+
/**
|
|
323
|
+
* Records the calls made on every `APIRequestContext` of this process, by
|
|
324
|
+
* wrapping the methods of the class they share. The test still gets
|
|
325
|
+
* Playwright's own objects. Does nothing while no recording is active.
|
|
326
|
+
*/
|
|
327
|
+
function captureApiRequests(requestContext) {
|
|
328
|
+
try {
|
|
329
|
+
wrapRequestMethods(requestContext);
|
|
330
|
+
} catch {}
|
|
331
|
+
}
|
|
332
|
+
function wrapRequestMethods(requestContext) {
|
|
333
|
+
const prototype = Object.getPrototypeOf(requestContext);
|
|
334
|
+
if (!prototype || prototype === Object.prototype) return;
|
|
335
|
+
for (const methodName of CAPTURED_METHODS) {
|
|
336
|
+
const original = prototype[methodName];
|
|
337
|
+
if (typeof original !== "function" || isWrapped(original)) continue;
|
|
338
|
+
prototype[methodName] = markWrapped(createWrapper(original, (args) => beginCall(methodName, args), endCall));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* The class of `APIRequestContext` can only be reached through an instance:
|
|
343
|
+
* finds it when `playwright.request.newContext()` creates the first one, which
|
|
344
|
+
* is also how Playwright creates the `request` fixture.
|
|
345
|
+
*/
|
|
346
|
+
function captureNewApiRequestContexts(apiRequest) {
|
|
347
|
+
const target = apiRequest;
|
|
348
|
+
const original = target.newContext;
|
|
349
|
+
if (typeof original !== "function" || isWrapped(original)) return;
|
|
350
|
+
target.newContext = markWrapped(createWrapper(original, () => void 0, (_call, result) => {
|
|
351
|
+
if (!isPromiseLike(result)) return result;
|
|
352
|
+
return result.then((requestContext) => {
|
|
353
|
+
captureApiRequests(requestContext);
|
|
354
|
+
return requestContext;
|
|
355
|
+
});
|
|
356
|
+
}));
|
|
357
|
+
}
|
|
358
|
+
function startApiRequestRecording(options) {
|
|
359
|
+
const recording = {
|
|
360
|
+
...options,
|
|
361
|
+
requests: []
|
|
362
|
+
};
|
|
363
|
+
const previous = state.recording;
|
|
364
|
+
state.recording = recording;
|
|
365
|
+
return { stop() {
|
|
366
|
+
if (state.recording === recording) state.recording = previous;
|
|
367
|
+
return recording.requests;
|
|
368
|
+
} };
|
|
369
|
+
}
|
|
370
|
+
function beginCall(methodName, args) {
|
|
371
|
+
state.depth++;
|
|
372
|
+
const recording = state.recording;
|
|
373
|
+
if (state.depth > 1 || !recording) return;
|
|
374
|
+
try {
|
|
375
|
+
const call = {
|
|
376
|
+
method: requestMethod(methodName, args),
|
|
377
|
+
url: requestUrl(args[0]),
|
|
378
|
+
startTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
379
|
+
location: callSite(recording.rootDir)
|
|
327
380
|
};
|
|
328
|
-
|
|
381
|
+
if (recording.traceId) {
|
|
382
|
+
const spanId = require_screenshots_zip.generateSpanId();
|
|
383
|
+
if (addTraceparent(args, require_screenshots_zip.traceparentHeader(recording.traceId, spanId))) call.spanId = spanId;
|
|
384
|
+
}
|
|
385
|
+
recording.requests.push(call);
|
|
386
|
+
return call;
|
|
387
|
+
} catch {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
329
390
|
}
|
|
330
|
-
function
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
391
|
+
function endCall(call, result) {
|
|
392
|
+
state.depth--;
|
|
393
|
+
if (!call || !isPromiseLike(result)) return result;
|
|
394
|
+
return result.then((response) => {
|
|
395
|
+
recordResponse(call, response);
|
|
396
|
+
return response;
|
|
397
|
+
}, (error) => {
|
|
398
|
+
call.endTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
399
|
+
call.errorType = error instanceof Error && error.name ? error.name : "Error";
|
|
400
|
+
throw error;
|
|
338
401
|
});
|
|
339
|
-
const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
|
|
340
|
-
return {
|
|
341
|
-
traceId: traceContext.traceId,
|
|
342
|
-
spanId: require_screenshots_zip.generateSpanId(),
|
|
343
|
-
parentSpanId: traceContext.rootSpanId,
|
|
344
|
-
name: `HTTP ${method}`,
|
|
345
|
-
kind: SPAN_KIND_CLIENT$2,
|
|
346
|
-
startTime,
|
|
347
|
-
endTime,
|
|
348
|
-
status: failed ? {
|
|
349
|
-
code: SPAN_STATUS_CODE_ERROR$2,
|
|
350
|
-
message: errorMessage$1(error)
|
|
351
|
-
} : { code: SPAN_STATUS_CODE_UNSET$2 },
|
|
352
|
-
attributes,
|
|
353
|
-
events: []
|
|
354
|
-
};
|
|
355
402
|
}
|
|
356
|
-
function
|
|
357
|
-
|
|
358
|
-
"http.request.method": method,
|
|
359
|
-
"http.resource.type": "fetch",
|
|
360
|
-
"playwright.request.api": true,
|
|
361
|
-
"url.full": url
|
|
362
|
-
};
|
|
403
|
+
function recordResponse(call, response) {
|
|
404
|
+
call.endTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
363
405
|
try {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
406
|
+
call.statusCode = response.status();
|
|
407
|
+
call.responseUrl = response.url();
|
|
408
|
+
const headers = response.headers();
|
|
409
|
+
const recorded = {};
|
|
410
|
+
for (const name of require_screenshots_zip.RECORDED_RESPONSE_HEADERS) if (typeof headers[name] === "string") recorded[name] = headers[name];
|
|
411
|
+
call.responseHeaders = recorded;
|
|
369
412
|
} catch {}
|
|
370
|
-
if (statusCode !== void 0) {
|
|
371
|
-
attributes["http.response.status_code"] = statusCode;
|
|
372
|
-
if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
|
|
373
|
-
} else if (error !== void 0) attributes["error.type"] = errorType$1(error);
|
|
374
|
-
const contentType = responseHeaders?.["content-type"];
|
|
375
|
-
const cacheControl = responseHeaders?.["cache-control"];
|
|
376
|
-
if (contentType) attributes["http.response.header.content-type"] = [contentType];
|
|
377
|
-
if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
|
|
378
|
-
return attributes;
|
|
379
413
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
414
|
+
/**
|
|
415
|
+
* Adds the header to the call's options, which `args` holds and Playwright is
|
|
416
|
+
* about to be called with. Leaves a `traceparent` the test set itself alone.
|
|
417
|
+
*/
|
|
418
|
+
function addTraceparent(args, traceparent) {
|
|
419
|
+
const options = args[1];
|
|
420
|
+
if (options !== void 0 && (typeof options !== "object" || !options)) return false;
|
|
421
|
+
const headers = options?.headers ?? (typeof args[0] === "string" ? {} : requestHeaders(args[0]));
|
|
422
|
+
if (typeof headers !== "object" || headers === null || Object.keys(headers).some((name) => name.toLowerCase() === "traceparent")) return false;
|
|
423
|
+
args[1] = {
|
|
424
|
+
...options,
|
|
425
|
+
headers: {
|
|
426
|
+
...headers,
|
|
427
|
+
traceparent
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
return true;
|
|
387
431
|
}
|
|
388
|
-
function
|
|
389
|
-
|
|
390
|
-
return
|
|
432
|
+
function requestHeaders(input) {
|
|
433
|
+
const headers = input?.headers;
|
|
434
|
+
return typeof headers === "function" ? headers.call(input) : void 0;
|
|
391
435
|
}
|
|
392
|
-
function
|
|
393
|
-
if (
|
|
394
|
-
const
|
|
395
|
-
return typeof method === "string" ?
|
|
436
|
+
function requestMethod(methodName, args) {
|
|
437
|
+
if (methodName !== "fetch") return methodName.toUpperCase();
|
|
438
|
+
const options = args[1];
|
|
439
|
+
return (typeof options?.method === "string" ? options.method : callIfFunction(args[0], "method") ?? "GET").toUpperCase();
|
|
396
440
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
return
|
|
441
|
+
/** `fetch()` also takes a Playwright `Request`. */
|
|
442
|
+
function requestUrl(input) {
|
|
443
|
+
return typeof input === "string" ? input : callIfFunction(input, "url") ?? String(input);
|
|
400
444
|
}
|
|
401
|
-
function
|
|
402
|
-
|
|
403
|
-
|
|
445
|
+
function callIfFunction(target, name) {
|
|
446
|
+
const member = target?.[name];
|
|
447
|
+
if (typeof member !== "function") return;
|
|
448
|
+
const value = member.call(target);
|
|
449
|
+
return typeof value === "string" ? value : void 0;
|
|
404
450
|
}
|
|
405
|
-
|
|
406
|
-
|
|
451
|
+
const STACK_FRAME_LOCATION = /^\s*at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
452
|
+
const PLAYWRIGHT_PACKAGE_FILE = /[/\\]node_modules[/\\](?:playwright|playwright-core|@playwright[/\\]test)[/\\]/;
|
|
453
|
+
/**
|
|
454
|
+
* Where the wrapped method was called from: the first frame below the wrapper
|
|
455
|
+
* that Playwright would also take as the step's location.
|
|
456
|
+
*/
|
|
457
|
+
function callSite(rootDir) {
|
|
458
|
+
const stackTraceLimit = Error.stackTraceLimit;
|
|
459
|
+
Error.stackTraceLimit = Math.max(stackTraceLimit, 20);
|
|
460
|
+
const stack = (/* @__PURE__ */ new Error()).stack?.split("\n") ?? [];
|
|
461
|
+
Error.stackTraceLimit = stackTraceLimit;
|
|
462
|
+
const wrapperIndex = stack.findIndex((line) => line.includes(require_screenshots_zip.API_REQUEST_WRAPPER_FILE));
|
|
463
|
+
if (wrapperIndex === -1) return;
|
|
464
|
+
for (const line of stack.slice(wrapperIndex + 1)) {
|
|
465
|
+
const match = STACK_FRAME_LOCATION.exec(line);
|
|
466
|
+
if (!match) continue;
|
|
467
|
+
const file = match[1].startsWith("file://") ? (0, node_url.fileURLToPath)(match[1]) : match[1];
|
|
468
|
+
if (!node_path.default.isAbsolute(file) || PLAYWRIGHT_PACKAGE_FILE.test(file)) continue;
|
|
469
|
+
return {
|
|
470
|
+
file: node_path.default.relative(rootDir, file),
|
|
471
|
+
line: Number(match[2]),
|
|
472
|
+
column: Number(match[3])
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Hands the recorded calls to the reporter, if anything keeps this test.
|
|
478
|
+
* Never rejects: a test must not fail because its requests couldn't be
|
|
479
|
+
* stored.
|
|
480
|
+
*/
|
|
481
|
+
async function handOffApiRequests(requests, config, options) {
|
|
482
|
+
try {
|
|
483
|
+
const retainsTrace = (trace) => require_screenshots_zip.shouldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo);
|
|
484
|
+
const retained = config.storeTraceZip && retainsTrace(config.trace) || [config.otlpDestinations, config.playwrightTraceApiDestinations].some((destinations) => require_screenshots_zip.filterRetainedDestinations(destinations, config.trace, retainsTrace).length > 0);
|
|
485
|
+
if (requests.length === 0 || !retained) return;
|
|
486
|
+
const body = JSON.stringify({ requests });
|
|
487
|
+
if (config.attachFixtureData) {
|
|
488
|
+
await options.testInfo.attach(require_screenshots_zip.API_REQUESTS_ATTACHMENT_NAME, {
|
|
489
|
+
body,
|
|
490
|
+
contentType: "application/json"
|
|
491
|
+
});
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
await require_screenshots_zip.writeFixtureHandoffFile(options.testInfo, require_screenshots_zip.API_REQUESTS_HANDOFF_FILE, body);
|
|
495
|
+
} catch (error) {
|
|
496
|
+
console.warn(`Failed to store API requests: ${error instanceof Error ? error.message : String(error)}`);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
function isPromiseLike(value) {
|
|
500
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
501
|
+
}
|
|
502
|
+
function isWrapped(method) {
|
|
503
|
+
return method[WRAPPED] === true;
|
|
504
|
+
}
|
|
505
|
+
function markWrapped(wrapper) {
|
|
506
|
+
wrapper[WRAPPED] = true;
|
|
507
|
+
return wrapper;
|
|
407
508
|
}
|
|
408
509
|
//#endregion
|
|
409
510
|
//#region src/fixture/reporter-config.ts
|
|
@@ -920,15 +1021,20 @@ const SPAN_STATUS_CODE_UNSET = 0;
|
|
|
920
1021
|
const SPAN_STATUS_CODE_ERROR = 2;
|
|
921
1022
|
let originalFetch;
|
|
922
1023
|
let activeTraceContext;
|
|
923
|
-
|
|
1024
|
+
let propagateTraceHeaders = false;
|
|
1025
|
+
function runWithTestFetchCapture(traceContext, callback, options = {}) {
|
|
924
1026
|
ensureFetchPatched();
|
|
925
|
-
const
|
|
1027
|
+
const previous = {
|
|
1028
|
+
activeTraceContext,
|
|
1029
|
+
propagateTraceHeaders
|
|
1030
|
+
};
|
|
926
1031
|
activeTraceContext = traceContext;
|
|
1032
|
+
propagateTraceHeaders = options.propagateTraceHeaders === true;
|
|
927
1033
|
return (async () => {
|
|
928
1034
|
try {
|
|
929
1035
|
return await callback();
|
|
930
1036
|
} finally {
|
|
931
|
-
activeTraceContext =
|
|
1037
|
+
({activeTraceContext, propagateTraceHeaders} = previous);
|
|
932
1038
|
}
|
|
933
1039
|
})();
|
|
934
1040
|
}
|
|
@@ -941,10 +1047,13 @@ const patchedFetch = async (input, init) => {
|
|
|
941
1047
|
const traceContext = activeTraceContext;
|
|
942
1048
|
if (!traceContext) return originalFetch ? originalFetch(input, init) : globalThis.fetch(input, init);
|
|
943
1049
|
if (!originalFetch) return globalThis.fetch(input, init);
|
|
1050
|
+
const spanId = require_screenshots_zip.generateSpanId();
|
|
1051
|
+
const sentInit = propagateTraceHeaders ? withTraceparent(input, init, require_screenshots_zip.traceparentHeader(traceContext.traceId, spanId)) : init;
|
|
944
1052
|
const startTime = /* @__PURE__ */ new Date();
|
|
945
1053
|
try {
|
|
946
|
-
const response = await originalFetch(input,
|
|
1054
|
+
const response = await originalFetch(input, sentInit);
|
|
947
1055
|
traceContext.addSpan(createFetchSpan({
|
|
1056
|
+
spanId,
|
|
948
1057
|
input,
|
|
949
1058
|
init,
|
|
950
1059
|
traceContext,
|
|
@@ -957,6 +1066,7 @@ const patchedFetch = async (input, init) => {
|
|
|
957
1066
|
return response;
|
|
958
1067
|
} catch (error) {
|
|
959
1068
|
traceContext.addSpan(createFetchSpan({
|
|
1069
|
+
spanId,
|
|
960
1070
|
input,
|
|
961
1071
|
init,
|
|
962
1072
|
traceContext,
|
|
@@ -967,7 +1077,28 @@ const patchedFetch = async (input, init) => {
|
|
|
967
1077
|
throw error;
|
|
968
1078
|
}
|
|
969
1079
|
};
|
|
970
|
-
|
|
1080
|
+
/**
|
|
1081
|
+
* Keeps the kind of headers the test passed. Leaves a `traceparent` the test
|
|
1082
|
+
* set itself alone.
|
|
1083
|
+
*/
|
|
1084
|
+
function withTraceparent(input, init, traceparent) {
|
|
1085
|
+
const existing = init?.headers ?? (input instanceof Request ? input.headers : void 0);
|
|
1086
|
+
if (new Headers(existing).has("traceparent")) return init;
|
|
1087
|
+
let headers;
|
|
1088
|
+
if (existing instanceof Headers) {
|
|
1089
|
+
headers = new Headers(existing);
|
|
1090
|
+
headers.set("traceparent", traceparent);
|
|
1091
|
+
} else if (Array.isArray(existing)) headers = [...existing, ["traceparent", traceparent]];
|
|
1092
|
+
else headers = {
|
|
1093
|
+
...existing,
|
|
1094
|
+
traceparent
|
|
1095
|
+
};
|
|
1096
|
+
return {
|
|
1097
|
+
...init,
|
|
1098
|
+
headers
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
function createFetchSpan({ spanId, input, init, traceContext, startTime, endTime, statusCode, contentType, cacheControl, error }) {
|
|
971
1102
|
const method = getFetchMethod(input, init);
|
|
972
1103
|
const attributes = createHttpAttributes({
|
|
973
1104
|
method,
|
|
@@ -980,7 +1111,7 @@ function createFetchSpan({ input, init, traceContext, startTime, endTime, status
|
|
|
980
1111
|
const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
|
|
981
1112
|
return {
|
|
982
1113
|
traceId: traceContext.traceId,
|
|
983
|
-
spanId
|
|
1114
|
+
spanId,
|
|
984
1115
|
parentSpanId: traceContext.rootSpanId,
|
|
985
1116
|
name: `HTTP ${method}`,
|
|
986
1117
|
kind: SPAN_KIND_CLIENT,
|
|
@@ -1045,11 +1176,19 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
1045
1176
|
scope: "worker",
|
|
1046
1177
|
auto: true
|
|
1047
1178
|
}],
|
|
1179
|
+
_playwrightOpentelemetryApiRequests: [async ({ playwright }, use) => {
|
|
1180
|
+
captureNewApiRequestContexts(playwright.request);
|
|
1181
|
+
await use();
|
|
1182
|
+
}, {
|
|
1183
|
+
scope: "worker",
|
|
1184
|
+
auto: true
|
|
1185
|
+
}],
|
|
1048
1186
|
_playwrightOpentelemetryNewContexts: [async ({}, use) => {
|
|
1049
1187
|
await use(/* @__PURE__ */ new Set());
|
|
1050
1188
|
}, { scope: "worker" }],
|
|
1051
1189
|
browser: [async ({ browser, _playwrightOpentelemetryNewContexts }, use) => {
|
|
1052
1190
|
const onContext = (context) => {
|
|
1191
|
+
captureApiRequests(context.request);
|
|
1053
1192
|
for (const listener of _playwrightOpentelemetryNewContexts) listener(context);
|
|
1054
1193
|
};
|
|
1055
1194
|
browser.on("context", onContext);
|
|
@@ -1066,16 +1205,29 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
1066
1205
|
testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
|
|
1067
1206
|
const config = require_screenshots_zip.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
1068
1207
|
const traceContext = await require_screenshots_zip.createTestTraceContext(testInfo, config);
|
|
1208
|
+
const apiRequests = startApiRequestRecording({
|
|
1209
|
+
rootDir: testInfo.config.rootDir,
|
|
1210
|
+
traceId: config.propagateTraceHeaders ? traceContext.traceId : void 0
|
|
1211
|
+
});
|
|
1069
1212
|
const registration = require_screenshots_zip.registerExpectedTrace(traceContext, config, {
|
|
1070
1213
|
trace,
|
|
1071
1214
|
testInfo
|
|
1072
1215
|
});
|
|
1073
|
-
|
|
1216
|
+
let requests;
|
|
1217
|
+
try {
|
|
1218
|
+
await runWithTestFetchCapture(traceContext, () => use(traceContext), { propagateTraceHeaders: config.propagateTraceHeaders });
|
|
1219
|
+
} finally {
|
|
1220
|
+
requests = apiRequests.stop();
|
|
1221
|
+
}
|
|
1074
1222
|
await registration;
|
|
1075
1223
|
await require_screenshots_zip.flushFixtureSpans(traceContext, config, {
|
|
1076
1224
|
trace,
|
|
1077
1225
|
testInfo
|
|
1078
1226
|
});
|
|
1227
|
+
await handOffApiRequests(requests, config, {
|
|
1228
|
+
trace,
|
|
1229
|
+
testInfo
|
|
1230
|
+
});
|
|
1079
1231
|
}, { auto: true }],
|
|
1080
1232
|
browserPageTracker: [async ({ testTraceContext }, use) => {
|
|
1081
1233
|
const tracker = new BrowserPageTracker(testTraceContext);
|
|
@@ -1114,12 +1266,10 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
1114
1266
|
testInfo
|
|
1115
1267
|
});
|
|
1116
1268
|
}, { auto: true }],
|
|
1117
|
-
request: async ({ request, testTraceContext }, use) => {
|
|
1118
|
-
await use(createCapturedApiRequestContext(request, testTraceContext));
|
|
1119
|
-
},
|
|
1120
1269
|
context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker, screencastCapture }, use) => {
|
|
1121
1270
|
const config = require_screenshots_zip.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
1122
1271
|
screencastCapture?.addContext(context);
|
|
1272
|
+
captureApiRequests(context.request);
|
|
1123
1273
|
const captureRequest = (request) => {
|
|
1124
1274
|
browserPageTracker.startDocumentNavigation(request);
|
|
1125
1275
|
const networkParent = browserPageTracker.getNetworkParent(request);
|
package/dist/fixture.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
1
|
+
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-48srAaol.cjs";
|
|
2
2
|
import { n as SpanEvent, t as Span } from "./otel-D0ztpic2.cjs";
|
|
3
3
|
import { BrowserContext, ConsoleMessage, Page, Request } from "@playwright/test";
|
|
4
4
|
export * from "@playwright/test";
|
|
@@ -108,6 +108,7 @@ declare const test: import("@playwright/test").TestType<import("@playwright/test
|
|
|
108
108
|
screencastCapture: ScreencastCapture | undefined;
|
|
109
109
|
}, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions & {
|
|
110
110
|
_playwrightOpentelemetryReporterCheck: void;
|
|
111
|
+
_playwrightOpentelemetryApiRequests: void;
|
|
111
112
|
_playwrightOpentelemetryNewContexts: Set<(context: import("@playwright/test").BrowserContext) => void>;
|
|
112
113
|
}>;
|
|
113
114
|
//#endregion
|
package/dist/fixture.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
1
|
+
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-48srAaol.mjs";
|
|
2
2
|
import { n as SpanEvent, t as Span } from "./otel-D0ztpic2.mjs";
|
|
3
3
|
import { BrowserContext, ConsoleMessage, Page, Request } from "@playwright/test";
|
|
4
4
|
export * from "@playwright/test";
|
|
@@ -108,6 +108,7 @@ declare const test: import("@playwright/test").TestType<import("@playwright/test
|
|
|
108
108
|
screencastCapture: ScreencastCapture | undefined;
|
|
109
109
|
}, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions & {
|
|
110
110
|
_playwrightOpentelemetryReporterCheck: void;
|
|
111
|
+
_playwrightOpentelemetryApiRequests: void;
|
|
111
112
|
_playwrightOpentelemetryNewContexts: Set<(context: import("@playwright/test").BrowserContext) => void>;
|
|
112
113
|
}>;
|
|
113
114
|
//#endregion
|