playwright-opentelemetry 0.13.5 → 0.14.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 +1 -1
- package/dist/{config-DhuwcBzL.d.cts → config-DFY22ysa.d.cts} +5 -0
- package/dist/{config-DhuwcBzL.d.mts → config-DFY22ysa.d.mts} +5 -0
- package/dist/fixture.cjs +433 -14
- package/dist/fixture.d.cts +51 -2
- package/dist/fixture.d.mts +51 -2
- package/dist/fixture.mjs +420 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{reporter-DV6yWUMU.mjs → reporter-CWAovnMj.mjs} +95 -60
- package/dist/{reporter-_hqajn5O.cjs → reporter-DMlPQnrW.cjs} +115 -80
- package/dist/reporter.cjs +1 -1
- package/dist/reporter.mjs +1 -1
- package/dist/{config-C-inwZvX.cjs → screenshots-zip-B07U2DaB.cjs} +192 -17
- package/dist/{config-CiYAieDt.mjs → screenshots-zip-DXk2R8_S.mjs} +157 -18
- package/package.json +1 -1
|
@@ -20,8 +20,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
20
|
enumerable: true
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
//#endregion
|
|
23
|
+
let _zip_js_zip_js = require("@zip.js/zip.js");
|
|
23
24
|
//#region package.json
|
|
24
|
-
var version = "0.
|
|
25
|
+
var version = "0.14.0";
|
|
25
26
|
const PLAYWRIGHT_TRACE_API_SOURCE_HEADER = "x-playwright-otel-source";
|
|
26
27
|
const PLAYWRIGHT_TRACE_API_SOURCE_REPORTER = "reporter";
|
|
27
28
|
function withPlaywrightTraceApiHeaders(headers) {
|
|
@@ -133,17 +134,37 @@ async function sendSpans(spans, options) {
|
|
|
133
134
|
if (spans.length === 0) return;
|
|
134
135
|
const body = JSON.stringify(buildOtlpRequest(spans, options.playwrightVersion));
|
|
135
136
|
if (options.debug) console.log("Sending spans to", options.tracesEndpoint);
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
137
|
+
for (const retryDelayMs of [...options.retryDelaysMs ?? [], null]) {
|
|
138
|
+
const failure = await postSpans(body, options);
|
|
139
|
+
if (!failure) return;
|
|
140
|
+
if (retryDelayMs === null || !failure.retryable) throw failure.error;
|
|
141
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async function postSpans(body, options) {
|
|
145
|
+
try {
|
|
146
|
+
const response = await fetch(options.tracesEndpoint, {
|
|
147
|
+
method: "POST",
|
|
148
|
+
body,
|
|
149
|
+
headers: {
|
|
150
|
+
"content-type": "application/json",
|
|
151
|
+
...options.headers || {}
|
|
152
|
+
},
|
|
153
|
+
...options.requestTimeoutMs && { signal: AbortSignal.timeout(options.requestTimeoutMs) }
|
|
154
|
+
});
|
|
155
|
+
if (response.ok) return null;
|
|
145
156
|
const error = await response.text();
|
|
146
|
-
|
|
157
|
+
const isThrottled = response.status === 429;
|
|
158
|
+
const isServerError = response.status >= 500;
|
|
159
|
+
return {
|
|
160
|
+
error: /* @__PURE__ */ new Error(`Failed to send spans: ${response.status} ${response.statusText}, ${error}`),
|
|
161
|
+
retryable: isThrottled || isServerError
|
|
162
|
+
};
|
|
163
|
+
} catch (error) {
|
|
164
|
+
return {
|
|
165
|
+
error,
|
|
166
|
+
retryable: true
|
|
167
|
+
};
|
|
147
168
|
}
|
|
148
169
|
}
|
|
149
170
|
//#endregion
|
|
@@ -185,6 +206,8 @@ function normalizeTraceMode(trace) {
|
|
|
185
206
|
const TRACE_CONTEXT_ATTACHMENT_NAME = "playwright-opentelemetry-trace-context";
|
|
186
207
|
const FIXTURE_SPANS_ATTACHMENT_NAME = "playwright-opentelemetry-fixture-spans";
|
|
187
208
|
const BROWSER_SERVICE_NAME = "playwright-browser";
|
|
209
|
+
const FIXTURE_EXPORT_RETRY_DELAYS_MS = [250, 750];
|
|
210
|
+
const FIXTURE_EXPORT_REQUEST_TIMEOUT_MS = 3e3;
|
|
188
211
|
async function createTestTraceContext(testInfo) {
|
|
189
212
|
const traceContext = {
|
|
190
213
|
traceId: generateTraceId(),
|
|
@@ -204,7 +227,15 @@ async function createTestTraceContext(testInfo) {
|
|
|
204
227
|
});
|
|
205
228
|
return traceContext;
|
|
206
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Writes the expected-trace marker that lets the Trace API admit spans from the
|
|
232
|
+
* app under test. Only browser requests carry the test's traceparent, so the
|
|
233
|
+
* marker is skipped when propagation is off; the fixture's own spans are
|
|
234
|
+
* trusted and stored without it. Never rejects, so callers can start it
|
|
235
|
+
* without awaiting.
|
|
236
|
+
*/
|
|
207
237
|
async function registerExpectedTrace(traceContext, config, options) {
|
|
238
|
+
if (!config.propagateTraceHeaders) return;
|
|
208
239
|
const couldRetainTrace = (trace) => couldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo);
|
|
209
240
|
const destinations = filterRetainedDestinations(config.playwrightTraceApiDestinations, config.trace, couldRetainTrace);
|
|
210
241
|
if (destinations.length === 0) return;
|
|
@@ -236,12 +267,21 @@ async function flushFixtureSpans(traceContext, config, options) {
|
|
|
236
267
|
});
|
|
237
268
|
const destinations = fixtureSpanDestinations(config, shouldRetainTrace);
|
|
238
269
|
if (destinations.length === 0) return;
|
|
239
|
-
await Promise.all(destinations.map((destination) =>
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
270
|
+
const failures = await Promise.all(destinations.map(async (destination) => {
|
|
271
|
+
try {
|
|
272
|
+
await sendSpans(traceContext.spans, {
|
|
273
|
+
tracesEndpoint: destination.tracesEndpoint,
|
|
274
|
+
headers: destination.headers,
|
|
275
|
+
playwrightVersion: "unknown",
|
|
276
|
+
debug: config.debug,
|
|
277
|
+
retryDelaysMs: FIXTURE_EXPORT_RETRY_DELAYS_MS,
|
|
278
|
+
requestTimeoutMs: FIXTURE_EXPORT_REQUEST_TIMEOUT_MS
|
|
279
|
+
});
|
|
280
|
+
} catch (error) {
|
|
281
|
+
return `${destination.tracesEndpoint}: ${error instanceof Error ? error.message : String(error)}`;
|
|
282
|
+
}
|
|
283
|
+
}));
|
|
284
|
+
for (const failure of failures) if (failure) console.warn(`Failed to export fixture spans for trace ${traceContext.traceId}: ${failure}`);
|
|
245
285
|
}
|
|
246
286
|
function serializeSpanForAttachment(span) {
|
|
247
287
|
return {
|
|
@@ -285,6 +325,7 @@ function resolvePlaywrightOpentelemetryConfig(config, options = {}) {
|
|
|
285
325
|
}),
|
|
286
326
|
storeTraceZip: config?.storeTraceZip === true,
|
|
287
327
|
trace: config?.trace ?? null,
|
|
328
|
+
screenshots: config?.screenshots ?? true,
|
|
288
329
|
propagateTraceHeaders: config?.propagateTraceHeaders ?? true,
|
|
289
330
|
debug: debugEnv === void 0 ? config?.debug ?? false : debugEnv === "1" || debugEnv === "true"
|
|
290
331
|
};
|
|
@@ -326,6 +367,104 @@ function getConfigurationErrorMessage() {
|
|
|
326
367
|
return "playwright-opentelemetry reporter requires an OTLP endpoint, trace API endpoint, or storeTraceZip to be configured.\n\nYou can configure it using environment variables:\n\n export OTEL_EXPORTER_OTLP_ENDPOINT=\"https://api.honeycomb.io\"\n export OTEL_EXPORTER_OTLP_HEADERS=\"x-honeycomb-team=YOUR_API_KEY\"\n\nOr via playwright.config.ts:\n\nimport { defineConfig } from '@playwright/test';\nimport type { PlaywrightOpentelemetryUseOptions } from 'playwright-opentelemetry/fixture';\n\nexport default defineConfig<PlaywrightOpentelemetryUseOptions>({\n use: {\n playwrightOpentelemetry: {\n otlpEndpoint: {\n url: 'http://localhost:4317/v1/traces',\n headers: {\n Authorization: 'Bearer YOUR_TOKEN',\n },\n },\n },\n },\n reporter: [['playwright-opentelemetry/reporter']],\n});\n\nNote: Environment variables take precedence over use.playwrightOpentelemetry options.\n";
|
|
327
368
|
}
|
|
328
369
|
//#endregion
|
|
370
|
+
//#region src/shared/screencast-screenshots.ts
|
|
371
|
+
/**
|
|
372
|
+
* The first Playwright version whose screencast frames carry the browser's
|
|
373
|
+
* presentation timestamp (1.61) and viewport size (1.60), and whose browsers
|
|
374
|
+
* report new contexts (1.60).
|
|
375
|
+
*
|
|
376
|
+
* From this version, screenshots only come from the fixture's screencast
|
|
377
|
+
* capture: tests without the fixture get none. Before it, the fixture
|
|
378
|
+
* captures nothing and the reporter reads screenshots from Playwright's
|
|
379
|
+
* trace.zip (see reporter/legacy/). Once the peer dependency requires this
|
|
380
|
+
* version, delete this module and that legacy path.
|
|
381
|
+
*/
|
|
382
|
+
const SCREENCAST_SCREENSHOTS_MIN_PLAYWRIGHT_VERSION = "1.61.0";
|
|
383
|
+
/** Whether this Playwright version's screencast can provide screenshots. */
|
|
384
|
+
function supportsScreencastScreenshots(playwrightVersion) {
|
|
385
|
+
const version = parseVersion(playwrightVersion);
|
|
386
|
+
const minimum = parseVersion(SCREENCAST_SCREENSHOTS_MIN_PLAYWRIGHT_VERSION);
|
|
387
|
+
if (!version || !minimum) return false;
|
|
388
|
+
for (let index = 0; index < minimum.length; index++) if (version[index] !== minimum[index]) return version[index] > minimum[index];
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Major, minor and patch of a version such as "1.61.0" or "1.61.0-next".
|
|
393
|
+
* Prereleases count as their release: 1.61.0-next already has the API.
|
|
394
|
+
*/
|
|
395
|
+
function parseVersion(version) {
|
|
396
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
397
|
+
return match ? [
|
|
398
|
+
Number(match[1]),
|
|
399
|
+
Number(match[2]),
|
|
400
|
+
Number(match[3])
|
|
401
|
+
] : void 0;
|
|
402
|
+
}
|
|
403
|
+
//#endregion
|
|
404
|
+
//#region src/shared/screenshots-zip.ts
|
|
405
|
+
/**
|
|
406
|
+
* The fixture attaches captured screencast frames to the test result as a
|
|
407
|
+
* screenshots ZIP under this name; the reporter uploads it and copies it into
|
|
408
|
+
* the local trace ZIP.
|
|
409
|
+
*/
|
|
410
|
+
const SCREENSHOTS_ATTACHMENT_NAME = "playwright-opentelemetry-screenshots";
|
|
411
|
+
const MANIFEST_PATH = "manifest.json";
|
|
412
|
+
const SCREENSHOTS_DIR = "screenshots/";
|
|
413
|
+
async function createScreenshotsZip(screenshots) {
|
|
414
|
+
const zipWriter = new _zip_js_zip_js.ZipWriter(new _zip_js_zip_js.BlobWriter("application/zip"));
|
|
415
|
+
await addScreenshotsToZip(zipWriter, screenshots);
|
|
416
|
+
return zipWriter.close();
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Add the manifest and frames of a screenshots ZIP to another ZIP, so the same
|
|
420
|
+
* layout can be uploaded on its own or embedded in a local trace ZIP.
|
|
421
|
+
*/
|
|
422
|
+
async function addScreenshotsToZip(zipWriter, screenshots) {
|
|
423
|
+
const sorted = [...screenshots].sort((a, b) => a.timestamp - b.timestamp);
|
|
424
|
+
const manifest = {
|
|
425
|
+
version: 3,
|
|
426
|
+
screenshots: sorted.map((screenshot) => ({
|
|
427
|
+
timestamp: screenshot.timestamp,
|
|
428
|
+
file: screenshot.file,
|
|
429
|
+
path: `${SCREENSHOTS_DIR}${screenshot.file}`,
|
|
430
|
+
contentType: screenshot.contentType,
|
|
431
|
+
pageId: screenshot.pageId,
|
|
432
|
+
...viewportOf(screenshot)
|
|
433
|
+
}))
|
|
434
|
+
};
|
|
435
|
+
await zipWriter.add(MANIFEST_PATH, new Blob([JSON.stringify(manifest, null, 2)], { type: "application/json" }).stream());
|
|
436
|
+
for (const screenshot of sorted) await zipWriter.add(`${SCREENSHOTS_DIR}${screenshot.file}`, screenshot.blob.stream(), { level: 0 });
|
|
437
|
+
}
|
|
438
|
+
async function readScreenshotsZip(zipBlob) {
|
|
439
|
+
const zipReader = new _zip_js_zip_js.ZipReader(new _zip_js_zip_js.BlobReader(zipBlob));
|
|
440
|
+
try {
|
|
441
|
+
const entries = new Map((await zipReader.getEntries()).filter((entry) => !entry.directory).map((entry) => [entry.filename, entry]));
|
|
442
|
+
const manifestEntry = entries.get(MANIFEST_PATH);
|
|
443
|
+
if (!manifestEntry) throw new Error(`Screenshots ZIP has no ${MANIFEST_PATH}`);
|
|
444
|
+
const manifest = JSON.parse(await manifestEntry.getData(new _zip_js_zip_js.TextWriter()));
|
|
445
|
+
return await Promise.all(manifest.screenshots.map(async (screenshot) => {
|
|
446
|
+
const entry = entries.get(screenshot.path);
|
|
447
|
+
if (!entry) throw new Error(`Screenshots ZIP has no ${screenshot.path}`);
|
|
448
|
+
return {
|
|
449
|
+
timestamp: screenshot.timestamp,
|
|
450
|
+
file: screenshot.file,
|
|
451
|
+
contentType: screenshot.contentType,
|
|
452
|
+
pageId: screenshot.pageId,
|
|
453
|
+
...viewportOf(screenshot),
|
|
454
|
+
blob: await entry.getData(new _zip_js_zip_js.BlobWriter(screenshot.contentType))
|
|
455
|
+
};
|
|
456
|
+
}));
|
|
457
|
+
} finally {
|
|
458
|
+
await zipReader.close();
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function viewportOf(screenshot) {
|
|
462
|
+
return screenshot.viewportWidth !== void 0 && screenshot.viewportHeight !== void 0 ? {
|
|
463
|
+
viewportWidth: screenshot.viewportWidth,
|
|
464
|
+
viewportHeight: screenshot.viewportHeight
|
|
465
|
+
} : {};
|
|
466
|
+
}
|
|
467
|
+
//#endregion
|
|
329
468
|
Object.defineProperty(exports, "BROWSER_SERVICE_NAME", {
|
|
330
469
|
enumerable: true,
|
|
331
470
|
get: function() {
|
|
@@ -350,6 +489,12 @@ Object.defineProperty(exports, "PLAYWRIGHT_TRACE_API_SOURCE_REPORTER", {
|
|
|
350
489
|
return PLAYWRIGHT_TRACE_API_SOURCE_REPORTER;
|
|
351
490
|
}
|
|
352
491
|
});
|
|
492
|
+
Object.defineProperty(exports, "SCREENSHOTS_ATTACHMENT_NAME", {
|
|
493
|
+
enumerable: true,
|
|
494
|
+
get: function() {
|
|
495
|
+
return SCREENSHOTS_ATTACHMENT_NAME;
|
|
496
|
+
}
|
|
497
|
+
});
|
|
353
498
|
Object.defineProperty(exports, "TRACE_CONTEXT_ATTACHMENT_NAME", {
|
|
354
499
|
enumerable: true,
|
|
355
500
|
get: function() {
|
|
@@ -362,12 +507,30 @@ Object.defineProperty(exports, "__toESM", {
|
|
|
362
507
|
return __toESM;
|
|
363
508
|
}
|
|
364
509
|
});
|
|
510
|
+
Object.defineProperty(exports, "addScreenshotsToZip", {
|
|
511
|
+
enumerable: true,
|
|
512
|
+
get: function() {
|
|
513
|
+
return addScreenshotsToZip;
|
|
514
|
+
}
|
|
515
|
+
});
|
|
365
516
|
Object.defineProperty(exports, "buildOtlpRequest", {
|
|
366
517
|
enumerable: true,
|
|
367
518
|
get: function() {
|
|
368
519
|
return buildOtlpRequest;
|
|
369
520
|
}
|
|
370
521
|
});
|
|
522
|
+
Object.defineProperty(exports, "couldRetainPlaywrightTrace", {
|
|
523
|
+
enumerable: true,
|
|
524
|
+
get: function() {
|
|
525
|
+
return couldRetainPlaywrightTrace;
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
Object.defineProperty(exports, "createScreenshotsZip", {
|
|
529
|
+
enumerable: true,
|
|
530
|
+
get: function() {
|
|
531
|
+
return createScreenshotsZip;
|
|
532
|
+
}
|
|
533
|
+
});
|
|
371
534
|
Object.defineProperty(exports, "createTestTraceContext", {
|
|
372
535
|
enumerable: true,
|
|
373
536
|
get: function() {
|
|
@@ -398,6 +561,12 @@ Object.defineProperty(exports, "generateTraceId", {
|
|
|
398
561
|
return generateTraceId;
|
|
399
562
|
}
|
|
400
563
|
});
|
|
564
|
+
Object.defineProperty(exports, "readScreenshotsZip", {
|
|
565
|
+
enumerable: true,
|
|
566
|
+
get: function() {
|
|
567
|
+
return readScreenshotsZip;
|
|
568
|
+
}
|
|
569
|
+
});
|
|
401
570
|
Object.defineProperty(exports, "registerExpectedTrace", {
|
|
402
571
|
enumerable: true,
|
|
403
572
|
get: function() {
|
|
@@ -422,6 +591,12 @@ Object.defineProperty(exports, "shouldRetainPlaywrightTrace", {
|
|
|
422
591
|
return shouldRetainPlaywrightTrace;
|
|
423
592
|
}
|
|
424
593
|
});
|
|
594
|
+
Object.defineProperty(exports, "supportsScreencastScreenshots", {
|
|
595
|
+
enumerable: true,
|
|
596
|
+
get: function() {
|
|
597
|
+
return supportsScreencastScreenshots;
|
|
598
|
+
}
|
|
599
|
+
});
|
|
425
600
|
Object.defineProperty(exports, "withPlaywrightTraceApiHeaders", {
|
|
426
601
|
enumerable: true,
|
|
427
602
|
get: function() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { BlobReader, BlobWriter, TextWriter, ZipReader, ZipWriter } from "@zip.js/zip.js";
|
|
1
2
|
//#region package.json
|
|
2
|
-
var version = "0.
|
|
3
|
+
var version = "0.14.0";
|
|
3
4
|
const PLAYWRIGHT_TRACE_API_SOURCE_HEADER = "x-playwright-otel-source";
|
|
4
5
|
const PLAYWRIGHT_TRACE_API_SOURCE_REPORTER = "reporter";
|
|
5
6
|
function withPlaywrightTraceApiHeaders(headers) {
|
|
@@ -111,17 +112,37 @@ async function sendSpans(spans, options) {
|
|
|
111
112
|
if (spans.length === 0) return;
|
|
112
113
|
const body = JSON.stringify(buildOtlpRequest(spans, options.playwrightVersion));
|
|
113
114
|
if (options.debug) console.log("Sending spans to", options.tracesEndpoint);
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
for (const retryDelayMs of [...options.retryDelaysMs ?? [], null]) {
|
|
116
|
+
const failure = await postSpans(body, options);
|
|
117
|
+
if (!failure) return;
|
|
118
|
+
if (retryDelayMs === null || !failure.retryable) throw failure.error;
|
|
119
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function postSpans(body, options) {
|
|
123
|
+
try {
|
|
124
|
+
const response = await fetch(options.tracesEndpoint, {
|
|
125
|
+
method: "POST",
|
|
126
|
+
body,
|
|
127
|
+
headers: {
|
|
128
|
+
"content-type": "application/json",
|
|
129
|
+
...options.headers || {}
|
|
130
|
+
},
|
|
131
|
+
...options.requestTimeoutMs && { signal: AbortSignal.timeout(options.requestTimeoutMs) }
|
|
132
|
+
});
|
|
133
|
+
if (response.ok) return null;
|
|
123
134
|
const error = await response.text();
|
|
124
|
-
|
|
135
|
+
const isThrottled = response.status === 429;
|
|
136
|
+
const isServerError = response.status >= 500;
|
|
137
|
+
return {
|
|
138
|
+
error: /* @__PURE__ */ new Error(`Failed to send spans: ${response.status} ${response.statusText}, ${error}`),
|
|
139
|
+
retryable: isThrottled || isServerError
|
|
140
|
+
};
|
|
141
|
+
} catch (error) {
|
|
142
|
+
return {
|
|
143
|
+
error,
|
|
144
|
+
retryable: true
|
|
145
|
+
};
|
|
125
146
|
}
|
|
126
147
|
}
|
|
127
148
|
//#endregion
|
|
@@ -163,6 +184,8 @@ function normalizeTraceMode(trace) {
|
|
|
163
184
|
const TRACE_CONTEXT_ATTACHMENT_NAME = "playwright-opentelemetry-trace-context";
|
|
164
185
|
const FIXTURE_SPANS_ATTACHMENT_NAME = "playwright-opentelemetry-fixture-spans";
|
|
165
186
|
const BROWSER_SERVICE_NAME = "playwright-browser";
|
|
187
|
+
const FIXTURE_EXPORT_RETRY_DELAYS_MS = [250, 750];
|
|
188
|
+
const FIXTURE_EXPORT_REQUEST_TIMEOUT_MS = 3e3;
|
|
166
189
|
async function createTestTraceContext(testInfo) {
|
|
167
190
|
const traceContext = {
|
|
168
191
|
traceId: generateTraceId(),
|
|
@@ -182,7 +205,15 @@ async function createTestTraceContext(testInfo) {
|
|
|
182
205
|
});
|
|
183
206
|
return traceContext;
|
|
184
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Writes the expected-trace marker that lets the Trace API admit spans from the
|
|
210
|
+
* app under test. Only browser requests carry the test's traceparent, so the
|
|
211
|
+
* marker is skipped when propagation is off; the fixture's own spans are
|
|
212
|
+
* trusted and stored without it. Never rejects, so callers can start it
|
|
213
|
+
* without awaiting.
|
|
214
|
+
*/
|
|
185
215
|
async function registerExpectedTrace(traceContext, config, options) {
|
|
216
|
+
if (!config.propagateTraceHeaders) return;
|
|
186
217
|
const couldRetainTrace = (trace) => couldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo);
|
|
187
218
|
const destinations = filterRetainedDestinations(config.playwrightTraceApiDestinations, config.trace, couldRetainTrace);
|
|
188
219
|
if (destinations.length === 0) return;
|
|
@@ -214,12 +245,21 @@ async function flushFixtureSpans(traceContext, config, options) {
|
|
|
214
245
|
});
|
|
215
246
|
const destinations = fixtureSpanDestinations(config, shouldRetainTrace);
|
|
216
247
|
if (destinations.length === 0) return;
|
|
217
|
-
await Promise.all(destinations.map((destination) =>
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
248
|
+
const failures = await Promise.all(destinations.map(async (destination) => {
|
|
249
|
+
try {
|
|
250
|
+
await sendSpans(traceContext.spans, {
|
|
251
|
+
tracesEndpoint: destination.tracesEndpoint,
|
|
252
|
+
headers: destination.headers,
|
|
253
|
+
playwrightVersion: "unknown",
|
|
254
|
+
debug: config.debug,
|
|
255
|
+
retryDelaysMs: FIXTURE_EXPORT_RETRY_DELAYS_MS,
|
|
256
|
+
requestTimeoutMs: FIXTURE_EXPORT_REQUEST_TIMEOUT_MS
|
|
257
|
+
});
|
|
258
|
+
} catch (error) {
|
|
259
|
+
return `${destination.tracesEndpoint}: ${error instanceof Error ? error.message : String(error)}`;
|
|
260
|
+
}
|
|
261
|
+
}));
|
|
262
|
+
for (const failure of failures) if (failure) console.warn(`Failed to export fixture spans for trace ${traceContext.traceId}: ${failure}`);
|
|
223
263
|
}
|
|
224
264
|
function serializeSpanForAttachment(span) {
|
|
225
265
|
return {
|
|
@@ -263,6 +303,7 @@ function resolvePlaywrightOpentelemetryConfig(config, options = {}) {
|
|
|
263
303
|
}),
|
|
264
304
|
storeTraceZip: config?.storeTraceZip === true,
|
|
265
305
|
trace: config?.trace ?? null,
|
|
306
|
+
screenshots: config?.screenshots ?? true,
|
|
266
307
|
propagateTraceHeaders: config?.propagateTraceHeaders ?? true,
|
|
267
308
|
debug: debugEnv === void 0 ? config?.debug ?? false : debugEnv === "1" || debugEnv === "true"
|
|
268
309
|
};
|
|
@@ -304,4 +345,102 @@ function getConfigurationErrorMessage() {
|
|
|
304
345
|
return "playwright-opentelemetry reporter requires an OTLP endpoint, trace API endpoint, or storeTraceZip to be configured.\n\nYou can configure it using environment variables:\n\n export OTEL_EXPORTER_OTLP_ENDPOINT=\"https://api.honeycomb.io\"\n export OTEL_EXPORTER_OTLP_HEADERS=\"x-honeycomb-team=YOUR_API_KEY\"\n\nOr via playwright.config.ts:\n\nimport { defineConfig } from '@playwright/test';\nimport type { PlaywrightOpentelemetryUseOptions } from 'playwright-opentelemetry/fixture';\n\nexport default defineConfig<PlaywrightOpentelemetryUseOptions>({\n use: {\n playwrightOpentelemetry: {\n otlpEndpoint: {\n url: 'http://localhost:4317/v1/traces',\n headers: {\n Authorization: 'Bearer YOUR_TOKEN',\n },\n },\n },\n },\n reporter: [['playwright-opentelemetry/reporter']],\n});\n\nNote: Environment variables take precedence over use.playwrightOpentelemetry options.\n";
|
|
305
346
|
}
|
|
306
347
|
//#endregion
|
|
307
|
-
|
|
348
|
+
//#region src/shared/screencast-screenshots.ts
|
|
349
|
+
/**
|
|
350
|
+
* The first Playwright version whose screencast frames carry the browser's
|
|
351
|
+
* presentation timestamp (1.61) and viewport size (1.60), and whose browsers
|
|
352
|
+
* report new contexts (1.60).
|
|
353
|
+
*
|
|
354
|
+
* From this version, screenshots only come from the fixture's screencast
|
|
355
|
+
* capture: tests without the fixture get none. Before it, the fixture
|
|
356
|
+
* captures nothing and the reporter reads screenshots from Playwright's
|
|
357
|
+
* trace.zip (see reporter/legacy/). Once the peer dependency requires this
|
|
358
|
+
* version, delete this module and that legacy path.
|
|
359
|
+
*/
|
|
360
|
+
const SCREENCAST_SCREENSHOTS_MIN_PLAYWRIGHT_VERSION = "1.61.0";
|
|
361
|
+
/** Whether this Playwright version's screencast can provide screenshots. */
|
|
362
|
+
function supportsScreencastScreenshots(playwrightVersion) {
|
|
363
|
+
const version = parseVersion(playwrightVersion);
|
|
364
|
+
const minimum = parseVersion(SCREENCAST_SCREENSHOTS_MIN_PLAYWRIGHT_VERSION);
|
|
365
|
+
if (!version || !minimum) return false;
|
|
366
|
+
for (let index = 0; index < minimum.length; index++) if (version[index] !== minimum[index]) return version[index] > minimum[index];
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Major, minor and patch of a version such as "1.61.0" or "1.61.0-next".
|
|
371
|
+
* Prereleases count as their release: 1.61.0-next already has the API.
|
|
372
|
+
*/
|
|
373
|
+
function parseVersion(version) {
|
|
374
|
+
const match = /^(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
375
|
+
return match ? [
|
|
376
|
+
Number(match[1]),
|
|
377
|
+
Number(match[2]),
|
|
378
|
+
Number(match[3])
|
|
379
|
+
] : void 0;
|
|
380
|
+
}
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/shared/screenshots-zip.ts
|
|
383
|
+
/**
|
|
384
|
+
* The fixture attaches captured screencast frames to the test result as a
|
|
385
|
+
* screenshots ZIP under this name; the reporter uploads it and copies it into
|
|
386
|
+
* the local trace ZIP.
|
|
387
|
+
*/
|
|
388
|
+
const SCREENSHOTS_ATTACHMENT_NAME = "playwright-opentelemetry-screenshots";
|
|
389
|
+
const MANIFEST_PATH = "manifest.json";
|
|
390
|
+
const SCREENSHOTS_DIR = "screenshots/";
|
|
391
|
+
async function createScreenshotsZip(screenshots) {
|
|
392
|
+
const zipWriter = new ZipWriter(new BlobWriter("application/zip"));
|
|
393
|
+
await addScreenshotsToZip(zipWriter, screenshots);
|
|
394
|
+
return zipWriter.close();
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Add the manifest and frames of a screenshots ZIP to another ZIP, so the same
|
|
398
|
+
* layout can be uploaded on its own or embedded in a local trace ZIP.
|
|
399
|
+
*/
|
|
400
|
+
async function addScreenshotsToZip(zipWriter, screenshots) {
|
|
401
|
+
const sorted = [...screenshots].sort((a, b) => a.timestamp - b.timestamp);
|
|
402
|
+
const manifest = {
|
|
403
|
+
version: 3,
|
|
404
|
+
screenshots: sorted.map((screenshot) => ({
|
|
405
|
+
timestamp: screenshot.timestamp,
|
|
406
|
+
file: screenshot.file,
|
|
407
|
+
path: `${SCREENSHOTS_DIR}${screenshot.file}`,
|
|
408
|
+
contentType: screenshot.contentType,
|
|
409
|
+
pageId: screenshot.pageId,
|
|
410
|
+
...viewportOf(screenshot)
|
|
411
|
+
}))
|
|
412
|
+
};
|
|
413
|
+
await zipWriter.add(MANIFEST_PATH, new Blob([JSON.stringify(manifest, null, 2)], { type: "application/json" }).stream());
|
|
414
|
+
for (const screenshot of sorted) await zipWriter.add(`${SCREENSHOTS_DIR}${screenshot.file}`, screenshot.blob.stream(), { level: 0 });
|
|
415
|
+
}
|
|
416
|
+
async function readScreenshotsZip(zipBlob) {
|
|
417
|
+
const zipReader = new ZipReader(new BlobReader(zipBlob));
|
|
418
|
+
try {
|
|
419
|
+
const entries = new Map((await zipReader.getEntries()).filter((entry) => !entry.directory).map((entry) => [entry.filename, entry]));
|
|
420
|
+
const manifestEntry = entries.get(MANIFEST_PATH);
|
|
421
|
+
if (!manifestEntry) throw new Error(`Screenshots ZIP has no ${MANIFEST_PATH}`);
|
|
422
|
+
const manifest = JSON.parse(await manifestEntry.getData(new TextWriter()));
|
|
423
|
+
return await Promise.all(manifest.screenshots.map(async (screenshot) => {
|
|
424
|
+
const entry = entries.get(screenshot.path);
|
|
425
|
+
if (!entry) throw new Error(`Screenshots ZIP has no ${screenshot.path}`);
|
|
426
|
+
return {
|
|
427
|
+
timestamp: screenshot.timestamp,
|
|
428
|
+
file: screenshot.file,
|
|
429
|
+
contentType: screenshot.contentType,
|
|
430
|
+
pageId: screenshot.pageId,
|
|
431
|
+
...viewportOf(screenshot),
|
|
432
|
+
blob: await entry.getData(new BlobWriter(screenshot.contentType))
|
|
433
|
+
};
|
|
434
|
+
}));
|
|
435
|
+
} finally {
|
|
436
|
+
await zipReader.close();
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
function viewportOf(screenshot) {
|
|
440
|
+
return screenshot.viewportWidth !== void 0 && screenshot.viewportHeight !== void 0 ? {
|
|
441
|
+
viewportWidth: screenshot.viewportWidth,
|
|
442
|
+
viewportHeight: screenshot.viewportHeight
|
|
443
|
+
} : {};
|
|
444
|
+
}
|
|
445
|
+
//#endregion
|
|
446
|
+
export { withPlaywrightTraceApiHeaders as S, PLAYWRIGHT_TRACE_API_SOURCE_REPORTER as _, supportsScreencastScreenshots as a, generateTraceId as b, FIXTURE_SPANS_ATTACHMENT_NAME as c, flushFixtureSpans as d, registerExpectedTrace as f, PLAYWRIGHT_TRACE_API_SOURCE_HEADER as g, filterRetainedDestinations as h, readScreenshotsZip as i, TRACE_CONTEXT_ATTACHMENT_NAME as l, shouldRetainPlaywrightTrace as m, addScreenshotsToZip as n, resolvePlaywrightOpentelemetryConfig as o, couldRetainPlaywrightTrace as p, createScreenshotsZip as r, BROWSER_SERVICE_NAME as s, SCREENSHOTS_ATTACHMENT_NAME as t, createTestTraceContext as u, buildOtlpRequest as v, sendSpans as x, generateSpanId as y };
|