playwright-opentelemetry 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{config-DFY22ysa.d.cts → config-g9K4ZUC_.d.cts} +9 -0
- package/dist/{config-DFY22ysa.d.mts → config-g9K4ZUC_.d.mts} +9 -0
- package/dist/fixture.cjs +14 -9
- package/dist/fixture.d.cts +1 -1
- package/dist/fixture.d.mts +1 -1
- package/dist/fixture.mjs +14 -9
- 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/{reporter-DaCojFom.d.cts → reporter-C1TwRMjP.d.cts} +7 -0
- package/dist/{reporter-DaCojFom.d.mts → reporter-C1TwRMjP.d.mts} +7 -0
- package/dist/{reporter-Z2WIipcT.cjs → reporter-p3Z6GrF-.cjs} +69 -21
- package/dist/{reporter-Owv9goRm.mjs → reporter-t-dJHyfd.mjs} +68 -21
- 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-Cp3l4YRU.mjs → screenshots-zip-CLFTP3sv.mjs} +48 -12
- package/dist/{screenshots-zip-B6_DJ3oU.cjs → screenshots-zip-CNPpbJfR.cjs} +85 -11
- package/package.json +1 -1
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
|
|
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
|
|
|
@@ -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/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-CNPpbJfR.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,
|
|
879
|
-
*
|
|
880
|
-
*
|
|
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
|
|
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,
|
|
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
|
|
1112
|
+
await handOffScreenshots(capture, config, {
|
|
1108
1113
|
trace,
|
|
1109
1114
|
testInfo
|
|
1110
1115
|
});
|
package/dist/fixture.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
1
|
+
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-g9K4ZUC_.cjs";
|
|
2
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";
|
package/dist/fixture.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
1
|
+
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-g9K4ZUC_.mjs";
|
|
2
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";
|
package/dist/fixture.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as supportsScreencastScreenshots, d as flushFixtureSpans, f as registerExpectedTrace,
|
|
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";
|
|
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,
|
|
876
|
-
*
|
|
877
|
-
*
|
|
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
|
|
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,
|
|
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
|
|
1109
|
+
await handOffScreenshots(capture, config, {
|
|
1105
1110
|
trace,
|
|
1106
1111
|
testInfo
|
|
1107
1112
|
});
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
2
|
-
import { t as PlaywrightOpentelemetryReporter } from "./reporter-
|
|
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 { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
2
|
-
import { t as PlaywrightOpentelemetryReporter } from "./reporter-
|
|
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
|
@@ -4,6 +4,7 @@ import { FullConfig, FullResult, Reporter, Suite, TestCase, TestResult, TestStep
|
|
|
4
4
|
declare class PlaywrightOpentelemetryReporter implements Reporter {
|
|
5
5
|
private spanBatches;
|
|
6
6
|
private pendingTraceArtifacts;
|
|
7
|
+
private fixtureHandoffRoots;
|
|
7
8
|
private rootDir?;
|
|
8
9
|
private playwrightVersion?;
|
|
9
10
|
private debug;
|
|
@@ -14,6 +15,12 @@ declare class PlaywrightOpentelemetryReporter implements Reporter {
|
|
|
14
15
|
onStepEnd(_test: TestCase, _result: TestResult, _step: TestStep): void;
|
|
15
16
|
onTestEnd(test: TestCase, result: TestResult): void;
|
|
16
17
|
onEnd(_result: FullResult): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* What the fixture handed over for this test attempt: its attachments with
|
|
20
|
+
* `attachFixtureData`, otherwise the files in the attempt's handoff
|
|
21
|
+
* directory, which is deleted here whether or not the test is reported.
|
|
22
|
+
*/
|
|
23
|
+
private takeFixtureData;
|
|
17
24
|
private prepareTraceArtifact;
|
|
18
25
|
private processTestStep;
|
|
19
26
|
onStdOut(chunk: string | Buffer, _test: TestCase, _result: TestResult): void;
|
|
@@ -4,6 +4,7 @@ import { FullConfig, FullResult, Reporter, Suite, TestCase, TestResult, TestStep
|
|
|
4
4
|
declare class PlaywrightOpentelemetryReporter implements Reporter {
|
|
5
5
|
private spanBatches;
|
|
6
6
|
private pendingTraceArtifacts;
|
|
7
|
+
private fixtureHandoffRoots;
|
|
7
8
|
private rootDir?;
|
|
8
9
|
private playwrightVersion?;
|
|
9
10
|
private debug;
|
|
@@ -14,6 +15,12 @@ declare class PlaywrightOpentelemetryReporter implements Reporter {
|
|
|
14
15
|
onStepEnd(_test: TestCase, _result: TestResult, _step: TestStep): void;
|
|
15
16
|
onTestEnd(test: TestCase, result: TestResult): void;
|
|
16
17
|
onEnd(_result: FullResult): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* What the fixture handed over for this test attempt: its attachments with
|
|
20
|
+
* `attachFixtureData`, otherwise the files in the attempt's handoff
|
|
21
|
+
* directory, which is deleted here whether or not the test is reported.
|
|
22
|
+
*/
|
|
23
|
+
private takeFixtureData;
|
|
17
24
|
private prepareTraceArtifact;
|
|
18
25
|
private processTestStep;
|
|
19
26
|
onStdOut(chunk: string | Buffer, _test: TestCase, _result: TestResult): void;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const require_screenshots_zip = require("./screenshots-zip-
|
|
1
|
+
const require_screenshots_zip = require("./screenshots-zip-CNPpbJfR.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 } =
|
|
216
|
-
const fixtureSpans = retainedConfig.storeTraceZip ?
|
|
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
|
-
|
|
265
|
+
screenshotsZip: fixtureData.screenshotsZip,
|
|
262
266
|
traceAttachmentPath: traceAttachment?.path,
|
|
263
267
|
traceId,
|
|
264
268
|
config: retainedConfig,
|
|
@@ -272,6 +276,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
272
276
|
}
|
|
273
277
|
}
|
|
274
278
|
async onEnd(_result) {
|
|
279
|
+
for (const root of this.fixtureHandoffRoots) await node_fs_promises.default.rmdir(root).catch(() => {});
|
|
275
280
|
const destinations = /* @__PURE__ */ new Map();
|
|
276
281
|
for (const batch of this.spanBatches) {
|
|
277
282
|
for (const destination of batch.config.otlpDestinations) {
|
|
@@ -313,6 +318,36 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
313
318
|
const traceApiFailure = sendFailures.find((failure) => failure.destination.kind === "trace-api");
|
|
314
319
|
if (traceApiFailure) throw traceApiFailure.error;
|
|
315
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
|
+
}
|
|
350
|
+
}
|
|
316
351
|
async prepareTraceArtifact(options) {
|
|
317
352
|
const screenshots = await readTestScreenshots(options);
|
|
318
353
|
const traceZipBlobPromise = options.config.storeTraceZip ? createTraceZipBlob({
|
|
@@ -400,16 +435,16 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
400
435
|
};
|
|
401
436
|
/**
|
|
402
437
|
* A test's screenshots. Playwright versions with a usable screencast only use
|
|
403
|
-
* the frames the fixture captured
|
|
438
|
+
* the frames the fixture captured; older versions only use
|
|
404
439
|
* Playwright's trace. Never rejects: a test's spans are still sent without
|
|
405
440
|
* its screenshots.
|
|
406
441
|
*/
|
|
407
442
|
async function readTestScreenshots(options) {
|
|
408
443
|
if (!options.config.screenshots) return [];
|
|
409
444
|
if (require_screenshots_zip.supportsScreencastScreenshots(options.playwrightVersion)) {
|
|
410
|
-
if (!options.
|
|
445
|
+
if (!options.screenshotsZip) return [];
|
|
411
446
|
try {
|
|
412
|
-
return await require_screenshots_zip.readScreenshotsZip(new Blob([
|
|
447
|
+
return await require_screenshots_zip.readScreenshotsZip(new Blob([options.screenshotsZip]));
|
|
413
448
|
} catch (error) {
|
|
414
449
|
console.warn(`Failed to read the test's screenshots: ${error instanceof Error ? error.message : String(error)}`);
|
|
415
450
|
return [];
|
|
@@ -424,8 +459,11 @@ function getProjectPlaywrightOpentelemetryConfig(project) {
|
|
|
424
459
|
function getTestConfig(test) {
|
|
425
460
|
return require_screenshots_zip.resolvePlaywrightOpentelemetryConfig(getProjectPlaywrightOpentelemetryConfig(test.parent.project()), { requireDestination: true });
|
|
426
461
|
}
|
|
462
|
+
function getProjectOutputDir(test) {
|
|
463
|
+
return test.parent.project()?.outputDir;
|
|
464
|
+
}
|
|
427
465
|
function getTestOutputDir(test) {
|
|
428
|
-
const outputDir = test
|
|
466
|
+
const outputDir = getProjectOutputDir(test);
|
|
429
467
|
if (!outputDir) throw new Error(`No outputDir found for test "${test.id}"`);
|
|
430
468
|
return outputDir;
|
|
431
469
|
}
|
|
@@ -452,31 +490,41 @@ function hasTraceApiDestination(config) {
|
|
|
452
490
|
function hasPlaywrightOpentelemetryDestination(config) {
|
|
453
491
|
return Boolean(config.storeTraceZip || config.otlpDestinations.some((destination) => destination.url) || config.playwrightTraceApiDestinations.some((destination) => destination.url));
|
|
454
492
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
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 {
|
|
458
507
|
traceId: require_screenshots_zip.generateTraceId(),
|
|
459
508
|
rootSpanId: require_screenshots_zip.generateSpanId()
|
|
460
509
|
};
|
|
461
510
|
let parsed;
|
|
462
511
|
try {
|
|
463
|
-
parsed = JSON.parse(
|
|
512
|
+
parsed = JSON.parse(body.toString("utf-8"));
|
|
464
513
|
} catch (error) {
|
|
465
|
-
throw new Error(`Invalid ${require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME}
|
|
514
|
+
throw new Error(`Invalid ${require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME} for test ${testId}: ${error}`);
|
|
466
515
|
}
|
|
467
|
-
if (!isTraceContextAttachment(parsed)) throw new Error(`Invalid ${require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME}
|
|
516
|
+
if (!isTraceContextAttachment(parsed)) throw new Error(`Invalid ${require_screenshots_zip.TRACE_CONTEXT_ATTACHMENT_NAME} for test ${testId}: expected { traceId, rootSpanId }`);
|
|
468
517
|
return parsed;
|
|
469
518
|
}
|
|
470
|
-
function
|
|
471
|
-
|
|
472
|
-
if (!attachment?.body) return [];
|
|
519
|
+
function parseFixtureSpans(body, testId) {
|
|
520
|
+
if (!body) return [];
|
|
473
521
|
let parsed;
|
|
474
522
|
try {
|
|
475
|
-
parsed = JSON.parse(
|
|
523
|
+
parsed = JSON.parse(body.toString("utf-8"));
|
|
476
524
|
} catch (error) {
|
|
477
|
-
throw new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME}
|
|
525
|
+
throw new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME} for test ${testId}: ${error}`);
|
|
478
526
|
}
|
|
479
|
-
if (!isRecord(parsed) || !Array.isArray(parsed.spans)) throw new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME}
|
|
527
|
+
if (!isRecord(parsed) || !Array.isArray(parsed.spans)) throw new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME} for test ${testId}: expected { spans }`);
|
|
480
528
|
return parsed.spans.map((span, index) => parseFixtureSpan(span, testId, index));
|
|
481
529
|
}
|
|
482
530
|
function parseFixtureSpan(value, testId, index) {
|
|
@@ -503,7 +551,7 @@ function parseFixtureSpan(value, testId, index) {
|
|
|
503
551
|
};
|
|
504
552
|
}
|
|
505
553
|
function invalidFixtureSpanError(testId, index) {
|
|
506
|
-
return /* @__PURE__ */ new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME}
|
|
554
|
+
return /* @__PURE__ */ new Error(`Invalid ${require_screenshots_zip.FIXTURE_SPANS_ATTACHMENT_NAME} for test ${testId}: invalid span at index ${index}`);
|
|
507
555
|
}
|
|
508
556
|
function parseAttachmentDate(value) {
|
|
509
557
|
if (typeof value !== "string") return;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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";
|
|
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 } =
|
|
214
|
-
const fixtureSpans = retainedConfig.storeTraceZip ?
|
|
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
|
-
|
|
262
|
+
screenshotsZip: fixtureData.screenshotsZip,
|
|
260
263
|
traceAttachmentPath: traceAttachment?.path,
|
|
261
264
|
traceId,
|
|
262
265
|
config: retainedConfig,
|
|
@@ -270,6 +273,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
270
273
|
}
|
|
271
274
|
}
|
|
272
275
|
async onEnd(_result) {
|
|
276
|
+
for (const root of this.fixtureHandoffRoots) await fs.rmdir(root).catch(() => {});
|
|
273
277
|
const destinations = /* @__PURE__ */ new Map();
|
|
274
278
|
for (const batch of this.spanBatches) {
|
|
275
279
|
for (const destination of batch.config.otlpDestinations) {
|
|
@@ -311,6 +315,36 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
311
315
|
const traceApiFailure = sendFailures.find((failure) => failure.destination.kind === "trace-api");
|
|
312
316
|
if (traceApiFailure) throw traceApiFailure.error;
|
|
313
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
|
+
}
|
|
347
|
+
}
|
|
314
348
|
async prepareTraceArtifact(options) {
|
|
315
349
|
const screenshots = await readTestScreenshots(options);
|
|
316
350
|
const traceZipBlobPromise = options.config.storeTraceZip ? createTraceZipBlob({
|
|
@@ -398,16 +432,16 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
398
432
|
};
|
|
399
433
|
/**
|
|
400
434
|
* A test's screenshots. Playwright versions with a usable screencast only use
|
|
401
|
-
* the frames the fixture captured
|
|
435
|
+
* the frames the fixture captured; older versions only use
|
|
402
436
|
* Playwright's trace. Never rejects: a test's spans are still sent without
|
|
403
437
|
* its screenshots.
|
|
404
438
|
*/
|
|
405
439
|
async function readTestScreenshots(options) {
|
|
406
440
|
if (!options.config.screenshots) return [];
|
|
407
441
|
if (supportsScreencastScreenshots(options.playwrightVersion)) {
|
|
408
|
-
if (!options.
|
|
442
|
+
if (!options.screenshotsZip) return [];
|
|
409
443
|
try {
|
|
410
|
-
return await readScreenshotsZip(new Blob([
|
|
444
|
+
return await readScreenshotsZip(new Blob([options.screenshotsZip]));
|
|
411
445
|
} catch (error) {
|
|
412
446
|
console.warn(`Failed to read the test's screenshots: ${error instanceof Error ? error.message : String(error)}`);
|
|
413
447
|
return [];
|
|
@@ -422,8 +456,11 @@ function getProjectPlaywrightOpentelemetryConfig(project) {
|
|
|
422
456
|
function getTestConfig(test) {
|
|
423
457
|
return resolvePlaywrightOpentelemetryConfig(getProjectPlaywrightOpentelemetryConfig(test.parent.project()), { requireDestination: true });
|
|
424
458
|
}
|
|
459
|
+
function getProjectOutputDir(test) {
|
|
460
|
+
return test.parent.project()?.outputDir;
|
|
461
|
+
}
|
|
425
462
|
function getTestOutputDir(test) {
|
|
426
|
-
const outputDir = test
|
|
463
|
+
const outputDir = getProjectOutputDir(test);
|
|
427
464
|
if (!outputDir) throw new Error(`No outputDir found for test "${test.id}"`);
|
|
428
465
|
return outputDir;
|
|
429
466
|
}
|
|
@@ -450,31 +487,41 @@ function hasTraceApiDestination(config) {
|
|
|
450
487
|
function hasPlaywrightOpentelemetryDestination(config) {
|
|
451
488
|
return Boolean(config.storeTraceZip || config.otlpDestinations.some((destination) => destination.url) || config.playwrightTraceApiDestinations.some((destination) => destination.url));
|
|
452
489
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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 {
|
|
456
504
|
traceId: generateTraceId(),
|
|
457
505
|
rootSpanId: generateSpanId()
|
|
458
506
|
};
|
|
459
507
|
let parsed;
|
|
460
508
|
try {
|
|
461
|
-
parsed = JSON.parse(
|
|
509
|
+
parsed = JSON.parse(body.toString("utf-8"));
|
|
462
510
|
} catch (error) {
|
|
463
|
-
throw new Error(`Invalid ${TRACE_CONTEXT_ATTACHMENT_NAME}
|
|
511
|
+
throw new Error(`Invalid ${TRACE_CONTEXT_ATTACHMENT_NAME} for test ${testId}: ${error}`);
|
|
464
512
|
}
|
|
465
|
-
if (!isTraceContextAttachment(parsed)) throw new Error(`Invalid ${TRACE_CONTEXT_ATTACHMENT_NAME}
|
|
513
|
+
if (!isTraceContextAttachment(parsed)) throw new Error(`Invalid ${TRACE_CONTEXT_ATTACHMENT_NAME} for test ${testId}: expected { traceId, rootSpanId }`);
|
|
466
514
|
return parsed;
|
|
467
515
|
}
|
|
468
|
-
function
|
|
469
|
-
|
|
470
|
-
if (!attachment?.body) return [];
|
|
516
|
+
function parseFixtureSpans(body, testId) {
|
|
517
|
+
if (!body) return [];
|
|
471
518
|
let parsed;
|
|
472
519
|
try {
|
|
473
|
-
parsed = JSON.parse(
|
|
520
|
+
parsed = JSON.parse(body.toString("utf-8"));
|
|
474
521
|
} catch (error) {
|
|
475
|
-
throw new Error(`Invalid ${FIXTURE_SPANS_ATTACHMENT_NAME}
|
|
522
|
+
throw new Error(`Invalid ${FIXTURE_SPANS_ATTACHMENT_NAME} for test ${testId}: ${error}`);
|
|
476
523
|
}
|
|
477
|
-
if (!isRecord(parsed) || !Array.isArray(parsed.spans)) throw new Error(`Invalid ${FIXTURE_SPANS_ATTACHMENT_NAME}
|
|
524
|
+
if (!isRecord(parsed) || !Array.isArray(parsed.spans)) throw new Error(`Invalid ${FIXTURE_SPANS_ATTACHMENT_NAME} for test ${testId}: expected { spans }`);
|
|
478
525
|
return parsed.spans.map((span, index) => parseFixtureSpan(span, testId, index));
|
|
479
526
|
}
|
|
480
527
|
function parseFixtureSpan(value, testId, index) {
|
|
@@ -501,7 +548,7 @@ function parseFixtureSpan(value, testId, index) {
|
|
|
501
548
|
};
|
|
502
549
|
}
|
|
503
550
|
function invalidFixtureSpanError(testId, index) {
|
|
504
|
-
return /* @__PURE__ */ new Error(`Invalid ${FIXTURE_SPANS_ATTACHMENT_NAME}
|
|
551
|
+
return /* @__PURE__ */ new Error(`Invalid ${FIXTURE_SPANS_ATTACHMENT_NAME} for test ${testId}: invalid span at index ${index}`);
|
|
505
552
|
}
|
|
506
553
|
function parseAttachmentDate(value) {
|
|
507
554
|
if (typeof value !== "string") return;
|
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
|
@@ -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.
|
|
5
|
+
var version = "0.18.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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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))
|
|
243
|
-
body
|
|
244
|
-
|
|
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,
|
|
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 };
|
|
@@ -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.
|
|
29
|
+
var version = "0.18.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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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))
|
|
265
|
-
body
|
|
266
|
-
|
|
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
|
+
});
|