playwright-opentelemetry 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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-CNPpbJfR.cjs");
2
+ const require_screenshots_zip = require("./screenshots-zip-Cy2Wivw7.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");
package/dist/fixture.mjs CHANGED
@@ -1,4 +1,4 @@
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-CLFTP3sv.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-CU1X4mzh.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";
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/index.ts
2
- var src_default = require("./reporter-p3Z6GrF-.cjs").PlaywrightOpentelemetryReporter;
2
+ var src_default = require("./reporter-BuViICz8.cjs").PlaywrightOpentelemetryReporter;
3
3
  //#endregion
4
4
  module.exports = src_default;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-t-dJHyfd.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-_CyyuDJs.mjs";
2
2
  //#region src/index.ts
3
3
  var src_default = PlaywrightOpentelemetryReporter;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- const require_screenshots_zip = require("./screenshots-zip-CNPpbJfR.cjs");
1
+ const require_screenshots_zip = require("./screenshots-zip-Cy2Wivw7.cjs");
2
2
  let node_fs = require("node:fs");
3
3
  node_fs = require_screenshots_zip.__toESM(node_fs, 1);
4
4
  let node_fs_promises = require("node:fs/promises");
@@ -1,4 +1,4 @@
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-CLFTP3sv.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-CU1X4mzh.mjs";
2
2
  import fsSync from "node:fs";
3
3
  import fs from "node:fs/promises";
4
4
  import path from "node:path";
