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.
@@ -1,6 +1,6 @@
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-CiYAieDt.mjs";
2
- import path from "node:path";
1
+ import { S as withPlaywrightTraceApiHeaders, _ as PLAYWRIGHT_TRACE_API_SOURCE_REPORTER, a as supportsScreencastScreenshots, b as generateTraceId, c as FIXTURE_SPANS_ATTACHMENT_NAME, g as PLAYWRIGHT_TRACE_API_SOURCE_HEADER, h as filterRetainedDestinations, i as readScreenshotsZip, l as TRACE_CONTEXT_ATTACHMENT_NAME, m as shouldRetainPlaywrightTrace, n as addScreenshotsToZip, o as resolvePlaywrightOpentelemetryConfig, r as createScreenshotsZip, v as buildOtlpRequest, x as sendSpans, y as generateSpanId } from "./screenshots-zip-DXk2R8_S.mjs";
3
2
  import fs from "node:fs/promises";
3
+ import path from "node:path";
4
4
  import { BlobReader, BlobWriter, TextWriter, ZipReader, ZipWriter } from "@zip.js/zip.js";
5
5
  //#region src/reporter/otel-attributes.ts
6
6
  const ATTR_CODE_FILE_PATH = "code.file.path";
@@ -13,20 +13,22 @@ const ATTR_TEST_CASE_RESULT_STATUS = "test.case.result.status";
13
13
  const TEST_SPAN_NAME = "playwright.test";
14
14
  const TEST_STEP_SPAN_NAME = "playwright.test.step";
15
15
  const ATTR_TEST_STEP_NAME = "test.step.name";
16
+ /** Playwright's step title, e.g. `Click` or `Expect "toBeVisible"` */
16
17
  const ATTR_TEST_STEP_TITLE = "test.step.title";
18
+ /** What the step acted on, e.g. the locator of a `Click` or the url of a `Navigate` */
19
+ const ATTR_TEST_STEP_SUBTITLE = "test.step.subtitle";
20
+ /** Prefix for the step's reported params, e.g. `test.step.param.locator` */
21
+ const ATTR_TEST_STEP_PARAM_PREFIX = "test.step.param.";
17
22
  const ATTR_TEST_STEP_CATEGORY = "test.step.category";
18
23
  const ATTR_TEST_PHASE = "playwright.test.phase";
19
24
  //#endregion
20
- //#region src/reporter/trace-zip-builder.ts
25
+ //#region src/reporter/legacy/trace-zip-screenshots.ts
21
26
  /**
22
- * Get the zip filename based on test location and ID.
23
- * Format: {basename(file)}:{line}-{testId}-pw-otel.zip
24
- * Fallback: {testId}-pw-otel.zip (if no location info)
27
+ * LEGACY: reads screenshots out of Playwright's trace.zip, for Playwright
28
+ * older than SCREENCAST_SCREENSHOTS_MIN_PLAYWRIGHT_VERSION. Delete this
29
+ * directory, its tests and the reporter's legacy branch once the peer
30
+ * dependency requires that version.
25
31
  */
26
- function getZipFilename(test, testId) {
27
- if (test.location) return `${path.basename(test.location.file)}:${test.location.line}-${testId}-pw-otel.zip`;
28
- return `${testId}-pw-otel.zip`;
29
- }
30
32
  const PLAYWRIGHT_TRACE_RESOURCES_DIR = "resources/";
31
33
  const PLAYWRIGHT_TRACE_SCREENCAST_DIR = "screencast/";
32
34
  /**
@@ -40,6 +42,8 @@ const PLAYWRIGHT_SCREENSHOT_PATTERN = /^.+@[a-f0-9]+-\d+\.jpe?g$/i;
40
42
  * (e.g., page@abc123-1766929201038.jpeg) and live in resources/ for
41
43
  * Playwright <= 1.62 or screencast/ for Playwright >= 1.63.
42
44
  *
45
+ * Never rejects: a trace that can't be read gives no screenshots.
46
+ *
43
47
  * @param traceZipPath - Path to the Playwright trace.zip file
44
48
  * @returns Map of filename (without directory prefix) to screenshot resources
45
49
  */
@@ -74,47 +78,6 @@ async function extractScreenshotsFromPlaywrightTrace(traceZipPath) {
74
78
  }
75
79
  return screenshots;
76
80
  }
