playwright-opentelemetry 0.15.0 → 0.17.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 CHANGED
@@ -76,7 +76,7 @@ npx @playwright-opentelemetry/trace-viewer
76
76
 
77
77
  ## Documentation
78
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).
79
+ Full documentation, including trace retention options, screenshot capture, multiple OTLP destinations, output formats, and the self-hostable Trace API, lives in the [project docs](https://github.com/endformdev/playwright-opentelemetry#documentation).
80
80
 
81
81
  ## Developing the reporter / fixture
82
82
 
package/dist/fixture.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_screenshots_zip = require("./screenshots-zip-C3N3xvp7.cjs");
2
+ const require_screenshots_zip = require("./screenshots-zip-CDmixuxY.cjs");
3
3
  let node_fs_promises = require("node:fs/promises");
4
4
  node_fs_promises = require_screenshots_zip.__toESM(node_fs_promises, 1);
5
5
  let node_path = require("node:path");
@@ -875,11 +875,11 @@ function shouldCaptureScreenshots(config, options) {
875
875
  return config.screenshots && storesScreenshots(config, (trace) => require_screenshots_zip.couldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo));
876
876
  }
877
877
  /**
878
- * Stops the capture and, if the test is retained, attaches its frames as a
879
- * screenshots ZIP for the reporter to upload. Never rejects: a test must not
880
- * fail because its screenshots couldn't be stored.
878
+ * Stops the capture and, if the test is retained, hands its frames to the
879
+ * reporter as a screenshots ZIP. Never rejects: a test must not fail because
880
+ * its screenshots couldn't be stored.
881
881
  */
882
- async function attachScreenshots(capture, config, options) {
882
+ async function handOffScreenshots(capture, config, options) {
883
883
  try {
884
884
  const frames = await capture.stop();
885
885
  const retained = storesScreenshots(config, (trace) => require_screenshots_zip.shouldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo));
@@ -893,8 +893,13 @@ async function attachScreenshots(capture, config, options) {
893
893
  viewportHeight: frame.viewportHeight,
894
894
  blob: new Blob([await node_fs_promises.default.readFile(frame.path)])
895
895
  }))));
896
+ const zipBytes = new Uint8Array(await zip.arrayBuffer());
897
+ if (!config.attachFixtureData) {
898
+ await require_screenshots_zip.writeFixtureHandoffFile(options.testInfo, require_screenshots_zip.SCREENSHOTS_HANDOFF_FILE, zipBytes);
899
+ return;
900
+ }
896
901
  const zipPath = node_path.default.join(capture.dir, "screenshots.zip");