package/dist/reporter.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/reporter/index.ts
2
- var reporter_default = require("./reporter-p3Z6GrF-.cjs").PlaywrightOpentelemetryReporter;
2
+ var reporter_default = require("./reporter-BuViICz8.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-t-dJHyfd.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-_CyyuDJs.mjs";
2
2
  //#region src/reporter/index.ts
3
3
  var reporter_default = PlaywrightOpentelemetryReporter;
4
4
  //#endregion
@@ -2,7 +2,7 @@ import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  import { BlobReader, BlobWriter, TextWriter, ZipReader, ZipWriter } from "@zip.js/zip.js";
4
4
  //#region package.json
5
- var version = "0.18.0";
5
+ var version = "0.18.1";
6
6
  const PLAYWRIGHT_TRACE_API_SOURCE_HEADER = "x-playwright-otel-source";
7
7
  const PLAYWRIGHT_TRACE_API_SOURCE_REPORTER = "reporter";
8
8
  function withPlaywrightTraceApiHeaders(headers) {
@@ -160,6 +160,11 @@ function filterRetainedDestinations(destinations, configTrace, shouldRetainTrace
160
160
  * own trace and HTML report. Both sides find a test attempt's files from its
161
161
  * ID and retry: the ID is already unique per project, file, title and
162
162
  * repeat-each index.
163
+ *
164
+ * Not documented, but Endform relies on it: its worker controller seeds
165
+ * {@link TRACE_CONTEXT_HANDOFF_FILE} here before dispatching an attempt, so
166
+ * it knows the attempt's trace ID even though it runs the reporter in another
167
+ * process. Keep the layout and format stable.
163
168
  */
164
169
  function fixtureHandoffDir(projectOutputDir, testId, retry) {
165
170
  return path.join(fixtureHandoffRoot(projectOutputDir), `${testId}-${retry}`);
@@ -174,11 +179,43 @@ function fixtureHandoffRoot(projectOutputDir) {
174
179
  const TRACE_CONTEXT_HANDOFF_FILE = "trace-context.json";
175
180
  const FIXTURE_SPANS_HANDOFF_FILE = "fixture-spans.json";
176
181
  const SCREENSHOTS_HANDOFF_FILE = "screenshots.zip";
182
+ const TRACE_ID_PATTERN = /^[0-9a-f]{32}$/i;
183
+ const SPAN_ID_PATTERN = /^[0-9a-f]{16}$/i;
184
+ function isTraceContextHandoff(value) {
185
+ return typeof value === "object" && value !== null && "traceId" in value && "rootSpanId" in value && typeof value.traceId === "string" && typeof value.rootSpanId === "string" && TRACE_ID_PATTERN.test(value.traceId) && SPAN_ID_PATTERN.test(value.rootSpanId);
186
+ }
177
187
  async function writeFixtureHandoffFile(testInfo, fileName, data) {
178
- const dir = fixtureHandoffDir(testInfo.project.outputDir, testInfo.testId, testInfo.retry);
188
+ const dir = testHandoffDir(testInfo);
179
189
  await fs.mkdir(dir, { recursive: true });
180
190
  await fs.writeFile(path.join(dir, fileName), data);
181
191
  }
192
+ /**
193
+ * The trace context a host seeded for this test attempt before its fixtures
194
+ * ran, so the attempt uses the trace ID the host chose. `undefined` when there
195
+ * is no seeded file; `"invalid"` when there is one the fixture can't use.
196
+ */
197
+ async function readSeededTraceContext(testInfo) {
198
+ const filePath = path.join(testHandoffDir(testInfo), TRACE_CONTEXT_HANDOFF_FILE);
199
+ let body;
200
+ try {
201
+ body = await fs.readFile(filePath, "utf-8");
202
+ } catch (error) {
203
+ if (error.code === "ENOENT") return;
204
+ return "invalid";
205
+ }
206
+ try {
207
+ const parsed = JSON.parse(body);
208
+ return isTraceContextHandoff(parsed) ? {
209
+ traceId: parsed.traceId,
210
+ rootSpanId: parsed.rootSpanId
211
+ } : "invalid";
212
+ } catch {
213
+ return "invalid";
214
+ }
215
+ }
216
+ function testHandoffDir(testInfo) {
217
+ return fixtureHandoffDir(testInfo.project.outputDir, testInfo.testId, testInfo.retry);
218
+ }
182
219
  //#endregion
183
220
  //#region src/shared/playwright-trace.ts
184
221
  function shouldRetainPlaywrightTrace(trace, testInfo) {
@@ -215,25 +252,34 @@ const FIXTURE_SPANS_ATTACHMENT_NAME = "playwright-opentelemetry-fixture-spans";
215
252
  const BROWSER_SERVICE_NAME = "playwright-browser";
216
253
  const FIXTURE_EXPORT_RETRY_DELAYS_MS = [250, 750];
217
254
  const FIXTURE_EXPORT_REQUEST_TIMEOUT_MS = 3e3;
255
+ /**
256
+ * Uses the trace context a host seeded in the attempt's handoff directory, if
257
+ * there is a valid one, so a host that runs the reporter in another process
258
+ * knows the attempt's trace ID up front. Otherwise creates new IDs and hands
259
+ * them to the reporter.
260
+ */
218
261
  async function createTestTraceContext(testInfo, config) {
219
- const traceContext = {
262
+ const seeded = await readSeededTraceContext(testInfo);
263
+ if (seeded === "invalid") console.warn(`Ignoring invalid ${TRACE_CONTEXT_HANDOFF_FILE} for test ${testInfo.testId} (retry ${testInfo.retry}): expected {"traceId": <32 hex>, "rootSpanId": <16 hex>}. Replacing it with new IDs.`);
264
+ const seededIds = seeded === "invalid" ? void 0 : seeded;
265
+ const ids = seededIds ?? {
220
266
  traceId: generateTraceId(),
221
- rootSpanId: generateSpanId(),
267
+ rootSpanId: generateSpanId()
268
+ };
269
+ const traceContext = {
270
+ ...ids,
222
271
  spans: [],
223
272
  requestContexts: /* @__PURE__ */ new WeakMap(),
224
273
  addSpan(span) {
225
274
  this.spans.push(span);
226
275
  }
227
276
  };
228
- const body = JSON.stringify({
229
- traceId: traceContext.traceId,
230
- rootSpanId: traceContext.rootSpanId
231
- });
277
+ const body = JSON.stringify(ids);
232
278
  if (config.attachFixtureData) await testInfo.attach(TRACE_CONTEXT_ATTACHMENT_NAME, {
233
279
  body,
234
280
  contentType: "application/json"
235
281
  });
236
- else await writeFixtureHandoffFile(testInfo, TRACE_CONTEXT_HANDOFF_FILE, body);
282
+ else if (!seededIds) await writeFixtureHandoffFile(testInfo, TRACE_CONTEXT_HANDOFF_FILE, body);
237
283
  return traceContext;
238
284
  }
239
285
  /**
@@ -26,7 +26,7 @@ let node_path = require("node:path");
26
26
  node_path = __toESM(node_path, 1);
27
27
  let _zip_js_zip_js = require("@zip.js/zip.js");
28
28
  //#region package.json
29
- var version = "0.18.0";
29
+ var version = "0.18.1";
30
30
  const PLAYWRIGHT_TRACE_API_SOURCE_HEADER = "x-playwright-otel-source";
31
31
  const PLAYWRIGHT_TRACE_API_SOURCE_REPORTER = "reporter";
32
32
  function withPlaywrightTraceApiHeaders(headers) {
@@ -184,6 +184,11 @@ function filterRetainedDestinations(destinations, configTrace, shouldRetainTrace
184
184
  * own trace and HTML report. Both sides find a test attempt's files from its
185
185
  * ID and retry: the ID is already unique per project, file, title and
186
186
  * repeat-each index.
187
+ *
188
+ * Not documented, but Endform relies on it: its worker controller seeds
189
+ * {@link TRACE_CONTEXT_HANDOFF_FILE} here before dispatching an attempt, so
190
+ * it knows the attempt's trace ID even though it runs the reporter in another
191
+ * process. Keep the layout and format stable.
187
192
  */
188
193
  function fixtureHandoffDir(projectOutputDir, testId, retry) {
189
194
  return node_path.default.join(fixtureHandoffRoot(projectOutputDir), `${testId}-${retry}`);
@@ -198,11 +203,43 @@ function fixtureHandoffRoot(projectOutputDir) {
198
203
  const TRACE_CONTEXT_HANDOFF_FILE = "trace-context.json";
199
204
  const FIXTURE_SPANS_HANDOFF_FILE = "fixture-spans.json";
200
205
  const SCREENSHOTS_HANDOFF_FILE = "screenshots.zip";
206
+ const TRACE_ID_PATTERN = /^[0-9a-f]{32}$/i;
207
+ const SPAN_ID_PATTERN = /^[0-9a-f]{16}$/i;
208
+ function isTraceContextHandoff(value) {
209
+ return typeof value === "object" && value !== null && "traceId" in value && "rootSpanId" in value && typeof value.traceId === "string" && typeof value.rootSpanId === "string" && TRACE_ID_PATTERN.test(value.traceId) && SPAN_ID_PATTERN.test(value.rootSpanId);
210
+ }
201
211
  async function writeFixtureHandoffFile(testInfo, fileName, data) {
202
- const dir = fixtureHandoffDir(testInfo.project.outputDir, testInfo.testId, testInfo.retry);
212
+ const dir = testHandoffDir(testInfo);
203
213
  await node_fs_promises.default.mkdir(dir, { recursive: true });
204
214
  await node_fs_promises.default.writeFile(node_path.default.join(dir, fileName), data);
205
215
  }
216
+ /**
217
+ * The trace context a host seeded for this test attempt before its fixtures
218
+ * ran, so the attempt uses the trace ID the host chose. `undefined` when there
219
+ * is no seeded file; `"invalid"` when there is one the fixture can't use.
220
+ */
221
+ async function readSeededTraceContext(testInfo) {
222
+ const filePath = node_path.default.join(testHandoffDir(testInfo), TRACE_CONTEXT_HANDOFF_FILE);
223
+ let body;
224
+ try {
225
+ body = await node_fs_promises.default.readFile(filePath, "utf-8");
226
+ } catch (error) {
227
+ if (error.code === "ENOENT") return;
228
+ return "invalid";
229
+ }
230
+ try {
231
+ const parsed = JSON.parse(body);
232
+ return isTraceContextHandoff(parsed) ? {
233
+ traceId: parsed.traceId,
234
+ rootSpanId: parsed.rootSpanId
235
+ } : "invalid";
236
+ } catch {
237
+ return "invalid";
238
+ }
239
+ }
240
+ function testHandoffDir(testInfo) {
241
+ return fixtureHandoffDir(testInfo.project.outputDir, testInfo.testId, testInfo.retry);
242
+ }
206
243
  //#endregion
207
244
  //#region src/shared/playwright-trace.ts
208
245
  function shouldRetainPlaywrightTrace(trace, testInfo) {
@@ -239,25 +276,34 @@ const FIXTURE_SPANS_ATTACHMENT_NAME = "playwright-opentelemetry-fixture-spans";
239
276
  const BROWSER_SERVICE_NAME = "playwright-browser";
240
277
  const FIXTURE_EXPORT_RETRY_DELAYS_MS = [250, 750];
241
278
  const FIXTURE_EXPORT_REQUEST_TIMEOUT_MS = 3e3;
279
+ /**
280
+ * Uses the trace context a host seeded in the attempt's handoff directory, if
281
+ * there is a valid one, so a host that runs the reporter in another process
282
+ * knows the attempt's trace ID up front. Otherwise creates new IDs and hands
283
+ * them to the reporter.
284
+ */
242
285
  async function createTestTraceContext(testInfo, config) {
243
- const traceContext = {
286
+ const seeded = await readSeededTraceContext(testInfo);
287
+ if (seeded === "invalid") console.warn(`Ignoring invalid ${TRACE_CONTEXT_HANDOFF_FILE} for test ${testInfo.testId} (retry ${testInfo.retry}): expected {"traceId": <32 hex>, "rootSpanId": <16 hex>}. Replacing it with new IDs.`);
288
+ const seededIds = seeded === "invalid" ? void 0 : seeded;
289
+ const ids = seededIds ?? {
244
290
  traceId: generateTraceId(),
245
- rootSpanId: generateSpanId(),
291
+ rootSpanId: generateSpanId()
292
+ };
293
+ const traceContext = {
294
+ ...ids,
246
295
  spans: [],
247
296
  requestContexts: /* @__PURE__ */ new WeakMap(),
248
297
  addSpan(span) {
249
298
  this.spans.push(span);
250
299
  }
251
300
  };
252
- const body = JSON.stringify({
253
- traceId: traceContext.traceId,
254
- rootSpanId: traceContext.rootSpanId
255
- });
301
+ const body = JSON.stringify(ids);
256
302
  if (config.attachFixtureData) await testInfo.attach(TRACE_CONTEXT_ATTACHMENT_NAME, {
257
303
  body,
258
304
  contentType: "application/json"
259
305
  });
260
- else await writeFixtureHandoffFile(testInfo, TRACE_CONTEXT_HANDOFF_FILE, body);
306
+ else if (!seededIds) await writeFixtureHandoffFile(testInfo, TRACE_CONTEXT_HANDOFF_FILE, body);
261
307
  return traceContext;
262
308
  }
263
309
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright-opentelemetry",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
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",