77
- async function createScreenshotsZip(screenshots) {
78
- const zipWriter = new ZipWriter(new BlobWriter("application/zip"));
79
- await addScreenshotsToZip(zipWriter, screenshots);
80
- return zipWriter.close();
81
- }
82
- async function createTraceZipBlob(options) {
83
- const { spans, fixtureSpans, playwrightVersion, screenshots } = options;
84
- const otlpRequest = buildOtlpRequest(spans, playwrightVersion);
85
- const traceJson = JSON.stringify(otlpRequest, null, 2);
86
- const zipWriter = new ZipWriter(new BlobWriter("application/zip"));
87
- await zipWriter.add("traces/playwright-opentelemetry.json", new Blob([traceJson]).stream());
88
- if (fixtureSpans.length > 0) {
89
- const fixtureOtlpRequest = buildOtlpRequest(fixtureSpans, playwrightVersion);
90
- await zipWriter.add("traces/playwright-fixture-spans.json", new Blob([JSON.stringify(fixtureOtlpRequest, null, 2)]).stream());
91
- }
92
- await addScreenshotsToZip(zipWriter, screenshots);
93
- return zipWriter.close();
94
- }
95
- async function writeTraceZip(outputDir, test, zipBlob) {
96
- const zipFilename = getZipFilename(test, test.id);
97
- const zipPath = path.join(outputDir, zipFilename);
98
- const arrayBuffer = await zipBlob.arrayBuffer();
99
- await fs.writeFile(zipPath, Buffer.from(arrayBuffer));
100
- }
101
- async function addScreenshotsToZip(zipWriter, screenshots) {
102
- const manifest = createScreenshotManifest(screenshots);
103
- await zipWriter.add("manifest.json", new Blob([JSON.stringify(manifest, null, 2)], { type: "application/json" }).stream());
104
- for (const [filename, screenshot] of screenshots.entries()) await zipWriter.add(`screenshots/${filename}`, screenshot.blob.stream());
105
- }
106
- function createScreenshotManifest(screenshots) {
107
- return {
108
- version: 3,
109
- screenshots: Array.from(screenshots.values()).map((screenshot) => ({
110
- timestamp: screenshot.timestamp,
111
- file: screenshot.file,
112
- path: `screenshots/${screenshot.file}`,
113
- contentType: screenshot.contentType,
114
- pageId: screenshot.pageId
115
- })).sort((a, b) => a.timestamp - b.timestamp)
116
- };
117
- }
118
81
  /**
119
82
  * Map screencast frame zip paths to the page that produced them.
120
83
  * Playwright <= 1.62 (trace v8) references frames via `sha1` relative to
@@ -178,6 +141,36 @@ function screenshotResourceName(filename) {
178
141
  return PLAYWRIGHT_SCREENSHOT_PATTERN.test(name) ? name : null;
179
142
  }
180
143
  //#endregion
144
+ //#region src/reporter/trace-zip-builder.ts
145
+ /**
146
+ * Get the zip filename based on test location and ID.
147
+ * Format: {basename(file)}:{line}-{testId}-pw-otel.zip
148
+ * Fallback: {testId}-pw-otel.zip (if no location info)
149
+ */
150
+ function getZipFilename(test, testId) {
151
+ if (test.location) return `${path.basename(test.location.file)}:${test.location.line}-${testId}-pw-otel.zip`;
152
+ return `${testId}-pw-otel.zip`;
153
+ }
154
+ async function createTraceZipBlob(options) {
155
+ const { spans, fixtureSpans, playwrightVersion, screenshots } = options;
156
+ const otlpRequest = buildOtlpRequest(spans, playwrightVersion);
157
+ const traceJson = JSON.stringify(otlpRequest, null, 2);
158
+ const zipWriter = new ZipWriter(new BlobWriter("application/zip"));
159
+ await zipWriter.add("traces/playwright-opentelemetry.json", new Blob([traceJson]).stream());
160
+ if (fixtureSpans.length > 0) {
161
+ const fixtureOtlpRequest = buildOtlpRequest(fixtureSpans, playwrightVersion);
162
+ await zipWriter.add("traces/playwright-fixture-spans.json", new Blob([JSON.stringify(fixtureOtlpRequest, null, 2)]).stream());
163
+ }
164
+ await addScreenshotsToZip(zipWriter, screenshots);
165
+ return zipWriter.close();
166
+ }
167
+ async function writeTraceZip(outputDir, test, zipBlob) {
168
+ const zipFilename = getZipFilename(test, test.id);
169
+ const zipPath = path.join(outputDir, zipFilename);
170
+ const arrayBuffer = await zipBlob.arrayBuffer();
171
+ await fs.writeFile(zipPath, Buffer.from(arrayBuffer));
172
+ }
173
+ //#endregion
181
174
  //#region src/reporter/reporter.ts
