playwright-opentelemetry 0.17.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 +1 -1
- package/dist/fixture.d.cts +2 -2
- package/dist/fixture.d.mts +2 -2
- package/dist/fixture.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/otel-D0ztpic2.d.cts +25 -0
- package/dist/otel-D0ztpic2.d.mts +25 -0
- package/dist/{reporter-C_sXaF-4.cjs → reporter-BuViICz8.cjs} +1 -1
- package/dist/{reporter-DtVv7zcl.d.cts → reporter-C1TwRMjP.d.cts} +1 -25
- package/dist/{reporter-DtVv7zcl.d.mts → reporter-C1TwRMjP.d.mts} +1 -25
- package/dist/{reporter-B7K2L2XR.mjs → reporter-_CyyuDJs.mjs} +1 -1
- package/dist/reporter.cjs +1 -1
- package/dist/reporter.d.cts +1 -1
- package/dist/reporter.d.mts +1 -1
- package/dist/reporter.mjs +1 -1
- package/dist/{screenshots-zip-D8_7p-Wx.mjs → screenshots-zip-CU1X4mzh.mjs} +55 -9
- package/dist/{screenshots-zip-CDmixuxY.cjs → screenshots-zip-Cy2Wivw7.cjs} +55 -9
- package/package.json +1 -1
- /package/dist/{index-g9K4ZUC_.d.cts → config-g9K4ZUC_.d.cts} +0 -0
- /package/dist/{index-g9K4ZUC_.d.mts → config-g9K4ZUC_.d.mts} +0 -0
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-
|
|
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.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import {
|
|
1
|
+
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-g9K4ZUC_.cjs";
|
|
2
|
+
import { n as SpanEvent, t as Span } from "./otel-D0ztpic2.cjs";
|
|
3
3
|
import { BrowserContext, ConsoleMessage, Page, Request } from "@playwright/test";
|
|
4
4
|
export * from "@playwright/test";
|
|
5
5
|
|
package/dist/fixture.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import {
|
|
1
|
+
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-g9K4ZUC_.mjs";
|
|
2
|
+
import { n as SpanEvent, t as Span } from "./otel-D0ztpic2.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 { 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-
|
|
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
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
1
|
+
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-g9K4ZUC_.cjs";
|
|
2
|
+
import { t as PlaywrightOpentelemetryReporter } from "./reporter-C1TwRMjP.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
|
|
2
|
-
import {
|
|
1
|
+
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-g9K4ZUC_.mjs";
|
|
2
|
+
import { t as PlaywrightOpentelemetryReporter } from "./reporter-C1TwRMjP.mjs";
|
|
3
3
|
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryDestination, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, PlaywrightOpentelemetryReporter as default };
|
package/dist/index.mjs
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/shared/otel.d.ts
|
|
2
|
+
type SpanAttributeValue = string | number | boolean | string[];
|
|
3
|
+
type SpanEvent = {
|
|
4
|
+
name: string;
|
|
5
|
+
time: Date;
|
|
6
|
+
attributes?: Record<string, SpanAttributeValue>;
|
|
7
|
+
};
|
|
8
|
+
type Span = {
|
|
9
|
+
traceId: string;
|
|
10
|
+
spanId: string;
|
|
11
|
+
parentSpanId?: string;
|
|
12
|
+
name: string;
|
|
13
|
+
startTime: Date;
|
|
14
|
+
endTime: Date;
|
|
15
|
+
attributes: Record<string, SpanAttributeValue>;
|
|
16
|
+
events?: SpanEvent[];
|
|
17
|
+
status?: {
|
|
18
|
+
code: number;
|
|
19
|
+
message?: string;
|
|
20
|
+
};
|
|
21
|
+
kind?: number; /** Service name for this span (if different from default). */
|
|
22
|
+
serviceName?: string;
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { SpanEvent as n, Span as t };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/shared/otel.d.ts
|
|
2
|
+
type SpanAttributeValue = string | number | boolean | string[];
|
|
3
|
+
type SpanEvent = {
|
|
4
|
+
name: string;
|
|
5
|
+
time: Date;
|
|
6
|
+
attributes?: Record<string, SpanAttributeValue>;
|
|
7
|
+
};
|
|
8
|
+
type Span = {
|
|
9
|
+
traceId: string;
|
|
10
|
+
spanId: string;
|
|
11
|
+
parentSpanId?: string;
|
|
12
|
+
name: string;
|
|
13
|
+
startTime: Date;
|
|
14
|
+
endTime: Date;
|
|
15
|
+
attributes: Record<string, SpanAttributeValue>;
|
|
16
|
+
events?: SpanEvent[];
|
|
17
|
+
status?: {
|
|
18
|
+
code: number;
|
|
19
|
+
message?: string;
|
|
20
|
+
};
|
|
21
|
+
kind?: number; /** Service name for this span (if different from default). */
|
|
22
|
+
serviceName?: string;
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { SpanEvent as n, Span as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_screenshots_zip = require("./screenshots-zip-
|
|
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,29 +1,5 @@
|
|
|
1
1
|
import { FullConfig, FullResult, Reporter, Suite, TestCase, TestResult, TestStep } from "@playwright/test/reporter";
|
|
2
2
|
|
|
3
|
-
//#region src/shared/otel.d.ts
|
|
4
|
-
type SpanAttributeValue = string | number | boolean | string[];
|
|
5
|
-
type SpanEvent = {
|
|
6
|
-
name: string;
|
|
7
|
-
time: Date;
|
|
8
|
-
attributes?: Record<string, SpanAttributeValue>;
|
|
9
|
-
};
|
|
10
|
-
type Span = {
|
|
11
|
-
traceId: string;
|
|
12
|
-
spanId: string;
|
|
13
|
-
parentSpanId?: string;
|
|
14
|
-
name: string;
|
|
15
|
-
startTime: Date;
|
|
16
|
-
endTime: Date;
|
|
17
|
-
attributes: Record<string, SpanAttributeValue>;
|
|
18
|
-
events?: SpanEvent[];
|
|
19
|
-
status?: {
|
|
20
|
-
code: number;
|
|
21
|
-
message?: string;
|
|
22
|
-
};
|
|
23
|
-
kind?: number; /** Service name for this span (if different from default). */
|
|
24
|
-
serviceName?: string;
|
|
25
|
-
};
|
|
26
|
-
//#endregion
|
|
27
3
|
//#region src/reporter/reporter.d.ts
|
|
28
4
|
declare class PlaywrightOpentelemetryReporter implements Reporter {
|
|
29
5
|
private spanBatches;
|
|
@@ -53,4 +29,4 @@ declare class PlaywrightOpentelemetryReporter implements Reporter {
|
|
|
53
29
|
private sendScreenshotsZipToTraceApi;
|
|
54
30
|
}
|
|
55
31
|
//#endregion
|
|
56
|
-
export {
|
|
32
|
+
export { PlaywrightOpentelemetryReporter as t };
|
|
@@ -1,29 +1,5 @@
|
|
|
1
1
|
import { FullConfig, FullResult, Reporter, Suite, TestCase, TestResult, TestStep } from "@playwright/test/reporter";
|
|
2
2
|
|
|
3
|
-
//#region src/shared/otel.d.ts
|
|
4
|
-
type SpanAttributeValue = string | number | boolean | string[];
|
|
5
|
-
type SpanEvent = {
|
|
6
|
-
name: string;
|
|
7
|
-
time: Date;
|
|
8
|
-
attributes?: Record<string, SpanAttributeValue>;
|
|
9
|
-
};
|
|
10
|
-
type Span = {
|
|
11
|
-
traceId: string;
|
|
12
|
-
spanId: string;
|
|
13
|
-
parentSpanId?: string;
|
|
14
|
-
name: string;
|
|
15
|
-
startTime: Date;
|
|
16
|
-
endTime: Date;
|
|
17
|
-
attributes: Record<string, SpanAttributeValue>;
|
|
18
|
-
events?: SpanEvent[];
|
|
19
|
-
status?: {
|
|
20
|
-
code: number;
|
|
21
|
-
message?: string;
|
|
22
|
-
};
|
|
23
|
-
kind?: number; /** Service name for this span (if different from default). */
|
|
24
|
-
serviceName?: string;
|
|
25
|
-
};
|
|
26
|
-
//#endregion
|
|
27
3
|
//#region src/reporter/reporter.d.ts
|
|
28
4
|
declare class PlaywrightOpentelemetryReporter implements Reporter {
|
|
29
5
|
private spanBatches;
|
|
@@ -53,4 +29,4 @@ declare class PlaywrightOpentelemetryReporter implements Reporter {
|
|
|
53
29
|
private sendScreenshotsZipToTraceApi;
|
|
54
30
|
}
|
|
55
31
|
//#endregion
|
|
56
|
-
export {
|
|
32
|
+
export { PlaywrightOpentelemetryReporter as t };
|
|
@@ -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-
|
|
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
package/dist/reporter.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as PlaywrightOpentelemetryReporter } from "./reporter-
|
|
1
|
+
import { t as PlaywrightOpentelemetryReporter } from "./reporter-C1TwRMjP.cjs";
|
|
2
2
|
export = PlaywrightOpentelemetryReporter;
|
package/dist/reporter.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as PlaywrightOpentelemetryReporter } from "./reporter-
|
|
1
|
+
import { t as PlaywrightOpentelemetryReporter } from "./reporter-C1TwRMjP.mjs";
|
|
2
2
|
export { PlaywrightOpentelemetryReporter as default };
|
package/dist/reporter.mjs
CHANGED
|
@@ -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.
|
|
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 =
|
|
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
|
|
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.
|
|
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 =
|
|
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
|
|
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
|
File without changes
|
|
File without changes
|