playwright-opentelemetry 0.12.1 → 0.13.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/README.md +81 -3
- package/dist/{config-CoP8kphA.mjs → config-ChGo0Y1S.mjs} +1 -1
- package/dist/{config-CE5ph46B.cjs → config-DTMVyy76.cjs} +1 -1
- package/dist/fixture.cjs +27 -10
- package/dist/fixture.mjs +27 -10
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{reporter-C5uzPmZH.cjs → reporter--8bw74PI.cjs} +36 -29
- package/dist/{reporter-CeFtIXbG.mjs → reporter-CgzB0Kq8.mjs} +36 -29
- package/dist/reporter.cjs +1 -1
- package/dist/reporter.mjs +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,11 +1,89 @@
|
|
|
1
|
-
#
|
|
1
|
+
# playwright-opentelemetry
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Trace your Playwright tests across the entire stack.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/playwright-opentelemetry)
|
|
6
|
+
[](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
|
+

|
|
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.
|
|
24
|
+
var version = "0.13.0";
|
|
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) {
|
package/dist/fixture.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_config = require("./config-
|
|
2
|
+
const require_config = require("./config-DTMVyy76.cjs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
node_path = require_config.__toESM(node_path, 1);
|
|
5
5
|
let _playwright_test = require("@playwright/test");
|
|
@@ -291,7 +291,8 @@ function createCapturedApiRequestContext(request, traceContext) {
|
|
|
291
291
|
traceContext,
|
|
292
292
|
startTime,
|
|
293
293
|
endTime: /* @__PURE__ */ new Date(),
|
|
294
|
-
statusCode: response.status()
|
|
294
|
+
statusCode: response.status(),
|
|
295
|
+
responseHeaders: response.headers()
|
|
295
296
|
}));
|
|
296
297
|
return response;
|
|
297
298
|
} catch (error) {
|
|
@@ -308,12 +309,13 @@ function createCapturedApiRequestContext(request, traceContext) {
|
|
|
308
309
|
};
|
|
309
310
|
} });
|
|
310
311
|
}
|
|
311
|
-
function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, error }) {
|
|
312
|
+
function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, responseHeaders, error }) {
|
|
312
313
|
const method = getRequestMethod(methodName, args);
|
|
313
314
|
const attributes = createHttpAttributes$1({
|
|
314
315
|
method,
|
|
315
316
|
url: getRequestUrl(args[0]),
|
|
316
317
|
statusCode,
|
|
318
|
+
responseHeaders,
|
|
317
319
|
error
|
|
318
320
|
});
|
|
319
321
|
const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
|
|
@@ -333,7 +335,7 @@ function createApiRequestSpan({ methodName, args, traceContext, startTime, endTi
|
|
|
333
335
|
events: []
|
|
334
336
|
};
|
|
335
337
|
}
|
|
336
|
-
function createHttpAttributes$1({ method, url, statusCode, error }) {
|
|
338
|
+
function createHttpAttributes$1({ method, url, statusCode, responseHeaders, error }) {
|
|
337
339
|
const attributes = {
|
|
338
340
|
"http.request.method": method,
|
|
339
341
|
"http.resource.type": "fetch",
|
|
@@ -351,6 +353,10 @@ function createHttpAttributes$1({ method, url, statusCode, error }) {
|
|
|
351
353
|
attributes["http.response.status_code"] = statusCode;
|
|
352
354
|
if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
|
|
353
355
|
} else if (error !== void 0) attributes["error.type"] = errorType$1(error);
|
|
356
|
+
const contentType = responseHeaders?.["content-type"];
|
|
357
|
+
const cacheControl = responseHeaders?.["cache-control"];
|
|
358
|
+
if (contentType) attributes["http.response.header.content-type"] = [contentType];
|
|
359
|
+
if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
|
|
354
360
|
return attributes;
|
|
355
361
|
}
|
|
356
362
|
function getRequestMethod(methodName, args) {
|
|
@@ -478,7 +484,10 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
|
|
|
478
484
|
const serverPort = parsedUrl.port !== "" ? Number.parseInt(parsedUrl.port, 10) : parsedUrl.protocol === "https:" ? 443 : 80;
|
|
479
485
|
let statusCodeValue = SPAN_STATUS_CODE_UNSET$1;
|
|
480
486
|
if (statusCode >= 400) statusCodeValue = SPAN_STATUS_CODE_ERROR$1;
|
|
481
|
-
const
|
|
487
|
+
const responseHeaders = await getResponseHeaders(response);
|
|
488
|
+
const contentType = responseHeaders?.["content-type"] ?? null;
|
|
489
|
+
const cacheControl = responseHeaders?.["cache-control"];
|
|
490
|
+
const resourceType = detectResourceType(contentType, url);
|
|
482
491
|
const attributes = {
|
|
483
492
|
"http.request.method": method,
|
|
484
493
|
"url.full": url,
|
|
@@ -490,6 +499,8 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
|
|
|
490
499
|
"browser.request.route_association": requestTraceContext.routeAssociation
|
|
491
500
|
};
|
|
492
501
|
if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
|
|
502
|
+
if (contentType) attributes["http.response.header.content-type"] = [contentType];
|
|
503
|
+
if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
|
|
493
504
|
if (statusCodeValue === SPAN_STATUS_CODE_ERROR$1) attributes["error.type"] = statusCode.toString();
|
|
494
505
|
const networkSpan = {
|
|
495
506
|
traceId: requestTraceContext.traceId,
|
|
@@ -506,9 +517,9 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
|
|
|
506
517
|
};
|
|
507
518
|
traceContext.addSpan(networkSpan);
|
|
508
519
|
}
|
|
509
|
-
async function
|
|
520
|
+
async function getResponseHeaders(response) {
|
|
510
521
|
try {
|
|
511
|
-
return await response.
|
|
522
|
+
return await response.allHeaders();
|
|
512
523
|
} catch {
|
|
513
524
|
return null;
|
|
514
525
|
}
|
|
@@ -550,7 +561,9 @@ const patchedFetch = async (input, init) => {
|
|
|
550
561
|
traceContext,
|
|
551
562
|
startTime,
|
|
552
563
|
endTime: /* @__PURE__ */ new Date(),
|
|
553
|
-
statusCode: response.status
|
|
564
|
+
statusCode: response.status,
|
|
565
|
+
contentType: response.headers.get("content-type"),
|
|
566
|
+
cacheControl: response.headers.get("cache-control")
|
|
554
567
|
}));
|
|
555
568
|
return response;
|
|
556
569
|
} catch (error) {
|
|
@@ -565,12 +578,14 @@ const patchedFetch = async (input, init) => {
|
|
|
565
578
|
throw error;
|
|
566
579
|
}
|
|
567
580
|
};
|
|
568
|
-
function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, error }) {
|
|
581
|
+
function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, contentType, cacheControl, error }) {
|
|
569
582
|
const method = getFetchMethod(input, init);
|
|
570
583
|
const attributes = createHttpAttributes({
|
|
571
584
|
method,
|
|
572
585
|
url: getFetchUrl(input),
|
|
573
586
|
statusCode,
|
|
587
|
+
contentType,
|
|
588
|
+
cacheControl,
|
|
574
589
|
error
|
|
575
590
|
});
|
|
576
591
|
const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
|
|
@@ -590,7 +605,7 @@ function createFetchSpan({ input, init, traceContext, startTime, endTime, status
|
|
|
590
605
|
events: []
|
|
591
606
|
};
|
|
592
607
|
}
|
|
593
|
-
function createHttpAttributes({ method, url, statusCode, error }) {
|
|
608
|
+
function createHttpAttributes({ method, url, statusCode, contentType, cacheControl, error }) {
|
|
594
609
|
const attributes = {
|
|
595
610
|
"http.request.method": method,
|
|
596
611
|
"http.resource.type": "fetch",
|
|
@@ -607,6 +622,8 @@ function createHttpAttributes({ method, url, statusCode, error }) {
|
|
|
607
622
|
attributes["http.response.status_code"] = statusCode;
|
|
608
623
|
if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
|
|
609
624
|
} else if (error !== void 0) attributes["error.type"] = errorType(error);
|
|
625
|
+
if (contentType) attributes["http.response.header.content-type"] = [contentType];
|
|
626
|
+
if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
|
|
610
627
|
return attributes;
|
|
611
628
|
}
|
|
612
629
|
function getFetchMethod(input, init) {
|
package/dist/fixture.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as createTestTraceContext, n as BROWSER_SERVICE_NAME, o as flushFixtureSpans, p as generateSpanId, s as registerExpectedTrace, t as resolvePlaywrightOpentelemetryConfig } from "./config-
|
|
1
|
+
import { a as createTestTraceContext, n as BROWSER_SERVICE_NAME, o as flushFixtureSpans, p as generateSpanId, s as registerExpectedTrace, t as resolvePlaywrightOpentelemetryConfig } from "./config-ChGo0Y1S.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { test as test$1 } from "@playwright/test";
|
|
4
4
|
export * from "@playwright/test";
|
|
@@ -290,7 +290,8 @@ function createCapturedApiRequestContext(request, traceContext) {
|
|
|
290
290
|
traceContext,
|
|
291
291
|
startTime,
|
|
292
292
|
endTime: /* @__PURE__ */ new Date(),
|
|
293
|
-
statusCode: response.status()
|
|
293
|
+
statusCode: response.status(),
|
|
294
|
+
responseHeaders: response.headers()
|
|
294
295
|
}));
|
|
295
296
|
return response;
|
|
296
297
|
} catch (error) {
|
|
@@ -307,12 +308,13 @@ function createCapturedApiRequestContext(request, traceContext) {
|
|
|
307
308
|
};
|
|
308
309
|
} });
|
|
309
310
|
}
|
|
310
|
-
function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, error }) {
|
|
311
|
+
function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, responseHeaders, error }) {
|
|
311
312
|
const method = getRequestMethod(methodName, args);
|
|
312
313
|
const attributes = createHttpAttributes$1({
|
|
313
314
|
method,
|
|
314
315
|
url: getRequestUrl(args[0]),
|
|
315
316
|
statusCode,
|
|
317
|
+
responseHeaders,
|
|
316
318
|
error
|
|
317
319
|
});
|
|
318
320
|
const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
|
|
@@ -332,7 +334,7 @@ function createApiRequestSpan({ methodName, args, traceContext, startTime, endTi
|
|
|
332
334
|
events: []
|
|
333
335
|
};
|
|
334
336
|
}
|
|
335
|
-
function createHttpAttributes$1({ method, url, statusCode, error }) {
|
|
337
|
+
function createHttpAttributes$1({ method, url, statusCode, responseHeaders, error }) {
|
|
336
338
|
const attributes = {
|
|
337
339
|
"http.request.method": method,
|
|
338
340
|
"http.resource.type": "fetch",
|
|
@@ -350,6 +352,10 @@ function createHttpAttributes$1({ method, url, statusCode, error }) {
|
|
|
350
352
|
attributes["http.response.status_code"] = statusCode;
|
|
351
353
|
if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
|
|
352
354
|
} else if (error !== void 0) attributes["error.type"] = errorType$1(error);
|
|
355
|
+
const contentType = responseHeaders?.["content-type"];
|
|
356
|
+
const cacheControl = responseHeaders?.["cache-control"];
|
|
357
|
+
if (contentType) attributes["http.response.header.content-type"] = [contentType];
|
|
358
|
+
if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
|
|
353
359
|
return attributes;
|
|
354
360
|
}
|
|
355
361
|
function getRequestMethod(methodName, args) {
|
|
@@ -477,7 +483,10 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
|
|
|
477
483
|
const serverPort = parsedUrl.port !== "" ? Number.parseInt(parsedUrl.port, 10) : parsedUrl.protocol === "https:" ? 443 : 80;
|
|
478
484
|
let statusCodeValue = SPAN_STATUS_CODE_UNSET$1;
|
|
479
485
|
if (statusCode >= 400) statusCodeValue = SPAN_STATUS_CODE_ERROR$1;
|
|
480
|
-
const
|
|
486
|
+
const responseHeaders = await getResponseHeaders(response);
|
|
487
|
+
const contentType = responseHeaders?.["content-type"] ?? null;
|
|
488
|
+
const cacheControl = responseHeaders?.["cache-control"];
|
|
489
|
+
const resourceType = detectResourceType(contentType, url);
|
|
481
490
|
const attributes = {
|
|
482
491
|
"http.request.method": method,
|
|
483
492
|
"url.full": url,
|
|
@@ -489,6 +498,8 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
|
|
|
489
498
|
"browser.request.route_association": requestTraceContext.routeAssociation
|
|
490
499
|
};
|
|
491
500
|
if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
|
|
501
|
+
if (contentType) attributes["http.response.header.content-type"] = [contentType];
|
|
502
|
+
if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
|
|
492
503
|
if (statusCodeValue === SPAN_STATUS_CODE_ERROR$1) attributes["error.type"] = statusCode.toString();
|
|
493
504
|
const networkSpan = {
|
|
494
505
|
traceId: requestTraceContext.traceId,
|
|
@@ -505,9 +516,9 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
|
|
|
505
516
|
};
|
|
506
517
|
traceContext.addSpan(networkSpan);
|
|
507
518
|
}
|
|
508
|
-
async function
|
|
519
|
+
async function getResponseHeaders(response) {
|
|
509
520
|
try {
|
|
510
|
-
return await response.
|
|
521
|
+
return await response.allHeaders();
|
|
511
522
|
} catch {
|
|
512
523
|
return null;
|
|
513
524
|
}
|
|
@@ -549,7 +560,9 @@ const patchedFetch = async (input, init) => {
|
|
|
549
560
|
traceContext,
|
|
550
561
|
startTime,
|
|
551
562
|
endTime: /* @__PURE__ */ new Date(),
|
|
552
|
-
statusCode: response.status
|
|
563
|
+
statusCode: response.status,
|
|
564
|
+
contentType: response.headers.get("content-type"),
|
|
565
|
+
cacheControl: response.headers.get("cache-control")
|
|
553
566
|
}));
|
|
554
567
|
return response;
|
|
555
568
|
} catch (error) {
|
|
@@ -564,12 +577,14 @@ const patchedFetch = async (input, init) => {
|
|
|
564
577
|
throw error;
|
|
565
578
|
}
|
|
566
579
|
};
|
|
567
|
-
function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, error }) {
|
|
580
|
+
function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, contentType, cacheControl, error }) {
|
|
568
581
|
const method = getFetchMethod(input, init);
|
|
569
582
|
const attributes = createHttpAttributes({
|
|
570
583
|
method,
|
|
571
584
|
url: getFetchUrl(input),
|
|
572
585
|
statusCode,
|
|
586
|
+
contentType,
|
|
587
|
+
cacheControl,
|
|
573
588
|
error
|
|
574
589
|
});
|
|
575
590
|
const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
|
|
@@ -589,7 +604,7 @@ function createFetchSpan({ input, init, traceContext, startTime, endTime, status
|
|
|
589
604
|
events: []
|
|
590
605
|
};
|
|
591
606
|
}
|
|
592
|
-
function createHttpAttributes({ method, url, statusCode, error }) {
|
|
607
|
+
function createHttpAttributes({ method, url, statusCode, contentType, cacheControl, error }) {
|
|
593
608
|
const attributes = {
|
|
594
609
|
"http.request.method": method,
|
|
595
610
|
"http.resource.type": "fetch",
|
|
@@ -606,6 +621,8 @@ function createHttpAttributes({ method, url, statusCode, error }) {
|
|
|
606
621
|
attributes["http.response.status_code"] = statusCode;
|
|
607
622
|
if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
|
|
608
623
|
} else if (error !== void 0) attributes["error.type"] = errorType(error);
|
|
624
|
+
if (contentType) attributes["http.response.header.content-type"] = [contentType];
|
|
625
|
+
if (cacheControl) attributes["http.response.header.cache-control"] = [cacheControl];
|
|
609
626
|
return attributes;
|
|
610
627
|
}
|
|
611
628
|
function getFetchMethod(input, init) {
|
package/dist/index.cjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_config = require("./config-
|
|
1
|
+
const require_config = require("./config-DTMVyy76.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");
|
|
@@ -29,6 +29,7 @@ function getZipFilename(test, testId) {
|
|
|
29
29
|
return `${testId}-pw-otel.zip`;
|
|
30
30
|
}
|
|
31
31
|
const PLAYWRIGHT_TRACE_RESOURCES_DIR = "resources/";
|
|
32
|
+
const PLAYWRIGHT_TRACE_SCREENCAST_DIR = "screencast/";
|
|
32
33
|
/**
|
|
33
34
|
* Pattern to match Playwright screenshot filenames: {name}@{hex-hash}-{timestamp}.jpeg
|
|
34
35
|
* Examples: page@f06f11f7c14d6ce1060d47d79f05c154-1766833384425.jpeg
|
|
@@ -36,11 +37,12 @@ const PLAYWRIGHT_TRACE_RESOURCES_DIR = "resources/";
|
|
|
36
37
|
const PLAYWRIGHT_SCREENSHOT_PATTERN = /^.+@[a-f0-9]+-\d+\.jpe?g$/i;
|
|
37
38
|
/**
|
|
38
39
|
* Extract screenshots from a Playwright trace ZIP file.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
40
|
+
* Screencast frames are named {pageGuid}-{timestamp}.jpeg
|
|
41
|
+
* (e.g., page@abc123-1766929201038.jpeg) and live in resources/ for
|
|
42
|
+
* Playwright <= 1.62 or screencast/ for Playwright >= 1.63.
|
|
41
43
|
*
|
|
42
44
|
* @param traceZipPath - Path to the Playwright trace.zip file
|
|
43
|
-
* @returns Map of filename (without
|
|
45
|
+
* @returns Map of filename (without directory prefix) to screenshot resources
|
|
44
46
|
*/
|
|
45
47
|
async function extractScreenshotsFromPlaywrightTrace(traceZipPath) {
|
|
46
48
|
const screenshots = /* @__PURE__ */ new Map();
|
|
@@ -48,23 +50,23 @@ async function extractScreenshotsFromPlaywrightTrace(traceZipPath) {
|
|
|
48
50
|
const zipBuffer = await node_fs_promises.default.readFile(traceZipPath);
|
|
49
51
|
const zipReader = new _zip_js_zip_js.ZipReader(new _zip_js_zip_js.BlobReader(new Blob([zipBuffer])));
|
|
50
52
|
const entries = await zipReader.getEntries();
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
if (!isFileEntry(entry)) return
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
const pageIdByPath = await extractScreencastPageIds(entries);
|
|
54
|
+
const screenshotEntries = entries.flatMap((entry) => {
|
|
55
|
+
if (!isFileEntry(entry)) return [];
|
|
56
|
+
const filename = screenshotResourceName(entry.filename);
|
|
57
|
+
return filename ? [{
|
|
58
|
+
entry,
|
|
59
|
+
filename
|
|
60
|
+
}] : [];
|
|
61
|
+
});
|
|
62
|
+
await Promise.all(screenshotEntries.map(async ({ entry, filename }) => {
|
|
59
63
|
const blob = await entry.getData(new _zip_js_zip_js.BlobWriter("image/jpeg"));
|
|
60
|
-
const metadata = screenshotMetadata.get(filename);
|
|
61
64
|
screenshots.set(filename, {
|
|
62
65
|
blob,
|
|
63
66
|
file: filename,
|
|
64
67
|
timestamp: extractTimestampFromFilename(filename),
|
|
65
68
|
contentType: getMimeType(filename),
|
|
66
|
-
|
|
67
|
-
pageId: metadata?.pageId ?? extractResourceIdFromFilename(filename)
|
|
69
|
+
pageId: pageIdByPath.get(entry.filename) ?? extractResourceIdFromFilename(filename)
|
|
68
70
|
});
|
|
69
71
|
}));
|
|
70
72
|
await zipReader.close();
|
|
@@ -104,38 +106,37 @@ async function addScreenshotsToZip(zipWriter, screenshots) {
|
|
|
104
106
|
}
|
|
105
107
|
function createScreenshotManifest(screenshots) {
|
|
106
108
|
return {
|
|
107
|
-
version:
|
|
109
|
+
version: 3,
|
|
108
110
|
screenshots: Array.from(screenshots.values()).map((screenshot) => ({
|
|
109
111
|
timestamp: screenshot.timestamp,
|
|
110
112
|
file: screenshot.file,
|
|
111
113
|
path: `screenshots/${screenshot.file}`,
|
|
112
114
|
contentType: screenshot.contentType,
|
|
113
|
-
contextId: screenshot.contextId,
|
|
114
115
|
pageId: screenshot.pageId
|
|
115
116
|
})).sort((a, b) => a.timestamp - b.timestamp)
|
|
116
117
|
};
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Map screencast frame zip paths to the page that produced them.
|
|
121
|
+
* Playwright <= 1.62 (trace v8) references frames via `sha1` relative to
|
|
122
|
+
* resources/; Playwright >= 1.63 (trace v9+) uses a zip-relative `file` path.
|
|
123
|
+
*/
|
|
124
|
+
async function extractScreencastPageIds(entries) {
|
|
125
|
+
const pageIdByPath = /* @__PURE__ */ new Map();
|
|
120
126
|
const traceEntries = entries.filter((entry) => isFileEntry(entry) && isPlaywrightTraceEntry(entry.filename));
|
|
121
127
|
await Promise.all(traceEntries.map(async (entry) => {
|
|
122
128
|
const text = await entry.getData(new _zip_js_zip_js.TextWriter());
|
|
123
|
-
let contextId = "unknown-context";
|
|
124
129
|
for (const line of text.split("\n")) {
|
|
125
130
|
if (!line.trim()) continue;
|
|
126
131
|
const event = parseTraceEvent(line);
|
|
127
132
|
if (!event) continue;
|
|
128
|
-
if (event.type
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (event.type === "screencast-frame" && typeof event.sha1 === "string" && typeof event.pageId === "string") metadata.set(event.sha1, {
|
|
133
|
-
contextId,
|
|
134
|
-
pageId: event.pageId
|
|
135
|
-
});
|
|
133
|
+
if (event.type !== "screencast-frame") continue;
|
|
134
|
+
if (typeof event.pageId !== "string") continue;
|
|
135
|
+
const screenshotPath = typeof event.file === "string" ? event.file : typeof event.sha1 === "string" ? `${PLAYWRIGHT_TRACE_RESOURCES_DIR}${event.sha1}` : null;
|
|
136
|
+
if (screenshotPath) pageIdByPath.set(screenshotPath, event.pageId);
|
|
136
137
|
}
|
|
137
138
|
}));
|
|
138
|
-
return
|
|
139
|
+
return pageIdByPath;
|
|
139
140
|
}
|
|
140
141
|
function isPlaywrightTraceEntry(filename) {
|
|
141
142
|
return filename === "trace.trace" || filename.endsWith("-trace.trace");
|
|
@@ -171,6 +172,12 @@ function getMimeType(filename) {
|
|
|
171
172
|
function isFileEntry(entry) {
|
|
172
173
|
return !entry.directory;
|
|
173
174
|
}
|
|
175
|
+
function screenshotResourceName(filename) {
|
|
176
|
+
const prefix = [PLAYWRIGHT_TRACE_RESOURCES_DIR, PLAYWRIGHT_TRACE_SCREENCAST_DIR].find((directory) => filename.startsWith(directory));
|
|
177
|
+
if (!prefix) return null;
|
|
178
|
+
const name = filename.slice(prefix.length);
|
|
179
|
+
return PLAYWRIGHT_SCREENSHOT_PATTERN.test(name) ? name : null;
|
|
180
|
+
}
|
|
174
181
|
//#endregion
|
|
175
182
|
//#region src/reporter/reporter.ts
|
|
176
183
|
var PlaywrightOpentelemetryReporter = class {
|
|
@@ -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-
|
|
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-ChGo0Y1S.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";
|
|
@@ -27,6 +27,7 @@ function getZipFilename(test, testId) {
|
|
|
27
27
|
return `${testId}-pw-otel.zip`;
|
|
28
28
|
}
|
|
29
29
|
const PLAYWRIGHT_TRACE_RESOURCES_DIR = "resources/";
|
|
30
|
+
const PLAYWRIGHT_TRACE_SCREENCAST_DIR = "screencast/";
|
|
30
31
|
/**
|
|
31
32
|
* Pattern to match Playwright screenshot filenames: {name}@{hex-hash}-{timestamp}.jpeg
|
|
32
33
|
* Examples: page@f06f11f7c14d6ce1060d47d79f05c154-1766833384425.jpeg
|
|
@@ -34,11 +35,12 @@ const PLAYWRIGHT_TRACE_RESOURCES_DIR = "resources/";
|
|
|
34
35
|
const PLAYWRIGHT_SCREENSHOT_PATTERN = /^.+@[a-f0-9]+-\d+\.jpe?g$/i;
|
|
35
36
|
/**
|
|
36
37
|
* Extract screenshots from a Playwright trace ZIP file.
|
|
37
|
-
*
|
|
38
|
-
*
|
|
38
|
+
* Screencast frames are named {pageGuid}-{timestamp}.jpeg
|
|
39
|
+
* (e.g., page@abc123-1766929201038.jpeg) and live in resources/ for
|
|
40
|
+
* Playwright <= 1.62 or screencast/ for Playwright >= 1.63.
|
|
39
41
|
*
|
|
40
42
|
* @param traceZipPath - Path to the Playwright trace.zip file
|
|
41
|
-
* @returns Map of filename (without
|
|
43
|
+
* @returns Map of filename (without directory prefix) to screenshot resources
|
|
42
44
|
*/
|
|
43
45
|
async function extractScreenshotsFromPlaywrightTrace(traceZipPath) {
|
|
44
46
|
const screenshots = /* @__PURE__ */ new Map();
|
|
@@ -46,23 +48,23 @@ async function extractScreenshotsFromPlaywrightTrace(traceZipPath) {
|
|
|
46
48
|
const zipBuffer = await fs.readFile(traceZipPath);
|
|
47
49
|
const zipReader = new ZipReader(new BlobReader(new Blob([zipBuffer])));
|
|
48
50
|
const entries = await zipReader.getEntries();
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
if (!isFileEntry(entry)) return
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
const pageIdByPath = await extractScreencastPageIds(entries);
|
|
52
|
+
const screenshotEntries = entries.flatMap((entry) => {
|
|
53
|
+
if (!isFileEntry(entry)) return [];
|
|
54
|
+
const filename = screenshotResourceName(entry.filename);
|
|
55
|
+
return filename ? [{
|
|
56
|
+
entry,
|
|
57
|
+
filename
|
|
58
|
+
}] : [];
|
|
59
|
+
});
|
|
60
|
+
await Promise.all(screenshotEntries.map(async ({ entry, filename }) => {
|
|
57
61
|
const blob = await entry.getData(new BlobWriter("image/jpeg"));
|
|
58
|
-
const metadata = screenshotMetadata.get(filename);
|
|
59
62
|
screenshots.set(filename, {
|
|
60
63
|
blob,
|
|
61
64
|
file: filename,
|
|
62
65
|
timestamp: extractTimestampFromFilename(filename),
|
|
63
66
|
contentType: getMimeType(filename),
|
|
64
|
-
|
|
65
|
-
pageId: metadata?.pageId ?? extractResourceIdFromFilename(filename)
|
|
67
|
+
pageId: pageIdByPath.get(entry.filename) ?? extractResourceIdFromFilename(filename)
|
|
66
68
|
});
|
|
67
69
|
}));
|
|
68
70
|
await zipReader.close();
|
|
@@ -102,38 +104,37 @@ async function addScreenshotsToZip(zipWriter, screenshots) {
|
|
|
102
104
|
}
|
|
103
105
|
function createScreenshotManifest(screenshots) {
|
|
104
106
|
return {
|
|
105
|
-
version:
|
|
107
|
+
version: 3,
|
|
106
108
|
screenshots: Array.from(screenshots.values()).map((screenshot) => ({
|
|
107
109
|
timestamp: screenshot.timestamp,
|
|
108
110
|
file: screenshot.file,
|
|
109
111
|
path: `screenshots/${screenshot.file}`,
|
|
110
112
|
contentType: screenshot.contentType,
|
|
111
|
-
contextId: screenshot.contextId,
|
|
112
113
|
pageId: screenshot.pageId
|
|
113
114
|
})).sort((a, b) => a.timestamp - b.timestamp)
|
|
114
115
|
};
|
|
115
116
|
}
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Map screencast frame zip paths to the page that produced them.
|
|
119
|
+
* Playwright <= 1.62 (trace v8) references frames via `sha1` relative to
|
|
120
|
+
* resources/; Playwright >= 1.63 (trace v9+) uses a zip-relative `file` path.
|
|
121
|
+
*/
|
|
122
|
+
async function extractScreencastPageIds(entries) {
|
|
123
|
+
const pageIdByPath = /* @__PURE__ */ new Map();
|
|
118
124
|
const traceEntries = entries.filter((entry) => isFileEntry(entry) && isPlaywrightTraceEntry(entry.filename));
|
|
119
125
|
await Promise.all(traceEntries.map(async (entry) => {
|
|
120
126
|
const text = await entry.getData(new TextWriter());
|
|
121
|
-
let contextId = "unknown-context";
|
|
122
127
|
for (const line of text.split("\n")) {
|
|
123
128
|
if (!line.trim()) continue;
|
|
124
129
|
const event = parseTraceEvent(line);
|
|
125
130
|
if (!event) continue;
|
|
126
|
-
if (event.type
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (event.type === "screencast-frame" && typeof event.sha1 === "string" && typeof event.pageId === "string") metadata.set(event.sha1, {
|
|
131
|
-
contextId,
|
|
132
|
-
pageId: event.pageId
|
|
133
|
-
});
|
|
131
|
+
if (event.type !== "screencast-frame") continue;
|
|
132
|
+
if (typeof event.pageId !== "string") continue;
|
|
133
|
+
const screenshotPath = typeof event.file === "string" ? event.file : typeof event.sha1 === "string" ? `${PLAYWRIGHT_TRACE_RESOURCES_DIR}${event.sha1}` : null;
|
|
134
|
+
if (screenshotPath) pageIdByPath.set(screenshotPath, event.pageId);
|
|
134
135
|
}
|
|
135
136
|
}));
|
|
136
|
-
return
|
|
137
|
+
return pageIdByPath;
|
|
137
138
|
}
|
|
138
139
|
function isPlaywrightTraceEntry(filename) {
|
|
139
140
|
return filename === "trace.trace" || filename.endsWith("-trace.trace");
|
|
@@ -169,6 +170,12 @@ function getMimeType(filename) {
|
|
|
169
170
|
function isFileEntry(entry) {
|
|
170
171
|
return !entry.directory;
|
|
171
172
|
}
|
|
173
|
+
function screenshotResourceName(filename) {
|
|
174
|
+
const prefix = [PLAYWRIGHT_TRACE_RESOURCES_DIR, PLAYWRIGHT_TRACE_SCREENCAST_DIR].find((directory) => filename.startsWith(directory));
|
|
175
|
+
if (!prefix) return null;
|
|
176
|
+
const name = filename.slice(prefix.length);
|
|
177
|
+
return PLAYWRIGHT_SCREENSHOT_PATTERN.test(name) ? name : null;
|
|
178
|
+
}
|
|
172
179
|
//#endregion
|
|
173
180
|
//#region src/reporter/reporter.ts
|
|
174
181
|
var PlaywrightOpentelemetryReporter = class {
|
package/dist/reporter.cjs
CHANGED
package/dist/reporter.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playwright-opentelemetry",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
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": [
|
|
@@ -54,7 +55,6 @@
|
|
|
54
55
|
"@zip.js/zip.js": "^2.8.26"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
|
-
"@biomejs/biome": "2.4.16",
|
|
58
58
|
"@playwright/test": "1.61.0",
|
|
59
59
|
"@types/bun": "^1.3.14",
|
|
60
60
|
"@types/node": "^25.9.1",
|