182
175
  var PlaywrightOpentelemetryReporter = class {
183
176
  spanBatches = [];
@@ -265,6 +258,7 @@ var PlaywrightOpentelemetryReporter = class {
265
258
  test,
266
259
  spans: testSpans,
267
260
  fixtureSpans,
261
+ screenshotsAttachmentPath: result.attachments.find((attachment) => attachment.name === "playwright-opentelemetry-screenshots" && attachment.path)?.path,
268
262
  traceAttachmentPath: traceAttachment?.path,
269
263
  traceId,
270
264
  config: retainedConfig,
@@ -307,7 +301,7 @@ var PlaywrightOpentelemetryReporter = class {
307
301
  for (const destination of destinations.values()) await sendSpans(destination.spans, destination.options);
308
302
  }
309
303
  async prepareTraceArtifact(options) {
310
- const screenshots = options.traceAttachmentPath ? await extractScreenshotsFromPlaywrightTrace(options.traceAttachmentPath) : /* @__PURE__ */ new Map();
304
+ const screenshots = await readTestScreenshots(options);
311
305
  const traceZipBlobPromise = options.config.storeTraceZip ? createTraceZipBlob({
312
306
  test: options.test,
313
307
  spans: options.spans,
@@ -315,11 +309,12 @@ var PlaywrightOpentelemetryReporter = class {
315
309
  playwrightVersion: options.playwrightVersion,
316
310
  screenshots
317
311
  }) : void 0;
318
- const uploadPromises = options.config.playwrightTraceApiDestinations.filter((destination) => destination.url).map((destination) => this.sendScreenshotsZipToTraceApi({
312
+ const screenshotsZip = screenshots.length > 0 ? await createScreenshotsZip(screenshots) : null;
313
+ const uploadPromises = screenshotsZip ? options.config.playwrightTraceApiDestinations.filter((destination) => destination.url).map((destination) => this.sendScreenshotsZipToTraceApi({
319
314
  traceId: options.traceId,
320
- screenshots,
315
+ screenshotsZip,
321
316
  destination
322
- }));
317
+ })) : [];
323
318
  const [traceZipBlob] = await Promise.all([traceZipBlobPromise, ...uploadPromises]);
324
319
  return { traceZipBlob };
325
320
  }
@@ -356,6 +351,11 @@ var PlaywrightOpentelemetryReporter = class {
356
351
  const attributes = {};
357
352
  attributes[ATTR_TEST_STEP_NAME] = currentTitlePath.join(" > ");
358
353
  attributes[ATTR_TEST_STEP_TITLE] = step.title;
354
+ if (step.subtitle) attributes[ATTR_TEST_STEP_SUBTITLE] = step.subtitle;
355
+ for (const [key, value] of Object.entries(step.params ?? {})) {
356
+ const attributeValue = toStepParamAttribute(value);
357
+ if (attributeValue !== void 0) attributes[`${ATTR_TEST_STEP_PARAM_PREFIX}${key}`] = attributeValue;
358
+ }
359
359
  attributes[ATTR_TEST_STEP_CATEGORY] = step.category;
360
360
  if (phase) attributes[ATTR_TEST_PHASE] = phase;
361
361
  if (step.location) {
@@ -386,8 +386,7 @@ var PlaywrightOpentelemetryReporter = class {
386
386
  return this.debug;
387
387
  }
388
388
  async sendScreenshotsZipToTraceApi(params) {
389
- const { traceId, screenshots, destination } = params;
390
- const screenshotsZip = await createScreenshotsZip(screenshots);
389
+ const { traceId, screenshotsZip, destination } = params;
391
390
  const screenshotUrl = `${destination.url}/playwright-otel-reporter/v1/screenshots.zip`;
392
391
  const response = await fetch(screenshotUrl, {
393
392
  method: "PUT",
@@ -405,6 +404,26 @@ var PlaywrightOpentelemetryReporter = class {
405
404
  }
406
405
  }
407
406
  };
407
+ /**
408
+ * A test's screenshots. Playwright versions with a usable screencast only use
409
+ * the frames the fixture captured and attached; older versions only use
410
+ * Playwright's trace. Never rejects: a test's spans are still sent without
411
+ * its screenshots.
412
+ */
413
+ async function readTestScreenshots(options) {
414
+ if (!options.config.screenshots) return [];
415
+ if (supportsScreencastScreenshots(options.playwrightVersion)) {
416
+ if (!options.screenshotsAttachmentPath) return [];
417
+ try {
418
+ return await readScreenshotsZip(new Blob([await fs.readFile(options.screenshotsAttachmentPath)]));
419
+ } catch (error) {
420
+ console.warn(`Failed to read the test's screenshots: ${error instanceof Error ? error.message : String(error)}`);
421
+ return [];
422
+ }
423
+ }
424
+ if (!options.traceAttachmentPath) return [];
425
+ return Array.from((await extractScreenshotsFromPlaywrightTrace(options.traceAttachmentPath)).values());
426
+ }
408
427
  function getProjectPlaywrightOpentelemetryConfig(project) {
409
428
  return project?.use?.playwrightOpentelemetry;
410
429
  }
@@ -514,10 +533,26 @@ function isInternalFixtureStep(step) {
514
533
  }
515
534
  function isInternalApiRequestStep(step) {
516
535
  if (step.category !== "pw:api" || !step.location?.file) return false;
517
- return isApiRequestStepTitle(step.title) && isInternalFixtureFile(step.location.file);
536
+ return isApiRequestStep(step) && isInternalFixtureFile(step.location.file);
518
537
  }
519
- function isApiRequestStepTitle(title) {
520
- return /^(?:DELETE|FETCH|GET|HEAD|PATCH|POST|PUT)\s+"/.test(title);
538
+ /**
539
+ * `APIRequestContext` calls. From Playwright 1.63 they report a url and a
540
+ * method; before that they show up only in the title, e.g. `GET "/api"`.
541
+ */
542
+ function isApiRequestStep(step) {
543
+ if (step.params) return typeof step.params.url === "string" && typeof step.params.method === "string";
544
+ return /^(?:DELETE|FETCH|GET|HEAD|PATCH|POST|PUT)\s+"/.test(step.title);
545
+ }
546
+ /**
547
+ * Span attributes hold primitives and string arrays, so other param values
548
+ * (options objects, mixed arrays) are stored as JSON.
549
+ */
550
+ function toStepParamAttribute(value) {
551
+ if (value === void 0 || value === null) return void 0;
552
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
553
+ if (Array.isArray(value) && value.every((item) => typeof item === "string")) return value;
554
+ const json = JSON.stringify(value);
555
+ return json === void 0 || json === "{}" ? void 0 : json;
521
556
  }
522
557
  function isInternalFixtureFile(filePath) {
523
558
  const file = filePath.replace(/\\/g, "/");
@@ -1,8 +1,8 @@
1
- const require_config = require("./config-C-inwZvX.cjs");
2
- let node_path = require("node:path");
3
- node_path = require_config.__toESM(node_path, 1);
1
+ const require_screenshots_zip = require("./screenshots-zip-B07U2DaB.cjs");
4
2
  let node_fs_promises = require("node:fs/promises");
5
- node_fs_promises = require_config.__toESM(node_fs_promises, 1);
3
+ node_fs_promises = require_screenshots_zip.__toESM(node_fs_promises, 1);
4
+ let node_path = require("node:path");
5
+ node_path = require_screenshots_zip.__toESM(node_path, 1);
6
6
  let _zip_js_zip_js = require("@zip.js/zip.js");
7
7
  //#region src/reporter/otel-attributes.ts
8
8
  const ATTR_CODE_FILE_PATH = "code.file.path";
@@ -15,20 +15,22 @@ const ATTR_TEST_CASE_RESULT_STATUS = "test.case.result.status";
15
15
  const TEST_SPAN_NAME = "playwright.test";
16
16
  const TEST_STEP_SPAN_NAME = "playwright.test.step";
17
17
  const ATTR_TEST_STEP_NAME = "test.step.name";
18
+ /** Playwright's step title, e.g. `Click` or `Expect "toBeVisible"` */
18
19
  const ATTR_TEST_STEP_TITLE = "test.step.title";
20
+ /** What the step acted on, e.g. the locator of a `Click` or the url of a `Navigate` */
21
+ const ATTR_TEST_STEP_SUBTITLE = "test.step.subtitle";
22
+ /** Prefix for the step's reported params, e.g. `test.step.param.locator` */
23
+ const ATTR_TEST_STEP_PARAM_PREFIX = "test.step.param.";
19
24
  const ATTR_TEST_STEP_CATEGORY = "test.step.category";
20
25
  const ATTR_TEST_PHASE = "playwright.test.phase";
21
26
  //#endregion
22
- //#region src/reporter/trace-zip-builder.ts
27
+ //#region src/reporter/legacy/trace-zip-screenshots.ts
23
28
  /**
24
- * Get the zip filename based on test location and ID.
25
- * Format: {basename(file)}:{line}-{testId}-pw-otel.zip
26
- * Fallback: {testId}-pw-otel.zip (if no location info)
29
+ * LEGACY: reads screenshots out of Playwright's trace.zip, for Playwright
30
+ * older than SCREENCAST_SCREENSHOTS_MIN_PLAYWRIGHT_VERSION. Delete this
31
+ * directory, its tests and the reporter's legacy branch once the peer
32
+ * dependency requires that version.
27
33
  */
28
- function getZipFilename(test, testId) {
29
- if (test.location) return `${node_path.default.basename(test.location.file)}:${test.location.line}-${testId}-pw-otel.zip`;
30
- return `${testId}-pw-otel.zip`;
31
- }
32
34
  const PLAYWRIGHT_TRACE_RESOURCES_DIR = "resources/";
33
35
  const PLAYWRIGHT_TRACE_SCREENCAST_DIR = "screencast/";
34
36
  /**
@@ -42,6 +44,8 @@ const PLAYWRIGHT_SCREENSHOT_PATTERN = /^.+@[a-f0-9]+-\d+\.jpe?g$/i;
42
44
  * (e.g., page@abc123-1766929201038.jpeg) and live in resources/ for
43
45
  * Playwright <= 1.62 or screencast/ for Playwright >= 1.63.
44
46
  *
47
+ * Never rejects: a trace that can't be read gives no screenshots.
48
+ *
45
49
  * @param traceZipPath - Path to the Playwright trace.zip file
46
50
  * @returns Map of filename (without directory prefix) to screenshot resources
47
51
  */
@@ -76,47 +80,6 @@ async function extractScreenshotsFromPlaywrightTrace(traceZipPath) {
76
80
  }
77
81
  return screenshots;
78
82
  }
79
- async function createScreenshotsZip(screenshots) {
80
- const zipWriter = new _zip_js_zip_js.ZipWriter(new _zip_js_zip_js.BlobWriter("application/zip"));
81
- await addScreenshotsToZip(zipWriter, screenshots);
82
- return zipWriter.close();
83
- }
84
- async function createTraceZipBlob(options) {
85
- const { spans, fixtureSpans, playwrightVersion, screenshots } = options;
86
- const otlpRequest = require_config.buildOtlpRequest(spans, playwrightVersion);
87
- const traceJson = JSON.stringify(otlpRequest, null, 2);
88
- const zipWriter = new _zip_js_zip_js.ZipWriter(new _zip_js_zip_js.BlobWriter("application/zip"));
89
- await zipWriter.add("traces/playwright-opentelemetry.json", new Blob([traceJson]).stream());
90
- if (fixtureSpans.length > 0) {
91
- const fixtureOtlpRequest = require_config.buildOtlpRequest(fixtureSpans, playwrightVersion);
92
- await zipWriter.add("traces/playwright-fixture-spans.json", new Blob([JSON.stringify(fixtureOtlpRequest, null, 2)]).stream());
93
- }
94
- await addScreenshotsToZip(zipWriter, screenshots);
95
- return zipWriter.close();
96
- }
97
- async function writeTraceZip(outputDir, test, zipBlob) {
98
- const zipFilename = getZipFilename(test, test.id);
99
- const zipPath = node_path.default.join(outputDir, zipFilename);
100
- const arrayBuffer = await zipBlob.arrayBuffer();
101
- await node_fs_promises.default.writeFile(zipPath, Buffer.from(arrayBuffer));
102
- }
103
- async function addScreenshotsToZip(zipWriter, screenshots) {
104
- const manifest = createScreenshotManifest(screenshots);
105
- await zipWriter.add("manifest.json", new Blob([JSON.stringify(manifest, null, 2)], { type: "application/json" }).stream());
106
- for (const [filename, screenshot] of screenshots.entries()) await zipWriter.add(`screenshots/${filename}`, screenshot.blob.stream());
107
- }
108
- function createScreenshotManifest(screenshots) {
109
- return {
110
- version: 3,
111
- screenshots: Array.from(screenshots.values()).map((screenshot) => ({
112
- timestamp: screenshot.timestamp,
113
- file: screenshot.file,
114
- path: `screenshots/${screenshot.file}`,
115
- contentType: screenshot.contentType,
116
- pageId: screenshot.pageId
117
- })).sort((a, b) => a.timestamp - b.timestamp)
118
- };
119
- }
120
83
  /**
121
84
  * Map screencast frame zip paths to the page that produced them.
122
85
  * Playwright <= 1.62 (trace v8) references frames via `sha1` relative to
@@ -180,6 +143,36 @@ function screenshotResourceName(filename) {
180
143
  return PLAYWRIGHT_SCREENSHOT_PATTERN.test(name) ? name : null;
181
144
  }
182
145
  //#endregion
146
+ //#region src/reporter/trace-zip-builder.ts
147
+ /**
148
+ * Get the zip filename based on test location and ID.
149
+ * Format: {basename(file)}:{line}-{testId}-pw-otel.zip
150
+ * Fallback: {testId}-pw-otel.zip (if no location info)
151
+ */
152
+ function getZipFilename(test, testId) {
153
+ if (test.location) return `${node_path.default.basename(test.location.file)}:${test.location.line}-${testId}-pw-otel.zip`;
154
+ return `${testId}-pw-otel.zip`;
155
+ }
156
+ async function createTraceZipBlob(options) {
157
+ const { spans, fixtureSpans, playwrightVersion, screenshots } = options;
158
+ const otlpRequest = require_screenshots_zip.buildOtlpRequest(spans, playwrightVersion);
159
+ const traceJson = JSON.stringify(otlpRequest, null, 2);
160
+ const zipWriter = new _zip_js_zip_js.ZipWriter(new _zip_js_zip_js.BlobWriter("application/zip"));
161
+ await zipWriter.add("traces/playwright-opentelemetry.json", new Blob([traceJson]).stream());
162
+ if (fixtureSpans.length > 0) {
163
+ const fixtureOtlpRequest = require_screenshots_zip.buildOtlpRequest(fixtureSpans, playwrightVersion);
164
+ await zipWriter.add("traces/playwright-fixture-spans.json", new Blob([JSON.stringify(fixtureOtlpRequest, null, 2)]).stream());
165
+ }
166
+ await require_screenshots_zip.addScreenshotsToZip(zipWriter, screenshots);
167
+ return zipWriter.close();
168
+ }
169
+ async function writeTraceZip(outputDir, test, zipBlob) {
170
+ const zipFilename = getZipFilename(test, test.id);
171
+ const zipPath = node_path.default.join(outputDir, zipFilename);
172
+ const arrayBuffer = await zipBlob.arrayBuffer();
173
+ await node_fs_promises.default.writeFile(zipPath, Buffer.from(arrayBuffer));
174
+ }
175
+ //#endregion
183
176
  //#region src/reporter/reporter.ts
184
177
  var PlaywrightOpentelemetryReporter = class {
185
178
  spanBatches = [];
@@ -193,7 +186,7 @@ var PlaywrightOpentelemetryReporter = class {
193
186
  this.playwrightVersion = config.version;
194
187
  const projects = Array.isArray(config.projects) ? config.projects : [];
195
188
  for (const project of projects) {
196
- const resolvedConfig = require_config.resolvePlaywrightOpentelemetryConfig(getProjectPlaywrightOpentelemetryConfig(project), { requireDestination: true });
189
+ const resolvedConfig = require_screenshots_zip.resolvePlaywrightOpentelemetryConfig(getProjectPlaywrightOpentelemetryConfig(project), { requireDestination: true });
197
190
  this.debug ||= resolvedConfig.debug;
198
191
  }
199
192
  }
@@ -208,12 +201,12 @@ var PlaywrightOpentelemetryReporter = class {
208
201
  retry: result.retry,
209
202
  status: result.status
210
203
  };
211
- const shouldRetainTrace = (trace) => trace === null ? Boolean(traceAttachment) : require_config.shouldRetainPlaywrightTrace(trace, traceRetentionTestInfo);
204
+ const shouldRetainTrace = (trace) => trace === null ? Boolean(traceAttachment) : require_screenshots_zip.shouldRetainPlaywrightTrace(trace, traceRetentionTestInfo);
212
205
  const shouldStoreTraceZip = config.storeTraceZip && shouldRetainTrace(config.trace);
213
206
  const retainedConfig = {
214
207
  ...config,
215
- otlpDestinations: require_config.filterRetainedDestinations(config.otlpDestinations, config.trace, shouldRetainTrace),
216
- playwrightTraceApiDestinations: require_config.filterRetainedDestinations(config.playwrightTraceApiDestinations, config.trace, shouldRetainTrace),
208
+ otlpDestinations: require_screenshots_zip.filterRetainedDestinations(config.otlpDestinations, config.trace, shouldRetainTrace),
209
+ playwrightTraceApiDestinations: require_screenshots_zip.filterRetainedDestinations(config.playwrightTraceApiDestinations, config.trace, shouldRetainTrace),
217
210
  storeTraceZip: shouldStoreTraceZip
218
211
  };
219
212
  if (!hasPlaywrightOpentelemetryDestination(retainedConfig)) return;
@@ -267,6 +260,7 @@ var PlaywrightOpentelemetryReporter = class {
267
260
  test,
268
261
  spans: testSpans,
269
262
  fixtureSpans,
263
+ screenshotsAttachmentPath: result.attachments.find((attachment) => attachment.name === "playwright-opentelemetry-screenshots" && attachment.path)?.path,
270
264
  traceAttachmentPath: traceAttachment?.path,
271
265
  traceId,
272
266
  config: retainedConfig,
@@ -300,16 +294,16 @@ var PlaywrightOpentelemetryReporter = class {
300
294
  if (!destination.url) continue;
301
295
  addDestinationSpans(destinations, batch.spans, {
302
296
  tracesEndpoint: `${destination.url}/v1/traces`,
303
- headers: require_config.withPlaywrightTraceApiHeaders(destination.headers),
297
+ headers: require_screenshots_zip.withPlaywrightTraceApiHeaders(destination.headers),
304
298
  playwrightVersion: this.playwrightVersion || "unknown",
305
299
  debug: batch.config.debug
306
300
  });
307
301
  }
308
302
  }
309
- for (const destination of destinations.values()) await require_config.sendSpans(destination.spans, destination.options);
303
+ for (const destination of destinations.values()) await require_screenshots_zip.sendSpans(destination.spans, destination.options);
310
304
  }
311
305
  async prepareTraceArtifact(options) {
312
- const screenshots = options.traceAttachmentPath ? await extractScreenshotsFromPlaywrightTrace(options.traceAttachmentPath) : /* @__PURE__ */ new Map();
306
+ const screenshots = await readTestScreenshots(options);
313
307
  const traceZipBlobPromise = options.config.storeTraceZip ? createTraceZipBlob({
314
308
  test: options.test,
315
309
  spans: options.spans,
@@ -317,11 +311,12 @@ var PlaywrightOpentelemetryReporter = class {
317
311
  playwrightVersion: options.playwrightVersion,
318
312
  screenshots
319
313
  }) : void 0;
320
- const uploadPromises = options.config.playwrightTraceApiDestinations.filter((destination) => destination.url).map((destination) => this.sendScreenshotsZipToTraceApi({
314
+ const screenshotsZip = screenshots.length > 0 ? await require_screenshots_zip.createScreenshotsZip(screenshots) : null;
315
+ const uploadPromises = screenshotsZip ? options.config.playwrightTraceApiDestinations.filter((destination) => destination.url).map((destination) => this.sendScreenshotsZipToTraceApi({
321
316
  traceId: options.traceId,
322
- screenshots,
317
+ screenshotsZip,
323
318
  destination
324
- }));
319
+ })) : [];
325
320
  const [traceZipBlob] = await Promise.all([traceZipBlobPromise, ...uploadPromises]);
326
321
  return { traceZipBlob };
327
322
  }
@@ -358,6 +353,11 @@ var PlaywrightOpentelemetryReporter = class {
358
353
  const attributes = {};
359
354
  attributes[ATTR_TEST_STEP_NAME] = currentTitlePath.join(" > ");
360
355
  attributes[ATTR_TEST_STEP_TITLE] = step.title;
356
+ if (step.subtitle) attributes[ATTR_TEST_STEP_SUBTITLE] = step.subtitle;
357
+ for (const [key, value] of Object.entries(step.params ?? {})) {
358
+ const attributeValue = toStepParamAttribute(value);
359
+ if (attributeValue !== void 0) attributes[`${ATTR_TEST_STEP_PARAM_PREFIX}${key}`] = attributeValue;
360
+ }
361
361
  attributes[ATTR_TEST_STEP_CATEGORY] = step.category;
362
362
  if (phase) attributes[ATTR_TEST_PHASE] = phase;
363
363
  if (step.location) {
@@ -367,7 +367,7 @@ var PlaywrightOpentelemetryReporter = class {
367
367
  }
368
368
  const stepSpan = {
369
369
  traceId,
370
- spanId: require_config.generateSpanId(),
370
+ spanId: require_screenshots_zip.generateSpanId(),
371
371
  parentSpanId,
372
372
  name: TEST_STEP_SPAN_NAME,
373
373
  startTime: step.startTime,
@@ -388,8 +388,7 @@ var PlaywrightOpentelemetryReporter = class {
388
388
  return this.debug;
389
389
  }
390
390
  async sendScreenshotsZipToTraceApi(params) {
391
- const { traceId, screenshots, destination } = params;
392
- const screenshotsZip = await createScreenshotsZip(screenshots);
391
+ const { traceId, screenshotsZip, destination } = params;
393
392
  const screenshotUrl = `${destination.url}/playwright-otel-reporter/v1/screenshots.zip`;
394
393
  const response = await fetch(screenshotUrl, {
395
394
  method: "PUT",
@@ -397,7 +396,7 @@ var PlaywrightOpentelemetryReporter = class {
397
396
  "content-type": "application/zip",
398
397
  "x-trace-id": traceId,
399
398
  ...destination.headers,
400
- [require_config.PLAYWRIGHT_TRACE_API_SOURCE_HEADER]: require_config.PLAYWRIGHT_TRACE_API_SOURCE_REPORTER
399
+ [require_screenshots_zip.PLAYWRIGHT_TRACE_API_SOURCE_HEADER]: require_screenshots_zip.PLAYWRIGHT_TRACE_API_SOURCE_REPORTER
401
400
  },
402
401
  body: screenshotsZip
403
402
  });
@@ -407,11 +406,31 @@ var PlaywrightOpentelemetryReporter = class {
407
406
  }
408
407
  }
409
408
  };
409
+ /**
410
+ * A test's screenshots. Playwright versions with a usable screencast only use
411
+ * the frames the fixture captured and attached; older versions only use
412
+ * Playwright's trace. Never rejects: a test's spans are still sent without
413
+ * its screenshots.
414
+ */
415
+ async function readTestScreenshots(options) {
416
+ if (!options.config.screenshots) return [];
417
+ if (require_screenshots_zip.supportsScreencastScreenshots(options.playwrightVersion)) {
418
+ if (!options.screenshotsAttachmentPath) return [];
419
+ try {
420
+ return await require_screenshots_zip.readScreenshotsZip(new Blob([await node_fs_promises.default.readFile(options.screenshotsAttachmentPath)]));
421
+ } catch (error) {
422
+ console.warn(`Failed to read the test's screenshots: ${error instanceof Error ? error.message : String(error)}`);
423
+ return [];
424
+ }
425
+ }
426
+ if (!options.traceAttachmentPath) return [];
427
+ return Array.from((await extractScreenshotsFromPlaywrightTrace(options.traceAttachmentPath)).values());
428
+ }
410
429
  function getProjectPlaywrightOpentelemetryConfig(project) {
411
430
  return project?.use?.playwrightOpentelemetry;
412
431
  }
413
432
  function getTestConfig(test) {
414
- return require_config.resolvePlaywrightOpentelemetryConfig(getProjectPlaywrightOpentelemetryConfig(test.parent.project()), { requireDestination: true });
433
+ return require_screenshots_zip.resolvePlaywrightOpentelemetryConfig(getProjectPlaywrightOpentelemetryConfig(test.parent.project()), { requireDestination: true });
415
434
  }
416
435
  function getTestOutputDir(test) {
417
436
  const outputDir = test.parent.project()?.outputDir;
@@ -437,30 +456,30 @@ function hasPlaywrightOpentelemetryDestination(config) {
437
456
  return Boolean(config.storeTraceZip || config.otlpDestinations.some((destination) => destination.url) || config.playwrightTraceApiDestinations.some((destination) => destination.url));
438
457
  }
439
458
  function readTraceContextAttachment(result, testId) {
440
- const attachment = result.attachments.find((attachment) => attachment.name === require_config.TRACE_CONTEXT_ATTACHMENT_NAME);
459
+ const attachment = result.attachments.find((attachment) => attachment.name === require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME);
441
460
  if (!attachment?.body) return {
442
- traceId: require_config.generateTraceId(),
443
- rootSpanId: require_config.generateSpanId()
461
+ traceId: require_screenshots_zip.generateTraceId(),
462
+ rootSpanId: require_screenshots_zip.generateSpanId()
444
463
  };
445
464
  let parsed;
446
465
  try {
447
466
  parsed = JSON.parse(attachment.body.toString("utf-8"));
448
467
  } catch (error) {
449
- throw new Error(`Invalid ${require_config.TRACE_CONTEXT_ATTACHMENT_NAME} attachment for test ${testId}: ${error}`);
468
+ throw new Error(`Invalid ${require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME} attachment for test ${testId}: ${error}`);
450
469
  }
451
- if (!isTraceContextAttachment(parsed)) throw new Error(`Invalid ${require_config.TRACE_CONTEXT_ATTACHMENT_NAME} attachment for test ${testId}: expected { traceId, rootSpanId }`);
470
+ if (!isTraceContextAttachment(parsed)) throw new Error(`Invalid ${require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME} attachment for test ${testId}: expected { traceId, rootSpanId }`);
452
471
  return parsed;
453
472
  }
454
473
  function readFixtureSpansAttachment(result, testId) {
455
- const attachment = result.attachments.find((attachment) => attachment.name === require_config.FIXTURE_SPANS_ATTACHMENT_NAME);
474
+ const attachment = result.attachments.find((attachment) => attachment.name === require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME);
456
475
  if (!attachment?.body) return [];
457
476
  let parsed;
458
477
  try {
459
478
  parsed = JSON.parse(attachment.body.toString("utf-8"));
460
479
  } catch (error) {
461
- throw new Error(`Invalid ${require_config.FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: ${error}`);
480
+ throw new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: ${error}`);
462
481
  }
463
- if (!isRecord(parsed) || !Array.isArray(parsed.spans)) throw new Error(`Invalid ${require_config.FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: expected { spans }`);
482
+ if (!isRecord(parsed) || !Array.isArray(parsed.spans)) throw new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: expected { spans }`);
464
483
  return parsed.spans.map((span, index) => parseFixtureSpan(span, testId, index));
465
484
  }
466
485
  function parseFixtureSpan(value, testId, index) {
@@ -487,7 +506,7 @@ function parseFixtureSpan(value, testId, index) {
487
506
  };
488
507
  }
489
508
  function invalidFixtureSpanError(testId, index) {
490
- return /* @__PURE__ */ new Error(`Invalid ${require_config.FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: invalid span at index ${index}`);
509
+ return /* @__PURE__ */ new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: invalid span at index ${index}`);
491
510
  }
492
511
  function parseAttachmentDate(value) {
493
512
  if (typeof value !== "string") return;
@@ -516,10 +535,26 @@ function isInternalFixtureStep(step) {
516
535
  }
517
536
  function isInternalApiRequestStep(step) {
518
537
  if (step.category !== "pw:api" || !step.location?.file) return false;
519
- return isApiRequestStepTitle(step.title) && isInternalFixtureFile(step.location.file);
538
+ return isApiRequestStep(step) && isInternalFixtureFile(step.location.file);
520
539
  }
521
- function isApiRequestStepTitle(title) {
522
- return /^(?:DELETE|FETCH|GET|HEAD|PATCH|POST|PUT)\s+"/.test(title);
540
+ /**
541
+ * `APIRequestContext` calls. From Playwright 1.63 they report a url and a
542
+ * method; before that they show up only in the title, e.g. `GET "/api"`.
543
+ */
544
+ function isApiRequestStep(step) {
545
+ if (step.params) return typeof step.params.url === "string" && typeof step.params.method === "string";
546
+ return /^(?:DELETE|FETCH|GET|HEAD|PATCH|POST|PUT)\s+"/.test(step.title);
547
+ }
548
+ /**
549
+ * Span attributes hold primitives and string arrays, so other param values
550
+ * (options objects, mixed arrays) are stored as JSON.
551
+ */
552
+ function toStepParamAttribute(value) {
553
+ if (value === void 0 || value === null) return void 0;
554
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return value;
555
+ if (Array.isArray(value) && value.every((item) => typeof item === "string")) return value;
556
+ const json = JSON.stringify(value);
557
+ return json === void 0 || json === "{}" ? void 0 : json;
523
558
  }
524
559
  function isInternalFixtureFile(filePath) {
525
560
  const file = filePath.replace(/\\/g, "/");
package/dist/reporter.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/reporter/index.ts
2
- var reporter_default = require("./reporter-_hqajn5O.cjs").PlaywrightOpentelemetryReporter;
2
+ var reporter_default = require("./reporter-DMlPQnrW.cjs").PlaywrightOpentelemetryReporter;
3
3
  //#endregion
4
4
  module.exports = reporter_default;
package/dist/reporter.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-DV6yWUMU.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-CWAovnMj.mjs";
2
2
  //#region src/reporter/index.ts
3
3
  var reporter_default = PlaywrightOpentelemetryReporter;
4
4
  //#endregion