897
- await node_fs_promises.default.writeFile(zipPath, Buffer.from(await zip.arrayBuffer()));
902
+ await node_fs_promises.default.writeFile(zipPath, zipBytes);
898
903
  await options.testInfo.attach(require_screenshots_zip.SCREENSHOTS_ATTACHMENT_NAME, {
899
904
  path: zipPath,
900
905
  contentType: "application/zip"
@@ -1034,7 +1039,7 @@ function createPlaywrightOtelTest(testBase) {
1034
1039
  return testBase.extend({
1035
1040
  playwrightOpentelemetry: [void 0, { option: true }],
1036
1041
  _playwrightOpentelemetryReporterCheck: [async ({}, use, workerInfo) => {
1037
- if (!hasPlaywrightOpentelemetryReporter(workerInfo.config.reporter)) throw new Error(MISSING_PLAYWRIGHT_OPENTELEMETRY_REPORTER_ERROR);
1042
+ if (workerInfo.project.use.playwrightOpentelemetry?.attachFixtureData !== true && !hasPlaywrightOpentelemetryReporter(workerInfo.config.reporter)) throw new Error(MISSING_PLAYWRIGHT_OPENTELEMETRY_REPORTER_ERROR);
1038
1043
  await use();
1039
1044
  }, {
1040
1045
  scope: "worker",
@@ -1060,7 +1065,7 @@ function createPlaywrightOtelTest(testBase) {
1060
1065
  }, { auto: true }],
1061
1066
  testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
1062
1067
  const config = require_screenshots_zip.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
1063
- const traceContext = await require_screenshots_zip.createTestTraceContext(testInfo);
1068
+ const traceContext = await require_screenshots_zip.createTestTraceContext(testInfo, config);
1064
1069
  const registration = require_screenshots_zip.registerExpectedTrace(traceContext, config, {
1065
1070
  trace,
1066
1071
  testInfo
@@ -1104,7 +1109,7 @@ function createPlaywrightOtelTest(testBase) {
1104
1109
  } finally {
1105
1110
  newContexts.delete(addContext);
1106
1111
  }
1107
- await attachScreenshots(capture, config, {
1112
+ await handOffScreenshots(capture, config, {
1108
1113
  trace,
1109
1114
  testInfo
1110
1115
  });
@@ -1,5 +1,5 @@
1
- import { n as Span, r as SpanEvent } from "./reporter-CLzdtg6G.cjs";
2
- import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./index-DFY22ysa.cjs";
1
+ import { n as Span, r as SpanEvent } from "./reporter-DtVv7zcl.cjs";
2
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./index-g9K4ZUC_.cjs";
3
3
  import { BrowserContext, ConsoleMessage, Page, Request } from "@playwright/test";
4
4
  export * from "@playwright/test";
5
5
 
@@ -1,5 +1,5 @@
1
- import { n as Span, r as SpanEvent } from "./reporter-CLzdtg6G.mjs";
2
- import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./index-DFY22ysa.mjs";
1
+ import { n as Span, r as SpanEvent } from "./reporter-DtVv7zcl.mjs";
2
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./index-g9K4ZUC_.mjs";
3
3
  import { BrowserContext, ConsoleMessage, Page, Request } from "@playwright/test";
4
4
  export * from "@playwright/test";
5
5
 
package/dist/fixture.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as supportsScreencastScreenshots, d as flushFixtureSpans, f as registerExpectedTrace, h as filterRetainedDestinations, m as shouldRetainPlaywrightTrace, o as resolvePlaywrightOpentelemetryConfig, p as couldRetainPlaywrightTrace, r as createScreenshotsZip, s as BROWSER_SERVICE_NAME, t as SCREENSHOTS_ATTACHMENT_NAME, u as createTestTraceContext, y as generateSpanId } from "./screenshots-zip-BzI9Jpan.mjs";
1
+ import { T as generateSpanId, a as supportsScreencastScreenshots, b as writeFixtureHandoffFile, d as flushFixtureSpans, f as registerExpectedTrace, g as SCREENSHOTS_HANDOFF_FILE, m as shouldRetainPlaywrightTrace, o as resolvePlaywrightOpentelemetryConfig, p as couldRetainPlaywrightTrace, r as createScreenshotsZip, s as BROWSER_SERVICE_NAME, t as SCREENSHOTS_ATTACHMENT_NAME, u as createTestTraceContext, x as filterRetainedDestinations } from "./screenshots-zip-D8_7p-Wx.mjs";
2
2
  import fs from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import { test as test$1 } from "@playwright/test";
@@ -872,11 +872,11 @@ function shouldCaptureScreenshots(config, options) {
872
872
  return config.screenshots && storesScreenshots(config, (trace) => couldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo));
873
873
  }
874
874
  /**
875
- * Stops the capture and, if the test is retained, attaches its frames as a
876
- * screenshots ZIP for the reporter to upload. Never rejects: a test must not
877
- * fail because its screenshots couldn't be stored.
875
+ * Stops the capture and, if the test is retained, hands its frames to the
876
+ * reporter as a screenshots ZIP. Never rejects: a test must not fail because
877
+ * its screenshots couldn't be stored.
878
878
  */
879
- async function attachScreenshots(capture, config, options) {
879
+ async function handOffScreenshots(capture, config, options) {
880
880
  try {
881
881
  const frames = await capture.stop();
882
882
  const retained = storesScreenshots(config, (trace) => shouldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo));
@@ -890,8 +890,13 @@ async function attachScreenshots(capture, config, options) {
890
890
  viewportHeight: frame.viewportHeight,
891
891
  blob: new Blob([await fs.readFile(frame.path)])
892
892
  }))));
893
+ const zipBytes = new Uint8Array(await zip.arrayBuffer());
894
+ if (!config.attachFixtureData) {
895
+ await writeFixtureHandoffFile(options.testInfo, SCREENSHOTS_HANDOFF_FILE, zipBytes);
896
+ return;
897
+ }
893
898
  const zipPath = path.join(capture.dir, "screenshots.zip");
894
- await fs.writeFile(zipPath, Buffer.from(await zip.arrayBuffer()));
899
+ await fs.writeFile(zipPath, zipBytes);
895
900
  await options.testInfo.attach(SCREENSHOTS_ATTACHMENT_NAME, {
896
901
  path: zipPath,
897
902
  contentType: "application/zip"
@@ -1031,7 +1036,7 @@ function createPlaywrightOtelTest(testBase) {
1031
1036
  return testBase.extend({
1032
1037
  playwrightOpentelemetry: [void 0, { option: true }],
1033
1038
  _playwrightOpentelemetryReporterCheck: [async ({}, use, workerInfo) => {
1034
- if (!hasPlaywrightOpentelemetryReporter(workerInfo.config.reporter)) throw new Error(MISSING_PLAYWRIGHT_OPENTELEMETRY_REPORTER_ERROR);
1039
+ if (workerInfo.project.use.playwrightOpentelemetry?.attachFixtureData !== true && !hasPlaywrightOpentelemetryReporter(workerInfo.config.reporter)) throw new Error(MISSING_PLAYWRIGHT_OPENTELEMETRY_REPORTER_ERROR);
1035
1040
  await use();
1036
1041
  }, {
1037
1042
  scope: "worker",
@@ -1057,7 +1062,7 @@ function createPlaywrightOtelTest(testBase) {
1057
1062
  }, { auto: true }],
1058
1063
  testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
1059
1064
  const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
1060
- const traceContext = await createTestTraceContext(testInfo);
1065
+ const traceContext = await createTestTraceContext(testInfo, config);
1061
1066
  const registration = registerExpectedTrace(traceContext, config, {
1062
1067
  trace,
1063
1068
  testInfo
@@ -1101,7 +1106,7 @@ function createPlaywrightOtelTest(testBase) {
1101
1106
  } finally {
1102
1107
  newContexts.delete(addContext);
1103
1108
  }
1104
- await attachScreenshots(capture, config, {
1109
+ await handOffScreenshots(capture, config, {
1105
1110
  trace,
1106
1111
  testInfo
1107
1112
  });
@@ -30,6 +30,15 @@ interface PlaywrightOpentelemetryConfig {
30
30
  * destinations and the local trace ZIP. Defaults to true.
31
31
  */
32
32
  screenshots?: boolean;
33
+ /**
34
+ * Attach the fixture's data (trace context, fixture spans and screenshots)
35
+ * to each test result, so it travels with blob reports and the reporter can
36
+ * run in `merge-reports` instead of in the test run. Playwright then copies
37
+ * that data into its own trace and HTML report. Defaults to false: the
38
+ * fixture leaves it in the project's output directory for the reporter,
39
+ * which must then run in the same test run.
40
+ */
41
+ attachFixtureData?: boolean;
33
42
  propagateTraceHeaders?: boolean;
34
43
  debug?: boolean;
35
44
  }
@@ -30,6 +30,15 @@ interface PlaywrightOpentelemetryConfig {
30
30
  * destinations and the local trace ZIP. Defaults to true.
31
31
  */
32
32
  screenshots?: boolean;
33
+ /**
34
+ * Attach the fixture's data (trace context, fixture spans and screenshots)
35
+ * to each test result, so it travels with blob reports and the reporter can
36
+ * run in `merge-reports` instead of in the test run. Playwright then copies
37
+ * that data into its own trace and HTML report. Defaults to false: the
38
+ * fixture leaves it in the project's output directory for the reporter,
39
+ * which must then run in the same test run.
40
+ */
41
+ attachFixtureData?: boolean;
33
42
  propagateTraceHeaders?: boolean;
34
43
  debug?: boolean;
35
44
  }
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/index.ts
2
- var src_default = require("./reporter-Dnqohjyo.cjs").PlaywrightOpentelemetryReporter;
2
+ var src_default = require("./reporter-C_sXaF-4.cjs").PlaywrightOpentelemetryReporter;
3
3
  //#endregion
4
4
  module.exports = src_default;
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-CLzdtg6G.cjs";
2
- import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./index-DFY22ysa.cjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-DtVv7zcl.cjs";
2
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./index-g9K4ZUC_.cjs";
3
3
  export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryDestination, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, PlaywrightOpentelemetryReporter as default };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-CLzdtg6G.mjs";
2
- import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./index-DFY22ysa.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-DtVv7zcl.mjs";
2
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./index-g9K4ZUC_.mjs";
3
3
  export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryDestination, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, PlaywrightOpentelemetryReporter as default };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-CMGLSTHi.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-B7K2L2XR.mjs";
2
2
  //#region src/index.ts
3
3
  var src_default = PlaywrightOpentelemetryReporter;
4
4
  //#endregion
@@ -1,4 +1,5 @@
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-BzI9Jpan.mjs";
1
+ import { C as PLAYWRIGHT_TRACE_API_SOURCE_REPORTER, D as sendSpans, E as generateTraceId, O as withPlaywrightTraceApiHeaders, S as PLAYWRIGHT_TRACE_API_SOURCE_HEADER, T as generateSpanId, a as supportsScreencastScreenshots, c as FIXTURE_SPANS_ATTACHMENT_NAME, i as readScreenshotsZip, l as TRACE_CONTEXT_ATTACHMENT_NAME, m as shouldRetainPlaywrightTrace, n as addScreenshotsToZip, o as resolvePlaywrightOpentelemetryConfig, r as createScreenshotsZip, t as SCREENSHOTS_ATTACHMENT_NAME, v as fixtureHandoffDir, w as buildOtlpRequest, x as filterRetainedDestinations, y as fixtureHandoffRoot } from "./screenshots-zip-D8_7p-Wx.mjs";
2
+ import fsSync from "node:fs";
2
3
  import fs from "node:fs/promises";
3
4
  import path from "node:path";
4
5
  import { BlobReader, BlobWriter, TextWriter, ZipReader, ZipWriter } from "@zip.js/zip.js";
@@ -175,6 +176,7 @@ async function writeTraceZip(outputDir, test, zipBlob) {
175
176
  var PlaywrightOpentelemetryReporter = class {
176
177
  spanBatches = [];
177
178
  pendingTraceArtifacts = [];
179
+ fixtureHandoffRoots = /* @__PURE__ */ new Set();
178
180
  rootDir;
179
181
  playwrightVersion;
180
182
  debug = false;
@@ -192,6 +194,7 @@ var PlaywrightOpentelemetryReporter = class {
192
194
  onStepBegin(_test, _result, _step) {}
193
195
  onStepEnd(_test, _result, _step) {}
194
196
  onTestEnd(test, result) {
197
+ const fixtureData = this.takeFixtureData(test, result);
195
198
  const config = getTestConfig(test);
196
199
  const traceAttachment = result.attachments.find((attachment) => attachment.name === "trace" && attachment.contentType === "application/zip" && attachment.path);
197
200
  const traceRetentionTestInfo = {
@@ -210,8 +213,8 @@ var PlaywrightOpentelemetryReporter = class {
210
213
  if (!hasPlaywrightOpentelemetryDestination(retainedConfig)) return;
211
214
  const testId = test.id;
212
215
  const outputDir = getTestOutputDir(test);
213
- const { traceId, rootSpanId: testSpanId } = readTraceContextAttachment(result, testId);
214
- const fixtureSpans = retainedConfig.storeTraceZip ? readFixtureSpansAttachment(result, testId) : [];
216
+ const { traceId, rootSpanId: testSpanId } = parseTraceContext(fixtureData.traceContext, testId);
217
+ const fixtureSpans = retainedConfig.storeTraceZip ? parseFixtureSpans(fixtureData.fixtureSpans, testId) : [];
215
218
  result.annotations.push({
216
219
  type: "playwrightOpentelemetryTraceId",
217
220
  description: traceId
@@ -256,7 +259,7 @@ var PlaywrightOpentelemetryReporter = class {
256
259
  test,
257
260
  spans: testSpans,
258
261
  fixtureSpans,
259
- screenshotsAttachmentPath: result.attachments.find((attachment) => attachment.name === "playwright-opentelemetry-screenshots" && attachment.path)?.path,
262
+ screenshotsZip: fixtureData.screenshotsZip,
260
263
  traceAttachmentPath: traceAttachment?.path,
261
264
  traceId,
262
265
  config: retainedConfig,
@@ -270,16 +273,12 @@ var PlaywrightOpentelemetryReporter = class {
270
273
  }
271
274
  }
272
275
  async onEnd(_result) {
273
- for (const artifact of this.pendingTraceArtifacts) {
274
- const prepared = await artifact.prepared;
275
- if ("error" in prepared) throw prepared.error;
276
- if (prepared.traceZipBlob) await writeTraceZip(artifact.outputDir, artifact.test, prepared.traceZipBlob);
277
- }
276
+ for (const root of this.fixtureHandoffRoots) await fs.rmdir(root).catch(() => {});
278
277
  const destinations = /* @__PURE__ */ new Map();
279
278
  for (const batch of this.spanBatches) {
280
279
  for (const destination of batch.config.otlpDestinations) {
281
280
  if (!destination.url) continue;
282
- addDestinationSpans(destinations, batch.spans, {
281
+ addDestinationSpans(destinations, batch.spans, "otlp", {
283
282
  tracesEndpoint: destination.url,
284
283
  headers: destination.headers,
285
284
  playwrightVersion: this.playwrightVersion || "unknown",
@@ -288,7 +287,7 @@ var PlaywrightOpentelemetryReporter = class {
288
287
  }
289
288
  for (const destination of batch.config.playwrightTraceApiDestinations) {
290
289
  if (!destination.url) continue;
291
- addDestinationSpans(destinations, batch.spans, {
290
+ addDestinationSpans(destinations, batch.spans, "trace-api", {
292
291
  tracesEndpoint: `${destination.url}/v1/traces`,
293
292
  headers: withPlaywrightTraceApiHeaders(destination.headers),
294
293
  playwrightVersion: this.playwrightVersion || "unknown",
@@ -296,7 +295,55 @@ var PlaywrightOpentelemetryReporter = class {
296
295
  });
297
296
  }
298
297
  }
299
- for (const destination of destinations.values()) await sendSpans(destination.spans, destination.options);
298
+ const sendFailures = (await Promise.all([...destinations.values()].map(async (destination) => {
299
+ try {
300
+ await sendSpans(destination.spans, destination.options);
301
+ return [];
302
+ } catch (error) {
303
+ return [{
304
+ destination,
305
+ error
306
+ }];
307
+ }
308
+ }))).flat();
309
+ for (const failure of sendFailures) console.warn(`Failed to send spans to ${failure.destination.options.tracesEndpoint}: ${errorMessage(failure.error)}`);
310
+ for (const artifact of this.pendingTraceArtifacts) {
311
+ const prepared = await artifact.prepared;
312
+ if ("error" in prepared) throw prepared.error;
313
+ if (prepared.traceZipBlob) await writeTraceZip(artifact.outputDir, artifact.test, prepared.traceZipBlob);
314
+ }
315
+ const traceApiFailure = sendFailures.find((failure) => failure.destination.kind === "trace-api");
316
+ if (traceApiFailure) throw traceApiFailure.error;
317
+ }
318
+ /**
319
+ * What the fixture handed over for this test attempt: its attachments with
320
+ * `attachFixtureData`, otherwise the files in the attempt's handoff
321
+ * directory, which is deleted here whether or not the test is reported.
322
+ */
323
+ takeFixtureData(test, result) {
324
+ const attachment = (name) => result.attachments.find((attachment) => attachment.name === name);
325
+ const screenshotsAttachmentPath = attachment(SCREENSHOTS_ATTACHMENT_NAME)?.path;
326
+ const attached = {
327
+ traceContext: attachment(TRACE_CONTEXT_ATTACHMENT_NAME)?.body,
328
+ fixtureSpans: attachment(FIXTURE_SPANS_ATTACHMENT_NAME)?.body,
329
+ screenshotsZip: screenshotsAttachmentPath ? readFixtureFile(screenshotsAttachmentPath, { required: true }) : void 0
330
+ };
331
+ const outputDir = getProjectOutputDir(test);
332
+ if (!outputDir) return attached;
333
+ this.fixtureHandoffRoots.add(fixtureHandoffRoot(outputDir));
334
+ const dir = fixtureHandoffDir(outputDir, test.id, result.retry);
335
+ try {
336
+ return {
337
+ traceContext: attached.traceContext ?? readFixtureFile(path.join(dir, "trace-context.json")),
338
+ fixtureSpans: attached.fixtureSpans ?? readFixtureFile(path.join(dir, "fixture-spans.json")),
339
+ screenshotsZip: attached.screenshotsZip ?? readFixtureFile(path.join(dir, "screenshots.zip"))
340
+ };
341
+ } finally {
342
+ fsSync.rmSync(dir, {
343
+ recursive: true,
344
+ force: true
345
+ });
346
+ }
300
347
  }
301
348
  async prepareTraceArtifact(options) {
302
349
  const screenshots = await readTestScreenshots(options);
@@ -385,16 +432,16 @@ var PlaywrightOpentelemetryReporter = class {
385
432
  };
386
433
  /**
387
434
  * A test's screenshots. Playwright versions with a usable screencast only use
388
- * the frames the fixture captured and attached; older versions only use
435
+ * the frames the fixture captured; older versions only use
389
436
  * Playwright's trace. Never rejects: a test's spans are still sent without
390
437
  * its screenshots.
391
438
  */
392
439
  async function readTestScreenshots(options) {
393
440
  if (!options.config.screenshots) return [];
394
441
  if (supportsScreencastScreenshots(options.playwrightVersion)) {
395
- if (!options.screenshotsAttachmentPath) return [];
442
+ if (!options.screenshotsZip) return [];
396
443
  try {
397
- return await readScreenshotsZip(new Blob([await fs.readFile(options.screenshotsAttachmentPath)]));
444
+ return await readScreenshotsZip(new Blob([options.screenshotsZip]));
398
445
  } catch (error) {
399
446
  console.warn(`Failed to read the test's screenshots: ${error instanceof Error ? error.message : String(error)}`);
400
447
  return [];
@@ -409,12 +456,19 @@ function getProjectPlaywrightOpentelemetryConfig(project) {
409
456
  function getTestConfig(test) {
410
457
  return resolvePlaywrightOpentelemetryConfig(getProjectPlaywrightOpentelemetryConfig(test.parent.project()), { requireDestination: true });
411
458
  }
459
+ function getProjectOutputDir(test) {
460
+ return test.parent.project()?.outputDir;
461
+ }
412
462
  function getTestOutputDir(test) {
413
- const outputDir = test.parent.project()?.outputDir;
463
+ const outputDir = getProjectOutputDir(test);
414
464
  if (!outputDir) throw new Error(`No outputDir found for test "${test.id}"`);
415
465
  return outputDir;
416
466
  }
417
- function addDestinationSpans(destinations, spans, options) {
467
+ function errorMessage(error) {
468
+ if (error instanceof Error) return error.message;
469
+ return String(error);
470
+ }
471
+ function addDestinationSpans(destinations, spans, kind, options) {
418
472
  const key = JSON.stringify(options);
419
473
  const destination = destinations.get(key);
420
474
  if (destination) {
@@ -422,6 +476,7 @@ function addDestinationSpans(destinations, spans, options) {
422
476
  return;
423
477
  }
424
478
  destinations.set(key, {
479
+ kind,
425
480
  spans: [...spans],
426
481
  options
427
482
  });
@@ -432,31 +487,41 @@ function hasTraceApiDestination(config) {
432
487
  function hasPlaywrightOpentelemetryDestination(config) {
433
488
  return Boolean(config.storeTraceZip || config.otlpDestinations.some((destination) => destination.url) || config.playwrightTraceApiDestinations.some((destination) => destination.url));
434
489
  }
435
- function readTraceContextAttachment(result, testId) {
436
- const attachment = result.attachments.find((attachment) => attachment.name === TRACE_CONTEXT_ATTACHMENT_NAME);
437
- if (!attachment?.body) return {
490
+ /**
491
+ * A file the fixture left, or undefined when it left none. Handoff files are
492
+ * optional; an attachment's file is not, so a missing one is reported.
493
+ */
494
+ function readFixtureFile(filePath, options = {}) {
495
+ try {
496
+ return fsSync.readFileSync(filePath);
497
+ } catch (error) {
498
+ if (options.required || error.code !== "ENOENT") console.warn(`Failed to read ${path.basename(filePath)} from the playwright-opentelemetry fixture: ${errorMessage(error)}`);
499
+ return;
500
+ }
501
+ }
502
+ function parseTraceContext(body, testId) {
503
+ if (!body) return {
438
504
  traceId: generateTraceId(),
439
505
  rootSpanId: generateSpanId()
440
506
  };
441
507
  let parsed;
442
508
  try {
443
- parsed = JSON.parse(attachment.body.toString("utf-8"));
509
+ parsed = JSON.parse(body.toString("utf-8"));
444
510
  } catch (error) {
445
- throw new Error(`Invalid ${TRACE_CONTEXT_ATTACHMENT_NAME} attachment for test ${testId}: ${error}`);
511
+ throw new Error(`Invalid ${TRACE_CONTEXT_ATTACHMENT_NAME} for test ${testId}: ${error}`);
446
512
  }
447
- if (!isTraceContextAttachment(parsed)) throw new Error(`Invalid ${TRACE_CONTEXT_ATTACHMENT_NAME} attachment for test ${testId}: expected { traceId, rootSpanId }`);
513
+ if (!isTraceContextAttachment(parsed)) throw new Error(`Invalid ${TRACE_CONTEXT_ATTACHMENT_NAME} for test ${testId}: expected { traceId, rootSpanId }`);
448
514
  return parsed;
449
515
  }
450
- function readFixtureSpansAttachment(result, testId) {
451
- const attachment = result.attachments.find((attachment) => attachment.name === FIXTURE_SPANS_ATTACHMENT_NAME);
452
- if (!attachment?.body) return [];
516
+ function parseFixtureSpans(body, testId) {
517
+ if (!body) return [];
453
518
  let parsed;
454
519
  try {
455
- parsed = JSON.parse(attachment.body.toString("utf-8"));
520
+ parsed = JSON.parse(body.toString("utf-8"));
456
521
  } catch (error) {
457
- throw new Error(`Invalid ${FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: ${error}`);
522
+ throw new Error(`Invalid ${FIXTURE_SPANS_ATTACHMENT_NAME} for test ${testId}: ${error}`);
458
523
  }
459
- if (!isRecord(parsed) || !Array.isArray(parsed.spans)) throw new Error(`Invalid ${FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: expected { spans }`);
524
+ if (!isRecord(parsed) || !Array.isArray(parsed.spans)) throw new Error(`Invalid ${FIXTURE_SPANS_ATTACHMENT_NAME} for test ${testId}: expected { spans }`);
460
525
  return parsed.spans.map((span, index) => parseFixtureSpan(span, testId, index));
461
526
  }
462
527
  function parseFixtureSpan(value, testId, index) {
@@ -483,7 +548,7 @@ function parseFixtureSpan(value, testId, index) {
483
548
  };
484
549
  }
485
550
  function invalidFixtureSpanError(testId, index) {
486
- return /* @__PURE__ */ new Error(`Invalid ${FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: invalid span at index ${index}`);
551
+ return /* @__PURE__ */ new Error(`Invalid ${FIXTURE_SPANS_ATTACHMENT_NAME} for test ${testId}: invalid span at index ${index}`);
487
552
  }
488
553
  function parseAttachmentDate(value) {
489
554
  if (typeof value !== "string") return;
@@ -1,4 +1,6 @@
1
- const require_screenshots_zip = require("./screenshots-zip-C3N3xvp7.cjs");
1
+ const require_screenshots_zip = require("./screenshots-zip-CDmixuxY.cjs");
2
+ let node_fs = require("node:fs");
3
+ node_fs = require_screenshots_zip.__toESM(node_fs, 1);
2
4
  let node_fs_promises = require("node:fs/promises");
3
5
  node_fs_promises = require_screenshots_zip.__toESM(node_fs_promises, 1);
4
6
  let node_path = require("node:path");
@@ -177,6 +179,7 @@ async function writeTraceZip(outputDir, test, zipBlob) {
177
179
  var PlaywrightOpentelemetryReporter = class {
178
180
  spanBatches = [];
179
181
  pendingTraceArtifacts = [];
182
+ fixtureHandoffRoots = /* @__PURE__ */ new Set();
180
183
  rootDir;
181
184
  playwrightVersion;
182
185
  debug = false;
@@ -194,6 +197,7 @@ var PlaywrightOpentelemetryReporter = class {
194
197
  onStepBegin(_test, _result, _step) {}
195
198
  onStepEnd(_test, _result, _step) {}
196
199
  onTestEnd(test, result) {
200
+ const fixtureData = this.takeFixtureData(test, result);
197
201
  const config = getTestConfig(test);
198
202
  const traceAttachment = result.attachments.find((attachment) => attachment.name === "trace" && attachment.contentType === "application/zip" && attachment.path);
199
203
  const traceRetentionTestInfo = {
@@ -212,8 +216,8 @@ var PlaywrightOpentelemetryReporter = class {
212
216
  if (!hasPlaywrightOpentelemetryDestination(retainedConfig)) return;
213
217
  const testId = test.id;
214
218
  const outputDir = getTestOutputDir(test);
215
- const { traceId, rootSpanId: testSpanId } = readTraceContextAttachment(result, testId);
216
- const fixtureSpans = retainedConfig.storeTraceZip ? readFixtureSpansAttachment(result, testId) : [];
219
+ const { traceId, rootSpanId: testSpanId } = parseTraceContext(fixtureData.traceContext, testId);
220
+ const fixtureSpans = retainedConfig.storeTraceZip ? parseFixtureSpans(fixtureData.fixtureSpans, testId) : [];
217
221
  result.annotations.push({
218
222
  type: "playwrightOpentelemetryTraceId",
219
223
  description: traceId
@@ -258,7 +262,7 @@ var PlaywrightOpentelemetryReporter = class {
258
262
  test,
259
263
  spans: testSpans,
260
264
  fixtureSpans,
261
- screenshotsAttachmentPath: result.attachments.find((attachment) => attachment.name === "playwright-opentelemetry-screenshots" && attachment.path)?.path,
265
+ screenshotsZip: fixtureData.screenshotsZip,
262
266
  traceAttachmentPath: traceAttachment?.path,
263
267
  traceId,
264
268
  config: retainedConfig,
@@ -272,16 +276,12 @@ var PlaywrightOpentelemetryReporter = class {
272
276
  }
273
277
  }
274
278
  async onEnd(_result) {
275
- for (const artifact of this.pendingTraceArtifacts) {
276
- const prepared = await artifact.prepared;
277
- if ("error" in prepared) throw prepared.error;
278
- if (prepared.traceZipBlob) await writeTraceZip(artifact.outputDir, artifact.test, prepared.traceZipBlob);
279
- }
279
+ for (const root of this.fixtureHandoffRoots) await node_fs_promises.default.rmdir(root).catch(() => {});
280
280
  const destinations = /* @__PURE__ */ new Map();
281
281
  for (const batch of this.spanBatches) {
282
282
  for (const destination of batch.config.otlpDestinations) {
283
283
  if (!destination.url) continue;
284
- addDestinationSpans(destinations, batch.spans, {
284
+ addDestinationSpans(destinations, batch.spans, "otlp", {
285
285
  tracesEndpoint: destination.url,
286
286
  headers: destination.headers,
287
287
  playwrightVersion: this.playwrightVersion || "unknown",
@@ -290,7 +290,7 @@ var PlaywrightOpentelemetryReporter = class {
290
290
  }
291
291
  for (const destination of batch.config.playwrightTraceApiDestinations) {
292
292
  if (!destination.url) continue;
293
- addDestinationSpans(destinations, batch.spans, {
293
+ addDestinationSpans(destinations, batch.spans, "trace-api", {
294
294
  tracesEndpoint: `${destination.url}/v1/traces`,
295
295
  headers: require_screenshots_zip.withPlaywrightTraceApiHeaders(destination.headers),
296
296
  playwrightVersion: this.playwrightVersion || "unknown",
@@ -298,7 +298,55 @@ var PlaywrightOpentelemetryReporter = class {
298
298
  });
299
299
  }
300
300
  }
301
- for (const destination of destinations.values()) await require_screenshots_zip.sendSpans(destination.spans, destination.options);
301
+ const sendFailures = (await Promise.all([...destinations.values()].map(async (destination) => {
302
+ try {
303
+ await require_screenshots_zip.sendSpans(destination.spans, destination.options);
304
+ return [];
305
+ } catch (error) {
306
+ return [{
307
+ destination,
308
+ error
309
+ }];
310
+ }
311
+ }))).flat();
312
+ for (const failure of sendFailures) console.warn(`Failed to send spans to ${failure.destination.options.tracesEndpoint}: ${errorMessage(failure.error)}`);
313
+ for (const artifact of this.pendingTraceArtifacts) {
314
+ const prepared = await artifact.prepared;
315
+ if ("error" in prepared) throw prepared.error;
316
+ if (prepared.traceZipBlob) await writeTraceZip(artifact.outputDir, artifact.test, prepared.traceZipBlob);
317
+ }
318
+ const traceApiFailure = sendFailures.find((failure) => failure.destination.kind === "trace-api");
319
+ if (traceApiFailure) throw traceApiFailure.error;
320
+ }
321
+ /**
322
+ * What the fixture handed over for this test attempt: its attachments with
323
+ * `attachFixtureData`, otherwise the files in the attempt's handoff
324
+ * directory, which is deleted here whether or not the test is reported.
325
+ */
326
+ takeFixtureData(test, result) {
327
+ const attachment = (name) => result.attachments.find((attachment) => attachment.name === name);
328
+ const screenshotsAttachmentPath = attachment(require_screenshots_zip.SCREENSHOTS_ATTACHMENT_NAME)?.path;
329
+ const attached = {
330
+ traceContext: attachment(require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME)?.body,
331
+ fixtureSpans: attachment(require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME)?.body,
332
+ screenshotsZip: screenshotsAttachmentPath ? readFixtureFile(screenshotsAttachmentPath, { required: true }) : void 0
333
+ };
334
+ const outputDir = getProjectOutputDir(test);
335
+ if (!outputDir) return attached;
336
+ this.fixtureHandoffRoots.add(require_screenshots_zip.fixtureHandoffRoot(outputDir));
337
+ const dir = require_screenshots_zip.fixtureHandoffDir(outputDir, test.id, result.retry);
338
+ try {
339
+ return {
340
+ traceContext: attached.traceContext ?? readFixtureFile(node_path.default.join(dir, "trace-context.json")),
341
+ fixtureSpans: attached.fixtureSpans ?? readFixtureFile(node_path.default.join(dir, "fixture-spans.json")),
342
+ screenshotsZip: attached.screenshotsZip ?? readFixtureFile(node_path.default.join(dir, "screenshots.zip"))
343
+ };
344
+ } finally {
345
+ node_fs.default.rmSync(dir, {
346
+ recursive: true,
347
+ force: true
348
+ });
349
+ }
302
350
  }
303
351
  async prepareTraceArtifact(options) {
304
352
  const screenshots = await readTestScreenshots(options);
@@ -387,16 +435,16 @@ var PlaywrightOpentelemetryReporter = class {
387
435
  };
388
436
  /**
389
437
  * A test's screenshots. Playwright versions with a usable screencast only use
390
- * the frames the fixture captured and attached; older versions only use
438
+ * the frames the fixture captured; older versions only use
391
439
  * Playwright's trace. Never rejects: a test's spans are still sent without
392
440
  * its screenshots.
393
441
  */
394
442
  async function readTestScreenshots(options) {
395
443
  if (!options.config.screenshots) return [];
396
444
  if (require_screenshots_zip.supportsScreencastScreenshots(options.playwrightVersion)) {
397
- if (!options.screenshotsAttachmentPath) return [];
445
+ if (!options.screenshotsZip) return [];
398
446
  try {
399
- return await require_screenshots_zip.readScreenshotsZip(new Blob([await node_fs_promises.default.readFile(options.screenshotsAttachmentPath)]));
447
+ return await require_screenshots_zip.readScreenshotsZip(new Blob([options.screenshotsZip]));
400
448
  } catch (error) {
401
449
  console.warn(`Failed to read the test's screenshots: ${error instanceof Error ? error.message : String(error)}`);
402
450
  return [];
@@ -411,12 +459,19 @@ function getProjectPlaywrightOpentelemetryConfig(project) {
411
459
  function getTestConfig(test) {
412
460
  return require_screenshots_zip.resolvePlaywrightOpentelemetryConfig(getProjectPlaywrightOpentelemetryConfig(test.parent.project()), { requireDestination: true });
413
461
  }
462
+ function getProjectOutputDir(test) {
463
+ return test.parent.project()?.outputDir;
464
+ }
414
465
  function getTestOutputDir(test) {
415
- const outputDir = test.parent.project()?.outputDir;
466
+ const outputDir = getProjectOutputDir(test);
416
467
  if (!outputDir) throw new Error(`No outputDir found for test "${test.id}"`);
417
468
  return outputDir;
418
469
  }
419
- function addDestinationSpans(destinations, spans, options) {
470
+ function errorMessage(error) {
471
+ if (error instanceof Error) return error.message;
472
+ return String(error);
473
+ }
474
+ function addDestinationSpans(destinations, spans, kind, options) {
420
475
  const key = JSON.stringify(options);
421
476
  const destination = destinations.get(key);
422
477
  if (destination) {
@@ -424,6 +479,7 @@ function addDestinationSpans(destinations, spans, options) {
424
479
  return;
425
480
  }
426
481
  destinations.set(key, {
482
+ kind,
427
483
  spans: [...spans],
428
484
  options
429
485
  });
@@ -434,31 +490,41 @@ function hasTraceApiDestination(config) {
434
490
  function hasPlaywrightOpentelemetryDestination(config) {
435
491
  return Boolean(config.storeTraceZip || config.otlpDestinations.some((destination) => destination.url) || config.playwrightTraceApiDestinations.some((destination) => destination.url));
436
492
  }
437
- function readTraceContextAttachment(result, testId) {
438
- const attachment = result.attachments.find((attachment) => attachment.name === require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME);
439
- if (!attachment?.body) return {
493
+ /**
494
+ * A file the fixture left, or undefined when it left none. Handoff files are
495
+ * optional; an attachment's file is not, so a missing one is reported.
496
+ */
497
+ function readFixtureFile(filePath, options = {}) {
498
+ try {
499
+ return node_fs.default.readFileSync(filePath);
500
+ } catch (error) {
501
+ if (options.required || error.code !== "ENOENT") console.warn(`Failed to read ${node_path.default.basename(filePath)} from the playwright-opentelemetry fixture: ${errorMessage(error)}`);
502
+ return;
503
+ }
504
+ }
505
+ function parseTraceContext(body, testId) {
506
+ if (!body) return {
440
507
  traceId: require_screenshots_zip.generateTraceId(),
441
508
  rootSpanId: require_screenshots_zip.generateSpanId()
442
509
  };
443
510
  let parsed;
444
511
  try {
445
- parsed = JSON.parse(attachment.body.toString("utf-8"));
512
+ parsed = JSON.parse(body.toString("utf-8"));
446
513
  } catch (error) {
447
- throw new Error(`Invalid ${require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME} attachment for test ${testId}: ${error}`);
514
+ throw new Error(`Invalid ${require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME} for test ${testId}: ${error}`);
448
515
  }
449
- if (!isTraceContextAttachment(parsed)) throw new Error(`Invalid ${require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME} attachment for test ${testId}: expected { traceId, rootSpanId }`);
516
+ if (!isTraceContextAttachment(parsed)) throw new Error(`Invalid ${require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME} for test ${testId}: expected { traceId, rootSpanId }`);
450
517
  return parsed;
451
518
  }
452
- function readFixtureSpansAttachment(result, testId) {
453
- const attachment = result.attachments.find((attachment) => attachment.name === require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME);
454
- if (!attachment?.body) return [];
519
+ function parseFixtureSpans(body, testId) {
520
+ if (!body) return [];
455
521
  let parsed;
456
522
  try {
457
- parsed = JSON.parse(attachment.body.toString("utf-8"));
523
+ parsed = JSON.parse(body.toString("utf-8"));
458
524
  } catch (error) {
459
- throw new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: ${error}`);
525
+ throw new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME} for test ${testId}: ${error}`);
460
526
  }
461
- if (!isRecord(parsed) || !Array.isArray(parsed.spans)) throw new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: expected { spans }`);
527
+ if (!isRecord(parsed) || !Array.isArray(parsed.spans)) throw new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME} for test ${testId}: expected { spans }`);
462
528
  return parsed.spans.map((span, index) => parseFixtureSpan(span, testId, index));
463
529
  }
464
530
  function parseFixtureSpan(value, testId, index) {
@@ -485,7 +551,7 @@ function parseFixtureSpan(value, testId, index) {
485
551
  };
486
552
  }
487
553
  function invalidFixtureSpanError(testId, index) {
488
- return /* @__PURE__ */ new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: invalid span at index ${index}`);
554
+ return /* @__PURE__ */ new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME} for test ${testId}: invalid span at index ${index}`);
489
555
  }
490
556
  function parseAttachmentDate(value) {
491
557
  if (typeof value !== "string") return;
@@ -28,6 +28,7 @@ type Span = {
28
28
  declare class PlaywrightOpentelemetryReporter implements Reporter {
29
29
  private spanBatches;
30
30
  private pendingTraceArtifacts;
31
+ private fixtureHandoffRoots;
31
32
  private rootDir?;
32
33
  private playwrightVersion?;
33
34
  private debug;
@@ -38,6 +39,12 @@ declare class PlaywrightOpentelemetryReporter implements Reporter {
38
39
  onStepEnd(_test: TestCase, _result: TestResult, _step: TestStep): void;
39
40
  onTestEnd(test: TestCase, result: TestResult): void;
40
41
  onEnd(_result: FullResult): Promise<void>;
42
+ /**
43
+ * What the fixture handed over for this test attempt: its attachments with
44
+ * `attachFixtureData`, otherwise the files in the attempt's handoff
45
+ * directory, which is deleted here whether or not the test is reported.
46
+ */
47
+ private takeFixtureData;
41
48
  private prepareTraceArtifact;
42
49
  private processTestStep;
43
50
  onStdOut(chunk: string | Buffer, _test: TestCase, _result: TestResult): void;
@@ -28,6 +28,7 @@ type Span = {
28
28
  declare class PlaywrightOpentelemetryReporter implements Reporter {
29
29
  private spanBatches;
30
30
  private pendingTraceArtifacts;
31
+ private fixtureHandoffRoots;
31
32
  private rootDir?;
32
33
  private playwrightVersion?;
33
34
  private debug;
@@ -38,6 +39,12 @@ declare class PlaywrightOpentelemetryReporter implements Reporter {
38
39
  onStepEnd(_test: TestCase, _result: TestResult, _step: TestStep): void;
39
40
  onTestEnd(test: TestCase, result: TestResult): void;
40
41
  onEnd(_result: FullResult): Promise<void>;
42
+ /**
43
+ * What the fixture handed over for this test attempt: its attachments with
44
+ * `attachFixtureData`, otherwise the files in the attempt's handoff
45
+ * directory, which is deleted here whether or not the test is reported.
46
+ */
47
+ private takeFixtureData;
41
48
  private prepareTraceArtifact;
42
49
  private processTestStep;
43
50
  onStdOut(chunk: string | Buffer, _test: TestCase, _result: TestResult): void;
package/dist/reporter.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/reporter/index.ts
2
- var reporter_default = require("./reporter-Dnqohjyo.cjs").PlaywrightOpentelemetryReporter;
2
+ var reporter_default = require("./reporter-C_sXaF-4.cjs").PlaywrightOpentelemetryReporter;
3
3
  //#endregion
4
4
  module.exports = reporter_default;
@@ -1,2 +1,2 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-CLzdtg6G.cjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-DtVv7zcl.cjs";
2
2
  export = PlaywrightOpentelemetryReporter;
@@ -1,2 +1,2 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-CLzdtg6G.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-DtVv7zcl.mjs";
2
2
  export { PlaywrightOpentelemetryReporter as default };
package/dist/reporter.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-CMGLSTHi.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-B7K2L2XR.mjs";
2
2
  //#region src/reporter/index.ts
3
3
  var reporter_default = PlaywrightOpentelemetryReporter;
4
4
  //#endregion
@@ -20,9 +20,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
20
20
  enumerable: true
21
21
  }) : target, mod));
22
22
  //#endregion
23
+ let node_fs_promises = require("node:fs/promises");
24
+ node_fs_promises = __toESM(node_fs_promises, 1);
25
+ let node_path = require("node:path");
26
+ node_path = __toESM(node_path, 1);
23
27
  let _zip_js_zip_js = require("@zip.js/zip.js");
24
28
  //#region package.json
25
- var version = "0.15.0";
29
+ var version = "0.17.0";
26
30
  const PLAYWRIGHT_TRACE_API_SOURCE_HEADER = "x-playwright-otel-source";
27
31
  const PLAYWRIGHT_TRACE_API_SOURCE_REPORTER = "reporter";
28
32
  function withPlaywrightTraceApiHeaders(headers) {
@@ -173,6 +177,33 @@ function filterRetainedDestinations(destinations, configTrace, shouldRetainTrace
173
177
  return destinations.filter((destination) => destination.url && shouldRetainTrace(destination.trace ?? configTrace));
174
178
  }
175
179
  //#endregion
180
+ //#region src/shared/fixture-handoff.ts
181
+ /**
182
+ * Unless `attachFixtureData` is on, the fixture hands its data to the reporter
183
+ * as files rather than test attachments, which Playwright would copy into its
184
+ * own trace and HTML report. Both sides find a test attempt's files from its
185
+ * ID and retry: the ID is already unique per project, file, title and
186
+ * repeat-each index.
187
+ */
188
+ function fixtureHandoffDir(projectOutputDir, testId, retry) {
189
+ return node_path.default.join(fixtureHandoffRoot(projectOutputDir), `${testId}-${retry}`);
190
+ }
191
+ /**
192
+ * In the project's output directory, which Playwright clears at the start of a
193
+ * run, not the test's, which Playwright can remove before the reporter reads it.
194
+ */
195
+ function fixtureHandoffRoot(projectOutputDir) {
196
+ return node_path.default.join(projectOutputDir, ".playwright-opentelemetry");
197
+ }
198
+ const TRACE_CONTEXT_HANDOFF_FILE = "trace-context.json";
199
+ const FIXTURE_SPANS_HANDOFF_FILE = "fixture-spans.json";
200
+ const SCREENSHOTS_HANDOFF_FILE = "screenshots.zip";
201
+ async function writeFixtureHandoffFile(testInfo, fileName, data) {
202
+ const dir = fixtureHandoffDir(testInfo.project.outputDir, testInfo.testId, testInfo.retry);
203
+ await node_fs_promises.default.mkdir(dir, { recursive: true });
204
+ await node_fs_promises.default.writeFile(node_path.default.join(dir, fileName), data);
205
+ }
206
+ //#endregion
176
207
  //#region src/shared/playwright-trace.ts
177
208
  function shouldRetainPlaywrightTrace(trace, testInfo) {
178
209
  const mode = normalizeTraceMode(trace);
@@ -208,7 +239,7 @@ const FIXTURE_SPANS_ATTACHMENT_NAME = "playwright-opentelemetry-fixture-spans";
208
239
  const BROWSER_SERVICE_NAME = "playwright-browser";
209
240
  const FIXTURE_EXPORT_RETRY_DELAYS_MS = [250, 750];
210
241
  const FIXTURE_EXPORT_REQUEST_TIMEOUT_MS = 3e3;
211
- async function createTestTraceContext(testInfo) {
242
+ async function createTestTraceContext(testInfo, config) {
212
243
  const traceContext = {
213
244
  traceId: generateTraceId(),
214
245
  rootSpanId: generateSpanId(),
@@ -218,13 +249,15 @@ async function createTestTraceContext(testInfo) {
218
249
  this.spans.push(span);
219
250
  }
220
251
  };
221
- await testInfo.attach(TRACE_CONTEXT_ATTACHMENT_NAME, {
222
- body: JSON.stringify({
223
- traceId: traceContext.traceId,
224
- rootSpanId: traceContext.rootSpanId
225
- }),
252
+ const body = JSON.stringify({
253
+ traceId: traceContext.traceId,
254
+ rootSpanId: traceContext.rootSpanId
255
+ });
256
+ if (config.attachFixtureData) await testInfo.attach(TRACE_CONTEXT_ATTACHMENT_NAME, {
257
+ body,
226
258
  contentType: "application/json"
227
259
  });
260
+ else await writeFixtureHandoffFile(testInfo, TRACE_CONTEXT_HANDOFF_FILE, body);
228
261
  return traceContext;
229
262
  }
230
263
  /**
@@ -261,10 +294,14 @@ async function registerExpectedTrace(traceContext, config, options) {
261
294
  async function flushFixtureSpans(traceContext, config, options) {
262
295
  if (traceContext.spans.length === 0) return;
263
296
  const shouldRetainTrace = (trace) => shouldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo);
264
- if (config.storeTraceZip && options.testInfo && shouldRetainTrace(config.trace)) await options.testInfo.attach(FIXTURE_SPANS_ATTACHMENT_NAME, {
265
- body: JSON.stringify({ spans: traceContext.spans.map(serializeSpanForAttachment) }),
266
- contentType: "application/json"
267
- });
297
+ if (config.storeTraceZip && options.testInfo && shouldRetainTrace(config.trace)) {
298
+ const body = JSON.stringify({ spans: traceContext.spans.map(serializeSpanForAttachment) });
299
+ if (config.attachFixtureData) await options.testInfo.attach(FIXTURE_SPANS_ATTACHMENT_NAME, {
300
+ body,
301
+ contentType: "application/json"
302
+ });
303
+ else await writeFixtureHandoffFile(options.testInfo, FIXTURE_SPANS_HANDOFF_FILE, body);
304
+ }
268
305
  const destinations = fixtureSpanDestinations(config, shouldRetainTrace);
269
306
  if (destinations.length === 0) return;
270
307
  const failures = await Promise.all(destinations.map(async (destination) => {
@@ -326,6 +363,7 @@ function resolvePlaywrightOpentelemetryConfig(config, options = {}) {
326
363
  storeTraceZip: config?.storeTraceZip === true,
327
364
  trace: config?.trace ?? null,
328
365
  screenshots: config?.screenshots ?? true,
366
+ attachFixtureData: config?.attachFixtureData === true,
329
367
  propagateTraceHeaders: config?.propagateTraceHeaders ?? true,
330
368
  debug: debugEnv === void 0 ? config?.debug ?? false : debugEnv === "1" || debugEnv === "true"
331
369
  };
@@ -477,6 +515,12 @@ Object.defineProperty(exports, "FIXTURE_SPANS_ATTACHMENT_NAME", {
477
515
  return FIXTURE_SPANS_ATTACHMENT_NAME;
478
516
  }
479
517
  });
518
+ Object.defineProperty(exports, "FIXTURE_SPANS_HANDOFF_FILE", {
519
+ enumerable: true,
520
+ get: function() {
521
+ return FIXTURE_SPANS_HANDOFF_FILE;
522
+ }
523
+ });
480
524
  Object.defineProperty(exports, "PLAYWRIGHT_TRACE_API_SOURCE_HEADER", {
481
525
  enumerable: true,
482
526
  get: function() {
@@ -495,12 +539,24 @@ Object.defineProperty(exports, "SCREENSHOTS_ATTACHMENT_NAME", {
495
539
  return SCREENSHOTS_ATTACHMENT_NAME;
496
540
  }
497
541
  });
542
+ Object.defineProperty(exports, "SCREENSHOTS_HANDOFF_FILE", {
543
+ enumerable: true,
544
+ get: function() {
545
+ return SCREENSHOTS_HANDOFF_FILE;
546
+ }
547
+ });
498
548
  Object.defineProperty(exports, "TRACE_CONTEXT_ATTACHMENT_NAME", {
499
549
  enumerable: true,
500
550
  get: function() {
501
551
  return TRACE_CONTEXT_ATTACHMENT_NAME;
502
552
  }
503
553
  });
554
+ Object.defineProperty(exports, "TRACE_CONTEXT_HANDOFF_FILE", {
555
+ enumerable: true,
556
+ get: function() {
557
+ return TRACE_CONTEXT_HANDOFF_FILE;
558
+ }
559
+ });
504
560
  Object.defineProperty(exports, "__toESM", {
505
561
  enumerable: true,
506
562
  get: function() {
@@ -543,6 +599,18 @@ Object.defineProperty(exports, "filterRetainedDestinations", {
543
599
  return filterRetainedDestinations;
544
600
  }
545
601
  });
602
+ Object.defineProperty(exports, "fixtureHandoffDir", {
603
+ enumerable: true,
604
+ get: function() {
605
+ return fixtureHandoffDir;
606
+ }
607
+ });
608
+ Object.defineProperty(exports, "fixtureHandoffRoot", {
609
+ enumerable: true,
610
+ get: function() {
611
+ return fixtureHandoffRoot;
612
+ }
613
+ });
546
614
  Object.defineProperty(exports, "flushFixtureSpans", {
547
615
  enumerable: true,
548
616
  get: function() {
@@ -603,3 +671,9 @@ Object.defineProperty(exports, "withPlaywrightTraceApiHeaders", {
603
671
  return withPlaywrightTraceApiHeaders;
604
672
  }
605
673
  });
674
+ Object.defineProperty(exports, "writeFixtureHandoffFile", {
675
+ enumerable: true,
676
+ get: function() {
677
+ return writeFixtureHandoffFile;
678
+ }
679
+ });
@@ -1,6 +1,8 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
1
3
  import { BlobReader, BlobWriter, TextWriter, ZipReader, ZipWriter } from "@zip.js/zip.js";
2
4
  //#region package.json
3
- var version = "0.15.0";
5
+ var version = "0.17.0";
4
6
  const PLAYWRIGHT_TRACE_API_SOURCE_HEADER = "x-playwright-otel-source";
5
7
  const PLAYWRIGHT_TRACE_API_SOURCE_REPORTER = "reporter";
6
8
  function withPlaywrightTraceApiHeaders(headers) {
@@ -151,6 +153,33 @@ function filterRetainedDestinations(destinations, configTrace, shouldRetainTrace
151
153
  return destinations.filter((destination) => destination.url && shouldRetainTrace(destination.trace ?? configTrace));
152
154
  }
153
155
  //#endregion
156
+ //#region src/shared/fixture-handoff.ts
157
+ /**
158
+ * Unless `attachFixtureData` is on, the fixture hands its data to the reporter
159
+ * as files rather than test attachments, which Playwright would copy into its
160
+ * own trace and HTML report. Both sides find a test attempt's files from its
161
+ * ID and retry: the ID is already unique per project, file, title and
162
+ * repeat-each index.
163
+ */
164
+ function fixtureHandoffDir(projectOutputDir, testId, retry) {
165
+ return path.join(fixtureHandoffRoot(projectOutputDir), `${testId}-${retry}`);
166
+ }
167
+ /**
168
+ * In the project's output directory, which Playwright clears at the start of a
169
+ * run, not the test's, which Playwright can remove before the reporter reads it.
170
+ */
171
+ function fixtureHandoffRoot(projectOutputDir) {
172
+ return path.join(projectOutputDir, ".playwright-opentelemetry");
173
+ }
174
+ const TRACE_CONTEXT_HANDOFF_FILE = "trace-context.json";
175
+ const FIXTURE_SPANS_HANDOFF_FILE = "fixture-spans.json";
176
+ const SCREENSHOTS_HANDOFF_FILE = "screenshots.zip";
177
+ async function writeFixtureHandoffFile(testInfo, fileName, data) {
178
+ const dir = fixtureHandoffDir(testInfo.project.outputDir, testInfo.testId, testInfo.retry);
179
+ await fs.mkdir(dir, { recursive: true });
180
+ await fs.writeFile(path.join(dir, fileName), data);
181
+ }
182
+ //#endregion
154
183
  //#region src/shared/playwright-trace.ts
155
184
  function shouldRetainPlaywrightTrace(trace, testInfo) {
156
185
  const mode = normalizeTraceMode(trace);
@@ -186,7 +215,7 @@ const FIXTURE_SPANS_ATTACHMENT_NAME = "playwright-opentelemetry-fixture-spans";
186
215
  const BROWSER_SERVICE_NAME = "playwright-browser";
187
216
  const FIXTURE_EXPORT_RETRY_DELAYS_MS = [250, 750];
188
217
  const FIXTURE_EXPORT_REQUEST_TIMEOUT_MS = 3e3;
189
- async function createTestTraceContext(testInfo) {
218
+ async function createTestTraceContext(testInfo, config) {
190
219
  const traceContext = {
191
220
  traceId: generateTraceId(),
192
221
  rootSpanId: generateSpanId(),
@@ -196,13 +225,15 @@ async function createTestTraceContext(testInfo) {
196
225
  this.spans.push(span);
197
226
  }
198
227
  };
199
- await testInfo.attach(TRACE_CONTEXT_ATTACHMENT_NAME, {
200
- body: JSON.stringify({
201
- traceId: traceContext.traceId,
202
- rootSpanId: traceContext.rootSpanId
203
- }),
228
+ const body = JSON.stringify({
229
+ traceId: traceContext.traceId,
230
+ rootSpanId: traceContext.rootSpanId
231
+ });
232
+ if (config.attachFixtureData) await testInfo.attach(TRACE_CONTEXT_ATTACHMENT_NAME, {
233
+ body,
204
234
  contentType: "application/json"
205
235
  });
236
+ else await writeFixtureHandoffFile(testInfo, TRACE_CONTEXT_HANDOFF_FILE, body);
206
237
  return traceContext;
207
238
  }
208
239
  /**
@@ -239,10 +270,14 @@ async function registerExpectedTrace(traceContext, config, options) {
239
270
  async function flushFixtureSpans(traceContext, config, options) {
240
271
  if (traceContext.spans.length === 0) return;
241
272
  const shouldRetainTrace = (trace) => shouldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo);
242
- if (config.storeTraceZip && options.testInfo && shouldRetainTrace(config.trace)) await options.testInfo.attach(FIXTURE_SPANS_ATTACHMENT_NAME, {
243
- body: JSON.stringify({ spans: traceContext.spans.map(serializeSpanForAttachment) }),
244
- contentType: "application/json"
245
- });
273
+ if (config.storeTraceZip && options.testInfo && shouldRetainTrace(config.trace)) {
274
+ const body = JSON.stringify({ spans: traceContext.spans.map(serializeSpanForAttachment) });
275
+ if (config.attachFixtureData) await options.testInfo.attach(FIXTURE_SPANS_ATTACHMENT_NAME, {
276
+ body,
277
+ contentType: "application/json"
278
+ });
279
+ else await writeFixtureHandoffFile(options.testInfo, FIXTURE_SPANS_HANDOFF_FILE, body);
280
+ }
246
281
  const destinations = fixtureSpanDestinations(config, shouldRetainTrace);
247
282
  if (destinations.length === 0) return;
248
283
  const failures = await Promise.all(destinations.map(async (destination) => {
@@ -304,6 +339,7 @@ function resolvePlaywrightOpentelemetryConfig(config, options = {}) {
304
339
  storeTraceZip: config?.storeTraceZip === true,
305
340
  trace: config?.trace ?? null,
306
341
  screenshots: config?.screenshots ?? true,
342
+ attachFixtureData: config?.attachFixtureData === true,
307
343
  propagateTraceHeaders: config?.propagateTraceHeaders ?? true,
308
344
  debug: debugEnv === void 0 ? config?.debug ?? false : debugEnv === "1" || debugEnv === "true"
309
345
  };
@@ -443,4 +479,4 @@ function viewportOf(screenshot) {
443
479
  } : {};
444
480
  }
445
481
  //#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 };
482
+ export { PLAYWRIGHT_TRACE_API_SOURCE_REPORTER as C, sendSpans as D, generateTraceId as E, withPlaywrightTraceApiHeaders as O, PLAYWRIGHT_TRACE_API_SOURCE_HEADER as S, generateSpanId as T, TRACE_CONTEXT_HANDOFF_FILE as _, supportsScreencastScreenshots as a, writeFixtureHandoffFile as b, FIXTURE_SPANS_ATTACHMENT_NAME as c, flushFixtureSpans as d, registerExpectedTrace as f, SCREENSHOTS_HANDOFF_FILE as g, FIXTURE_SPANS_HANDOFF_FILE 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, fixtureHandoffDir as v, buildOtlpRequest as w, filterRetainedDestinations as x, fixtureHandoffRoot as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright-opentelemetry",
3
- "version": "0.15.0",
3
+ "version": "0.17.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",