playwright-opentelemetry 0.7.0 → 0.8.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/{config-C8VVYvBv.cjs → config-Z0Hqjd_6.cjs} +1 -1
- package/dist/{config-B9rx_m23.mjs → config-uXd4Im5F.mjs} +1 -1
- package/dist/fixture/factory.cjs +1 -1
- package/dist/fixture/factory.mjs +1 -1
- package/dist/fixture.cjs +1 -1
- package/dist/fixture.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{playwright-opentelemetry-fixture-DABcsfrU.mjs → playwright-opentelemetry-fixture-2vhqZLmh.mjs} +1 -1
- package/dist/{playwright-opentelemetry-fixture-CGLwOCBm.cjs → playwright-opentelemetry-fixture-BQXmeAcf.cjs} +1 -1
- package/dist/{reporter-CtflXoLs.mjs → reporter-CM4W2jxM.mjs} +63 -15
- package/dist/{reporter-D4iIeblG.cjs → reporter-DKlbB_nC.cjs} +62 -14
- package/dist/reporter.cjs +1 -1
- package/dist/reporter.mjs +1 -1
- package/package.json +2 -2
|
@@ -21,7 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region package.json
|
|
24
|
-
var version = "0.
|
|
24
|
+
var version = "0.8.1";
|
|
25
25
|
//#endregion
|
|
26
26
|
//#region src/shared/otel.ts
|
|
27
27
|
/** Generate a random 32-character hex trace ID. */
|
package/dist/fixture/factory.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_playwright_opentelemetry_fixture = require("../playwright-opentelemetry-fixture-
|
|
2
|
+
const require_playwright_opentelemetry_fixture = require("../playwright-opentelemetry-fixture-BQXmeAcf.cjs");
|
|
3
3
|
exports.createPlaywrightOtelTest = require_playwright_opentelemetry_fixture.createPlaywrightOtelTest;
|
package/dist/fixture/factory.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createPlaywrightOtelTest } from "../playwright-opentelemetry-fixture-
|
|
1
|
+
import { t as createPlaywrightOtelTest } from "../playwright-opentelemetry-fixture-2vhqZLmh.mjs";
|
|
2
2
|
export { createPlaywrightOtelTest };
|
package/dist/fixture.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_playwright_opentelemetry_fixture = require("./playwright-opentelemetry-fixture-
|
|
2
|
+
const require_playwright_opentelemetry_fixture = require("./playwright-opentelemetry-fixture-BQXmeAcf.cjs");
|
|
3
3
|
let _playwright_test = require("@playwright/test");
|
|
4
4
|
//#region src/fixture/index.ts
|
|
5
5
|
const test = require_playwright_opentelemetry_fixture.createPlaywrightOtelTest(_playwright_test.test);
|
package/dist/fixture.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createPlaywrightOtelTest } from "./playwright-opentelemetry-fixture-
|
|
1
|
+
import { t as createPlaywrightOtelTest } from "./playwright-opentelemetry-fixture-2vhqZLmh.mjs";
|
|
2
2
|
import { test as test$1 } from "@playwright/test";
|
|
3
3
|
export * from "@playwright/test";
|
|
4
4
|
//#region src/fixture/index.ts
|
package/dist/index.cjs
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as flushFixtureSpans, c as generateSpanId, i as createTestTraceContext, t as resolvePlaywrightOpentelemetryConfig } from "./config-
|
|
1
|
+
import { a as flushFixtureSpans, c as generateSpanId, i as createTestTraceContext, t as resolvePlaywrightOpentelemetryConfig } from "./config-uXd4Im5F.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
//#region src/fixture/browser-page-tracker.ts
|
|
4
4
|
const BROWSER_PAGE_SPAN_NAME = "browser.page";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { c as generateSpanId, l as generateTraceId, n as FIXTURE_SPANS_ATTACHMENT_NAME, o as shouldRetainPlaywrightTrace, r as TRACE_CONTEXT_ATTACHMENT_NAME, s as buildOtlpRequest, t as resolvePlaywrightOpentelemetryConfig, u as sendSpans } from "./config-
|
|
1
|
+
import { c as generateSpanId, l as generateTraceId, n as FIXTURE_SPANS_ATTACHMENT_NAME, o as shouldRetainPlaywrightTrace, r as TRACE_CONTEXT_ATTACHMENT_NAME, s as buildOtlpRequest, t as resolvePlaywrightOpentelemetryConfig, u as sendSpans } from "./config-uXd4Im5F.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
|
-
import { BlobReader, BlobWriter, ZipReader, ZipWriter } from "@zip.js/zip.js";
|
|
4
|
+
import { BlobReader, BlobWriter, TextWriter, ZipReader, ZipWriter } from "@zip.js/zip.js";
|
|
5
5
|
//#region src/reporter/otel-attributes.ts
|
|
6
6
|
const ATTR_CODE_FILE_PATH = "code.file.path";
|
|
7
7
|
const ATTR_CODE_LINE_NUMBER = "code.line.number";
|
|
@@ -38,7 +38,7 @@ const PLAYWRIGHT_SCREENSHOT_PATTERN = /^.+@[a-f0-9]+-\d+\.jpe?g$/i;
|
|
|
38
38
|
* {pageGuid}-{timestamp}.jpeg (e.g., page@abc123-1766929201038.jpeg)
|
|
39
39
|
*
|
|
40
40
|
* @param traceZipPath - Path to the Playwright trace.zip file
|
|
41
|
-
* @returns Map of filename (without resources/ prefix) to
|
|
41
|
+
* @returns Map of filename (without resources/ prefix) to screenshot resources
|
|
42
42
|
*/
|
|
43
43
|
async function extractScreenshotsFromPlaywrightTrace(traceZipPath) {
|
|
44
44
|
const screenshots = /* @__PURE__ */ new Map();
|
|
@@ -46,6 +46,7 @@ async function extractScreenshotsFromPlaywrightTrace(traceZipPath) {
|
|
|
46
46
|
const zipBuffer = await fs.readFile(traceZipPath);
|
|
47
47
|
const zipReader = new ZipReader(new BlobReader(new Blob([zipBuffer])));
|
|
48
48
|
const entries = await zipReader.getEntries();
|
|
49
|
+
const screenshotMetadata = await extractScreenshotTraceMetadata(entries);
|
|
49
50
|
await Promise.all(entries.filter((entry) => {
|
|
50
51
|
if (!isFileEntry(entry)) return false;
|
|
51
52
|
if (!entry.filename.startsWith(PLAYWRIGHT_TRACE_RESOURCES_DIR)) return false;
|
|
@@ -54,7 +55,15 @@ async function extractScreenshotsFromPlaywrightTrace(traceZipPath) {
|
|
|
54
55
|
}).map(async (entry) => {
|
|
55
56
|
const filename = entry.filename.slice(10);
|
|
56
57
|
const blob = await entry.getData(new BlobWriter("image/jpeg"));
|
|
57
|
-
|
|
58
|
+
const metadata = screenshotMetadata.get(filename);
|
|
59
|
+
screenshots.set(filename, {
|
|
60
|
+
blob,
|
|
61
|
+
file: filename,
|
|
62
|
+
timestamp: extractTimestampFromFilename(filename),
|
|
63
|
+
contentType: getMimeType(filename),
|
|
64
|
+
contextId: metadata?.contextId ?? "unknown-context",
|
|
65
|
+
pageId: metadata?.pageId ?? extractResourceIdFromFilename(filename)
|
|
66
|
+
});
|
|
58
67
|
}));
|
|
59
68
|
await zipReader.close();
|
|
60
69
|
} catch (err) {
|
|
@@ -89,25 +98,65 @@ async function writeTraceZip(outputDir, test, zipBlob) {
|
|
|
89
98
|
async function addScreenshotsToZip(zipWriter, screenshots) {
|
|
90
99
|
const manifest = createScreenshotManifest(screenshots);
|
|
91
100
|
await zipWriter.add("manifest.json", new Blob([JSON.stringify(manifest, null, 2)], { type: "application/json" }).stream());
|
|
92
|
-
for (const [filename,
|
|
101
|
+
for (const [filename, screenshot] of screenshots.entries()) await zipWriter.add(`screenshots/${filename}`, screenshot.blob.stream());
|
|
93
102
|
}
|
|
94
103
|
function createScreenshotManifest(screenshots) {
|
|
95
104
|
return {
|
|
96
|
-
version:
|
|
97
|
-
screenshots: Array.from(screenshots.
|
|
98
|
-
timestamp:
|
|
99
|
-
file:
|
|
100
|
-
path: `screenshots/${
|
|
101
|
-
contentType:
|
|
105
|
+
version: 2,
|
|
106
|
+
screenshots: Array.from(screenshots.values()).map((screenshot) => ({
|
|
107
|
+
timestamp: screenshot.timestamp,
|
|
108
|
+
file: screenshot.file,
|
|
109
|
+
path: `screenshots/${screenshot.file}`,
|
|
110
|
+
contentType: screenshot.contentType,
|
|
111
|
+
contextId: screenshot.contextId,
|
|
112
|
+
pageId: screenshot.pageId
|
|
102
113
|
})).sort((a, b) => a.timestamp - b.timestamp)
|
|
103
114
|
};
|
|
104
115
|
}
|
|
116
|
+
async function extractScreenshotTraceMetadata(entries) {
|
|
117
|
+
const metadata = /* @__PURE__ */ new Map();
|
|
118
|
+
const traceEntries = entries.filter((entry) => isFileEntry(entry) && isPlaywrightTraceEntry(entry.filename));
|
|
119
|
+
await Promise.all(traceEntries.map(async (entry) => {
|
|
120
|
+
const text = await entry.getData(new TextWriter());
|
|
121
|
+
let contextId = "unknown-context";
|
|
122
|
+
for (const line of text.split("\n")) {
|
|
123
|
+
if (!line.trim()) continue;
|
|
124
|
+
const event = parseTraceEvent(line);
|
|
125
|
+
if (!event) continue;
|
|
126
|
+
if (event.type === "context-options" && typeof event.contextId === "string") {
|
|
127
|
+
contextId = event.contextId;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (event.type === "screencast-frame" && typeof event.sha1 === "string" && typeof event.pageId === "string") metadata.set(event.sha1, {
|
|
131
|
+
contextId,
|
|
132
|
+
pageId: event.pageId
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}));
|
|
136
|
+
return metadata;
|
|
137
|
+
}
|
|
138
|
+
function isPlaywrightTraceEntry(filename) {
|
|
139
|
+
return filename === "trace.trace" || filename.endsWith("-trace.trace");
|
|
140
|
+
}
|
|
141
|
+
function parseTraceEvent(line) {
|
|
142
|
+
try {
|
|
143
|
+
const value = JSON.parse(line);
|
|
144
|
+
return typeof value === "object" && value !== null ? value : void 0;
|
|
145
|
+
} catch {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
105
149
|
function extractTimestampFromFilename(filename) {
|
|
106
150
|
const lastDashIndex = filename.lastIndexOf("-");
|
|
107
151
|
if (lastDashIndex === -1) return 0;
|
|
108
152
|
const timestamp = Number.parseInt(filename.slice(lastDashIndex + 1).replace(/\.[^.]+$/, ""), 10);
|
|
109
153
|
return Number.isNaN(timestamp) ? 0 : timestamp;
|
|
110
154
|
}
|
|
155
|
+
function extractResourceIdFromFilename(filename) {
|
|
156
|
+
const lastDashIndex = filename.lastIndexOf("-");
|
|
157
|
+
if (lastDashIndex === -1) return "unknown-page";
|
|
158
|
+
return filename.slice(0, lastDashIndex) || "unknown-page";
|
|
159
|
+
}
|
|
111
160
|
function getMimeType(filename) {
|
|
112
161
|
switch (filename.split(".").pop()?.toLowerCase()) {
|
|
113
162
|
case "png": return "image/png";
|
|
@@ -153,10 +202,9 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
153
202
|
const outputDir = getTestOutputDir(test);
|
|
154
203
|
const { traceId, rootSpanId: testSpanId } = readTraceContextAttachment(result, testId);
|
|
155
204
|
const fixtureSpans = config.storeTraceZip ? readFixtureSpansAttachment(result, testId) : [];
|
|
156
|
-
result.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
body: Buffer.from(traceId, "utf-8")
|
|
205
|
+
result.annotations.push({
|
|
206
|
+
type: "playwrightOpentelemetryTraceId",
|
|
207
|
+
description: traceId
|
|
160
208
|
});
|
|
161
209
|
const attributes = {};
|
|
162
210
|
const titlePath = test.titlePath();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_config = require("./config-
|
|
1
|
+
const require_config = require("./config-Z0Hqjd_6.cjs");
|
|
2
2
|
let node_path = require("node:path");
|
|
3
3
|
node_path = require_config.__toESM(node_path, 1);
|
|
4
4
|
let node_fs_promises = require("node:fs/promises");
|
|
@@ -40,7 +40,7 @@ const PLAYWRIGHT_SCREENSHOT_PATTERN = /^.+@[a-f0-9]+-\d+\.jpe?g$/i;
|
|
|
40
40
|
* {pageGuid}-{timestamp}.jpeg (e.g., page@abc123-1766929201038.jpeg)
|
|
41
41
|
*
|
|
42
42
|
* @param traceZipPath - Path to the Playwright trace.zip file
|
|
43
|
-
* @returns Map of filename (without resources/ prefix) to
|
|
43
|
+
* @returns Map of filename (without resources/ prefix) to screenshot resources
|
|
44
44
|
*/
|
|
45
45
|
async function extractScreenshotsFromPlaywrightTrace(traceZipPath) {
|
|
46
46
|
const screenshots = /* @__PURE__ */ new Map();
|
|
@@ -48,6 +48,7 @@ async function extractScreenshotsFromPlaywrightTrace(traceZipPath) {
|
|
|
48
48
|
const zipBuffer = await node_fs_promises.default.readFile(traceZipPath);
|
|
49
49
|
const zipReader = new _zip_js_zip_js.ZipReader(new _zip_js_zip_js.BlobReader(new Blob([zipBuffer])));
|
|
50
50
|
const entries = await zipReader.getEntries();
|
|
51
|
+
const screenshotMetadata = await extractScreenshotTraceMetadata(entries);
|
|
51
52
|
await Promise.all(entries.filter((entry) => {
|
|
52
53
|
if (!isFileEntry(entry)) return false;
|
|
53
54
|
if (!entry.filename.startsWith(PLAYWRIGHT_TRACE_RESOURCES_DIR)) return false;
|
|
@@ -56,7 +57,15 @@ async function extractScreenshotsFromPlaywrightTrace(traceZipPath) {
|
|
|
56
57
|
}).map(async (entry) => {
|
|
57
58
|
const filename = entry.filename.slice(10);
|
|
58
59
|
const blob = await entry.getData(new _zip_js_zip_js.BlobWriter("image/jpeg"));
|
|
59
|
-
|
|
60
|
+
const metadata = screenshotMetadata.get(filename);
|
|
61
|
+
screenshots.set(filename, {
|
|
62
|
+
blob,
|
|
63
|
+
file: filename,
|
|
64
|
+
timestamp: extractTimestampFromFilename(filename),
|
|
65
|
+
contentType: getMimeType(filename),
|
|
66
|
+
contextId: metadata?.contextId ?? "unknown-context",
|
|
67
|
+
pageId: metadata?.pageId ?? extractResourceIdFromFilename(filename)
|
|
68
|
+
});
|
|
60
69
|
}));
|
|
61
70
|
await zipReader.close();
|
|
62
71
|
} catch (err) {
|
|
@@ -91,25 +100,65 @@ async function writeTraceZip(outputDir, test, zipBlob) {
|
|
|
91
100
|
async function addScreenshotsToZip(zipWriter, screenshots) {
|
|
92
101
|
const manifest = createScreenshotManifest(screenshots);
|
|
93
102
|
await zipWriter.add("manifest.json", new Blob([JSON.stringify(manifest, null, 2)], { type: "application/json" }).stream());
|
|
94
|
-
for (const [filename,
|
|
103
|
+
for (const [filename, screenshot] of screenshots.entries()) await zipWriter.add(`screenshots/${filename}`, screenshot.blob.stream());
|
|
95
104
|
}
|
|
96
105
|
function createScreenshotManifest(screenshots) {
|
|
97
106
|
return {
|
|
98
|
-
version:
|
|
99
|
-
screenshots: Array.from(screenshots.
|
|
100
|
-
timestamp:
|
|
101
|
-
file:
|
|
102
|
-
path: `screenshots/${
|
|
103
|
-
contentType:
|
|
107
|
+
version: 2,
|
|
108
|
+
screenshots: Array.from(screenshots.values()).map((screenshot) => ({
|
|
109
|
+
timestamp: screenshot.timestamp,
|
|
110
|
+
file: screenshot.file,
|
|
111
|
+
path: `screenshots/${screenshot.file}`,
|
|
112
|
+
contentType: screenshot.contentType,
|
|
113
|
+
contextId: screenshot.contextId,
|
|
114
|
+
pageId: screenshot.pageId
|
|
104
115
|
})).sort((a, b) => a.timestamp - b.timestamp)
|
|
105
116
|
};
|
|
106
117
|
}
|
|
118
|
+
async function extractScreenshotTraceMetadata(entries) {
|
|
119
|
+
const metadata = /* @__PURE__ */ new Map();
|
|
120
|
+
const traceEntries = entries.filter((entry) => isFileEntry(entry) && isPlaywrightTraceEntry(entry.filename));
|
|
121
|
+
await Promise.all(traceEntries.map(async (entry) => {
|
|
122
|
+
const text = await entry.getData(new _zip_js_zip_js.TextWriter());
|
|
123
|
+
let contextId = "unknown-context";
|
|
124
|
+
for (const line of text.split("\n")) {
|
|
125
|
+
if (!line.trim()) continue;
|
|
126
|
+
const event = parseTraceEvent(line);
|
|
127
|
+
if (!event) continue;
|
|
128
|
+
if (event.type === "context-options" && typeof event.contextId === "string") {
|
|
129
|
+
contextId = event.contextId;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (event.type === "screencast-frame" && typeof event.sha1 === "string" && typeof event.pageId === "string") metadata.set(event.sha1, {
|
|
133
|
+
contextId,
|
|
134
|
+
pageId: event.pageId
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
138
|
+
return metadata;
|
|
139
|
+
}
|
|
140
|
+
function isPlaywrightTraceEntry(filename) {
|
|
141
|
+
return filename === "trace.trace" || filename.endsWith("-trace.trace");
|
|
142
|
+
}
|
|
143
|
+
function parseTraceEvent(line) {
|
|
144
|
+
try {
|
|
145
|
+
const value = JSON.parse(line);
|
|
146
|
+
return typeof value === "object" && value !== null ? value : void 0;
|
|
147
|
+
} catch {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
107
151
|
function extractTimestampFromFilename(filename) {
|
|
108
152
|
const lastDashIndex = filename.lastIndexOf("-");
|
|
109
153
|
if (lastDashIndex === -1) return 0;
|
|
110
154
|
const timestamp = Number.parseInt(filename.slice(lastDashIndex + 1).replace(/\.[^.]+$/, ""), 10);
|
|
111
155
|
return Number.isNaN(timestamp) ? 0 : timestamp;
|
|
112
156
|
}
|
|
157
|
+
function extractResourceIdFromFilename(filename) {
|
|
158
|
+
const lastDashIndex = filename.lastIndexOf("-");
|
|
159
|
+
if (lastDashIndex === -1) return "unknown-page";
|
|
160
|
+
return filename.slice(0, lastDashIndex) || "unknown-page";
|
|
161
|
+
}
|
|
113
162
|
function getMimeType(filename) {
|
|
114
163
|
switch (filename.split(".").pop()?.toLowerCase()) {
|
|
115
164
|
case "png": return "image/png";
|
|
@@ -155,10 +204,9 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
155
204
|
const outputDir = getTestOutputDir(test);
|
|
156
205
|
const { traceId, rootSpanId: testSpanId } = readTraceContextAttachment(result, testId);
|
|
157
206
|
const fixtureSpans = config.storeTraceZip ? readFixtureSpansAttachment(result, testId) : [];
|
|
158
|
-
result.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
body: Buffer.from(traceId, "utf-8")
|
|
207
|
+
result.annotations.push({
|
|
208
|
+
type: "playwrightOpentelemetryTraceId",
|
|
209
|
+
description: traceId
|
|
162
210
|
});
|
|
163
211
|
const attributes = {};
|
|
164
212
|
const titlePath = test.titlePath();
|
package/dist/reporter.cjs
CHANGED
package/dist/reporter.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playwright-opentelemetry",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@biomejs/biome": "2.4.16",
|
|
64
|
-
"@playwright/test": "1.
|
|
64
|
+
"@playwright/test": "1.61.0",
|
|
65
65
|
"@types/bun": "^1.3.14",
|
|
66
66
|
"@types/node": "^25.9.1",
|
|
67
67
|
"tsdown": "^0.22.1"
|