playwright-opentelemetry 0.8.0 → 0.9.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/dist/{config-BltzmZgg.mjs → config-Cec6zO6v.mjs} +1 -1
- package/dist/{config-Cc1BZNAB.cjs → config-DtWFdgrv.cjs} +1 -1
- package/dist/fixture.cjs +484 -3
- package/dist/fixture.d.cts +50 -2
- package/dist/fixture.d.mts +50 -2
- package/dist/fixture.mjs +483 -2
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{reporter-C_2H_1Ph.mjs → reporter-BAfvjrKo.mjs} +4 -5
- package/dist/{reporter-Dtah1-91.cjs → reporter-k3LuaBV8.cjs} +4 -5
- package/dist/reporter.cjs +1 -1
- package/dist/reporter.mjs +1 -1
- package/package.json +1 -7
- package/dist/fixture/factory.cjs +0 -3
- package/dist/fixture/factory.d.cts +0 -2
- package/dist/fixture/factory.d.mts +0 -2
- package/dist/fixture/factory.mjs +0 -2
- package/dist/playwright-opentelemetry-fixture-BBMxdNJV.cjs +0 -489
- package/dist/playwright-opentelemetry-fixture-Dx53ybJd.d.cts +0 -67
- package/dist/playwright-opentelemetry-fixture-fBGMe1bl.mjs +0 -483
- package/dist/playwright-opentelemetry-fixture-xHcfAc5d.d.mts +0 -67
|
@@ -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.9.0";
|
|
25
25
|
//#endregion
|
|
26
26
|
//#region src/shared/otel.ts
|
|
27
27
|
/** Generate a random 32-character hex trace ID. */
|
package/dist/fixture.cjs
CHANGED
|
@@ -1,10 +1,491 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_config = require("./config-DtWFdgrv.cjs");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
node_path = require_config.__toESM(node_path, 1);
|
|
3
5
|
let _playwright_test = require("@playwright/test");
|
|
6
|
+
//#region src/fixture/browser-page-tracker.ts
|
|
7
|
+
const BROWSER_PAGE_SPAN_NAME = "browser.page";
|
|
8
|
+
const BROWSER_ROUTE_SPAN_NAME = "browser.route";
|
|
9
|
+
const BROWSER_SERVICE_NAME = "playwright-browser";
|
|
10
|
+
const SPAN_STATUS_CODE_UNSET$1 = 0;
|
|
11
|
+
var BrowserPageTracker = class {
|
|
12
|
+
traceContext;
|
|
13
|
+
nextPageId = 1;
|
|
14
|
+
pageStates = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
pages = /* @__PURE__ */ new Set();
|
|
16
|
+
constructor(traceContext) {
|
|
17
|
+
this.traceContext = traceContext;
|
|
18
|
+
}
|
|
19
|
+
registerPage(page) {
|
|
20
|
+
this.stateFor(page);
|
|
21
|
+
this.pages.add(page);
|
|
22
|
+
}
|
|
23
|
+
unregisterPage(page, endTime = /* @__PURE__ */ new Date()) {
|
|
24
|
+
this.finishPageSpans(page, endTime);
|
|
25
|
+
this.pages.delete(page);
|
|
26
|
+
}
|
|
27
|
+
finishAll(endTime = /* @__PURE__ */ new Date()) {
|
|
28
|
+
for (const page of this.pages) this.finishPageSpans(page, endTime);
|
|
29
|
+
this.pages.clear();
|
|
30
|
+
}
|
|
31
|
+
startDocumentNavigation(request) {
|
|
32
|
+
if (!isMainFrameNavigationRequest(request)) return;
|
|
33
|
+
const page = pageForRequest(request);
|
|
34
|
+
if (!page) return;
|
|
35
|
+
this.startDocumentPageSpan(page, request.url(), /* @__PURE__ */ new Date());
|
|
36
|
+
}
|
|
37
|
+
handleFrameNavigated(page, url) {
|
|
38
|
+
const state = this.stateFor(page);
|
|
39
|
+
const previousUrl = state.lastUrl;
|
|
40
|
+
state.lastUrl = url;
|
|
41
|
+
if (!previousUrl || previousUrl === "about:blank") return;
|
|
42
|
+
if (!shouldCreateSameDocumentPageSpan(previousUrl, url, state.activeRouteSpan?.url)) return;
|
|
43
|
+
this.startRouteSpan(page, url, previousUrl, /* @__PURE__ */ new Date());
|
|
44
|
+
}
|
|
45
|
+
getNetworkParent(request) {
|
|
46
|
+
const page = pageForRequest(request);
|
|
47
|
+
if (!page) return {
|
|
48
|
+
spanId: this.traceContext.rootSpanId,
|
|
49
|
+
routeAssociation: "root"
|
|
50
|
+
};
|
|
51
|
+
const state = this.stateFor(page);
|
|
52
|
+
if (state.activeRouteSpan) return {
|
|
53
|
+
spanId: state.activeRouteSpan.span.spanId,
|
|
54
|
+
routeAssociation: "active-route"
|
|
55
|
+
};
|
|
56
|
+
if (state.activeDocumentSpan) return {
|
|
57
|
+
spanId: state.activeDocumentSpan.span.spanId,
|
|
58
|
+
routeAssociation: "active-page"
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
spanId: this.traceContext.rootSpanId,
|
|
62
|
+
routeAssociation: "root"
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
recordConsoleMessage(page, message, time = /* @__PURE__ */ new Date()) {
|
|
66
|
+
const activeSpan = this.getActiveBrowserSpan(page);
|
|
67
|
+
if (!activeSpan) return;
|
|
68
|
+
const type = message.type();
|
|
69
|
+
const attributes = {
|
|
70
|
+
message: message.text(),
|
|
71
|
+
"browser.console.type": type,
|
|
72
|
+
"severity.text": consoleSeverityText(type)
|
|
73
|
+
};
|
|
74
|
+
const location = message.location();
|
|
75
|
+
if (location.url) attributes["code.file.path"] = location.url;
|
|
76
|
+
const line = consoleLocationLine(location);
|
|
77
|
+
if (line !== void 0) attributes["code.line.number"] = line + 1;
|
|
78
|
+
activeSpan.events.push({
|
|
79
|
+
name: "log",
|
|
80
|
+
time,
|
|
81
|
+
attributes
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
recordPageError(page, error, time = /* @__PURE__ */ new Date()) {
|
|
85
|
+
const activeSpan = this.getActiveBrowserSpan(page);
|
|
86
|
+
if (!activeSpan) return;
|
|
87
|
+
const attributes = {};
|
|
88
|
+
if (error.name) attributes["exception.type"] = error.name;
|
|
89
|
+
if (error.message) attributes["exception.message"] = error.message;
|
|
90
|
+
if (error.stack) attributes["exception.stacktrace"] = error.stack;
|
|
91
|
+
activeSpan.events.push({
|
|
92
|
+
name: "exception",
|
|
93
|
+
time,
|
|
94
|
+
attributes
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
startDocumentPageSpan(page, url, startTime) {
|
|
98
|
+
const state = this.stateFor(page);
|
|
99
|
+
this.finishPageSpans(page, startTime);
|
|
100
|
+
const span = this.createBrowserSpan({
|
|
101
|
+
pageId: state.pageId,
|
|
102
|
+
name: BROWSER_PAGE_SPAN_NAME,
|
|
103
|
+
url,
|
|
104
|
+
navigationType: "document",
|
|
105
|
+
parentSpanId: this.traceContext.rootSpanId,
|
|
106
|
+
startTime
|
|
107
|
+
});
|
|
108
|
+
state.activeDocumentSpan = {
|
|
109
|
+
span,
|
|
110
|
+
url
|
|
111
|
+
};
|
|
112
|
+
state.documentUrl = url;
|
|
113
|
+
state.lastUrl = url;
|
|
114
|
+
this.traceContext.addSpan(span);
|
|
115
|
+
}
|
|
116
|
+
startRouteSpan(page, url, previousUrl, startTime) {
|
|
117
|
+
const state = this.stateFor(page);
|
|
118
|
+
this.finishRouteSpan(state, startTime);
|
|
119
|
+
const span = this.createBrowserSpan({
|
|
120
|
+
pageId: state.pageId,
|
|
121
|
+
name: BROWSER_ROUTE_SPAN_NAME,
|
|
122
|
+
url,
|
|
123
|
+
navigationType: "same-document",
|
|
124
|
+
parentSpanId: state.activeDocumentSpan?.span.spanId ?? this.traceContext.rootSpanId,
|
|
125
|
+
startTime,
|
|
126
|
+
previousUrl,
|
|
127
|
+
documentUrl: state.documentUrl
|
|
128
|
+
});
|
|
129
|
+
state.activeRouteSpan = {
|
|
130
|
+
span,
|
|
131
|
+
url
|
|
132
|
+
};
|
|
133
|
+
this.traceContext.addSpan(span);
|
|
134
|
+
}
|
|
135
|
+
finishPageSpans(page, endTime) {
|
|
136
|
+
const state = this.pageStates.get(page);
|
|
137
|
+
if (!state) return;
|
|
138
|
+
this.finishRouteSpan(state, endTime);
|
|
139
|
+
if (state.activeDocumentSpan) {
|
|
140
|
+
state.activeDocumentSpan.span.endTime = endTime;
|
|
141
|
+
state.activeDocumentSpan = void 0;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
finishRouteSpan(state, endTime) {
|
|
145
|
+
if (state.activeRouteSpan) {
|
|
146
|
+
state.activeRouteSpan.span.endTime = endTime;
|
|
147
|
+
state.activeRouteSpan = void 0;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
getActiveBrowserSpan(page) {
|
|
151
|
+
const state = this.pageStates.get(page);
|
|
152
|
+
return state?.activeRouteSpan?.span ?? state?.activeDocumentSpan?.span;
|
|
153
|
+
}
|
|
154
|
+
stateFor(page) {
|
|
155
|
+
const existing = this.pageStates.get(page);
|
|
156
|
+
if (existing) return existing;
|
|
157
|
+
const state = {
|
|
158
|
+
pageId: `page-${this.nextPageId++}`,
|
|
159
|
+
lastUrl: page.url()
|
|
160
|
+
};
|
|
161
|
+
this.pageStates.set(page, state);
|
|
162
|
+
return state;
|
|
163
|
+
}
|
|
164
|
+
createBrowserSpan({ pageId, name, url, navigationType, parentSpanId, startTime, previousUrl, documentUrl }) {
|
|
165
|
+
return {
|
|
166
|
+
traceId: this.traceContext.traceId,
|
|
167
|
+
spanId: require_config.generateSpanId(),
|
|
168
|
+
parentSpanId,
|
|
169
|
+
name,
|
|
170
|
+
startTime,
|
|
171
|
+
endTime: startTime,
|
|
172
|
+
status: { code: SPAN_STATUS_CODE_UNSET$1 },
|
|
173
|
+
attributes: pageAttributes({
|
|
174
|
+
pageId,
|
|
175
|
+
url,
|
|
176
|
+
navigationType,
|
|
177
|
+
previousUrl,
|
|
178
|
+
documentUrl
|
|
179
|
+
}),
|
|
180
|
+
events: [],
|
|
181
|
+
serviceName: BROWSER_SERVICE_NAME
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
function consoleSeverityText(type) {
|
|
186
|
+
switch (type) {
|
|
187
|
+
case "debug": return "DEBUG";
|
|
188
|
+
case "warning": return "WARN";
|
|
189
|
+
case "error":
|
|
190
|
+
case "assert": return "ERROR";
|
|
191
|
+
case "trace": return "TRACE";
|
|
192
|
+
default: return "INFO";
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function consoleLocationLine(location) {
|
|
196
|
+
return location.line ?? location.lineNumber;
|
|
197
|
+
}
|
|
198
|
+
function pageAttributes({ pageId, url, navigationType, previousUrl, documentUrl }) {
|
|
199
|
+
const attributes = {
|
|
200
|
+
"browser.resource.type": navigationType === "document" ? "page" : "route",
|
|
201
|
+
"browser.page.id": pageId,
|
|
202
|
+
"browser.page.navigation.type": navigationType,
|
|
203
|
+
"url.full": url
|
|
204
|
+
};
|
|
205
|
+
try {
|
|
206
|
+
const parsedUrl = new URL(url);
|
|
207
|
+
attributes["url.path"] = parsedUrl.pathname;
|
|
208
|
+
if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
|
|
209
|
+
} catch {}
|
|
210
|
+
if (previousUrl) attributes["browser.route.previous_url"] = previousUrl;
|
|
211
|
+
if (documentUrl) attributes["browser.document.url"] = documentUrl;
|
|
212
|
+
return attributes;
|
|
213
|
+
}
|
|
214
|
+
function isMainFrameNavigationRequest(request) {
|
|
215
|
+
if (!request.isNavigationRequest()) return false;
|
|
216
|
+
try {
|
|
217
|
+
const frame = request.frame();
|
|
218
|
+
return frame === frame.page().mainFrame();
|
|
219
|
+
} catch {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function pageForRequest(request) {
|
|
224
|
+
try {
|
|
225
|
+
return request.frame().page();
|
|
226
|
+
} catch {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function stripHash(url) {
|
|
231
|
+
try {
|
|
232
|
+
const parsed = new URL(url);
|
|
233
|
+
parsed.hash = "";
|
|
234
|
+
return parsed.toString();
|
|
235
|
+
} catch {
|
|
236
|
+
return url.split("#")[0] ?? url;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function shouldCreateSameDocumentPageSpan(previousUrl, nextUrl, activePageUrl) {
|
|
240
|
+
if (activePageUrl && stripHash(activePageUrl) === stripHash(nextUrl)) return false;
|
|
241
|
+
return stripHash(previousUrl) !== stripHash(nextUrl);
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/fixture/network-propagator.ts
|
|
245
|
+
function storeRequestTraceContext({ request, traceContext, parentSpanId, routeAssociation }) {
|
|
246
|
+
const spanId = require_config.generateSpanId();
|
|
247
|
+
traceContext.requestContexts.set(request, {
|
|
248
|
+
traceId: traceContext.traceId,
|
|
249
|
+
spanId,
|
|
250
|
+
parentSpanId,
|
|
251
|
+
routeAssociation
|
|
252
|
+
});
|
|
253
|
+
return spanId;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Intercepts network requests to propagate trace context via traceparent header.
|
|
257
|
+
* @param options - The propagator options
|
|
258
|
+
*/
|
|
259
|
+
async function propagateRouteTraceHeaders({ route, request, traceId, spanId }) {
|
|
260
|
+
const traceHeader = `00-${traceId}-${spanId}-01`;
|
|
261
|
+
await route.fallback({ headers: {
|
|
262
|
+
...request.headers(),
|
|
263
|
+
traceparent: traceHeader
|
|
264
|
+
} });
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/fixture/reporter-config.ts
|
|
268
|
+
const PLAYWRIGHT_OPENTELEMETRY_REPORTER_NAMES = new Set(["playwright-opentelemetry", "playwright-opentelemetry/reporter"]);
|
|
269
|
+
const PLAYWRIGHT_OPENTELEMETRY_REPORTER_PATHS = ["dist/reporter.mjs", "dist/reporter.cjs"];
|
|
270
|
+
const MISSING_PLAYWRIGHT_OPENTELEMETRY_REPORTER_ERROR = `playwright-opentelemetry fixture is enabled, but the reporter is missing.
|
|
271
|
+
|
|
272
|
+
Add it to playwright.config.ts:
|
|
273
|
+
|
|
274
|
+
reporter: [["playwright-opentelemetry/reporter"]]`;
|
|
275
|
+
function hasPlaywrightOpentelemetryReporter(reporter) {
|
|
276
|
+
return reporter.some(([reporterName]) => isPlaywrightOpentelemetryReporterName(reporterName));
|
|
277
|
+
}
|
|
278
|
+
function isPlaywrightOpentelemetryReporterName(reporterName) {
|
|
279
|
+
if (PLAYWRIGHT_OPENTELEMETRY_REPORTER_NAMES.has(reporterName)) return true;
|
|
280
|
+
const normalizedReporterName = reporterName.replace(/\\/g, "/");
|
|
281
|
+
return PLAYWRIGHT_OPENTELEMETRY_REPORTER_PATHS.some((reporterPath) => normalizedReporterName === reporterPath || normalizedReporterName.endsWith(`/${reporterPath}`));
|
|
282
|
+
}
|
|
283
|
+
//#endregion
|
|
284
|
+
//#region src/fixture/request-response-capture.ts
|
|
285
|
+
/**
|
|
286
|
+
* Detects the resource type based on Content-Type header with URL extension fallback.
|
|
287
|
+
* This categorization mirrors Chrome DevTools Network tab behavior.
|
|
288
|
+
*
|
|
289
|
+
* @param contentType - The Content-Type response header value (may be null)
|
|
290
|
+
* @param url - The request URL (used as fallback)
|
|
291
|
+
* @returns The detected resource type
|
|
292
|
+
*/
|
|
293
|
+
function detectResourceType(contentType, url) {
|
|
294
|
+
if (contentType) {
|
|
295
|
+
const mimeType = contentType.split(";")[0].trim().toLowerCase();
|
|
296
|
+
if (mimeType !== "application/octet-stream") {
|
|
297
|
+
if (mimeType === "text/html" || mimeType === "application/xhtml+xml") return "document";
|
|
298
|
+
if (mimeType === "application/javascript" || mimeType === "text/javascript" || mimeType === "application/x-javascript" || mimeType === "application/ecmascript" || mimeType === "text/ecmascript" || mimeType === "module" || mimeType === "application/wasm") return "script";
|
|
299
|
+
if (mimeType === "text/css") return "stylesheet";
|
|
300
|
+
if (mimeType.startsWith("image/")) return "image";
|
|
301
|
+
if (mimeType.startsWith("font/") || mimeType === "application/font-woff" || mimeType === "application/font-woff2" || mimeType === "application/x-font-ttf" || mimeType === "application/x-font-opentype") return "font";
|
|
302
|
+
if (mimeType.startsWith("video/") || mimeType.startsWith("audio/")) return "media";
|
|
303
|
+
if (mimeType === "application/json" || mimeType === "text/plain" || mimeType === "application/xml" || mimeType === "text/xml" || mimeType.endsWith("+json") || mimeType.endsWith("+xml")) return "fetch";
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const resourceType = detectResourceTypeFromUrl(url);
|
|
307
|
+
if (resourceType) return resourceType;
|
|
308
|
+
return "other";
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Detects resource type from URL file extension.
|
|
312
|
+
* Used as fallback when Content-Type header is missing or generic.
|
|
313
|
+
*/
|
|
314
|
+
function detectResourceTypeFromUrl(url) {
|
|
315
|
+
try {
|
|
316
|
+
const lastSegment = new URL(url).pathname.toLowerCase().split("/").pop() || "";
|
|
317
|
+
const dotIndex = lastSegment.lastIndexOf(".");
|
|
318
|
+
if (dotIndex === -1) return null;
|
|
319
|
+
const extension = lastSegment.slice(dotIndex + 1);
|
|
320
|
+
if (extension === "html" || extension === "htm" || extension === "xhtml") return "document";
|
|
321
|
+
if (extension === "js" || extension === "mjs" || extension === "cjs" || extension === "jsx" || extension === "ts" || extension === "tsx" || extension === "wasm") return "script";
|
|
322
|
+
if (extension === "css") return "stylesheet";
|
|
323
|
+
if (extension === "png" || extension === "jpg" || extension === "jpeg" || extension === "gif" || extension === "svg" || extension === "webp" || extension === "ico" || extension === "bmp" || extension === "avif") return "image";
|
|
324
|
+
if (extension === "woff" || extension === "woff2" || extension === "ttf" || extension === "otf" || extension === "eot") return "font";
|
|
325
|
+
if (extension === "mp4" || extension === "webm" || extension === "ogg" || extension === "mp3" || extension === "wav" || extension === "m4a" || extension === "aac" || extension === "flac" || extension === "avi" || extension === "mov") return "media";
|
|
326
|
+
if (extension === "json" || extension === "xml") return "fetch";
|
|
327
|
+
return null;
|
|
328
|
+
} catch {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* OpenTelemetry SpanKind values
|
|
334
|
+
* @see https://opentelemetry.io/docs/specs/otel/trace/api/#spankind
|
|
335
|
+
*/
|
|
336
|
+
const SPAN_KIND_CLIENT = 3;
|
|
337
|
+
/**
|
|
338
|
+
* OpenTelemetry SpanStatusCode values
|
|
339
|
+
* @see https://opentelemetry.io/docs/specs/otel/trace/api/#set-status
|
|
340
|
+
*/
|
|
341
|
+
const SPAN_STATUS_CODE_UNSET = 0;
|
|
342
|
+
const SPAN_STATUS_CODE_ERROR = 2;
|
|
343
|
+
/**
|
|
344
|
+
* Captures request/response data and stores the complete network span in the
|
|
345
|
+
* current test trace context. Called after the request has completed.
|
|
346
|
+
*
|
|
347
|
+
* @param options - The capture options
|
|
348
|
+
*/
|
|
349
|
+
async function fixtureCaptureRequestResponse({ request, response, traceContext }) {
|
|
350
|
+
const url = request.url();
|
|
351
|
+
const method = request.method();
|
|
352
|
+
const statusCode = response.status();
|
|
353
|
+
const requestTraceContext = traceContext.requestContexts.get(request);
|
|
354
|
+
if (!requestTraceContext) return;
|
|
355
|
+
const timing = request.timing();
|
|
356
|
+
const startTime = new Date(timing.startTime);
|
|
357
|
+
const endTime = timing.responseEnd >= 0 ? new Date(timing.startTime + timing.responseEnd) : new Date(timing.startTime);
|
|
358
|
+
const parsedUrl = new URL(url);
|
|
359
|
+
const serverAddress = parsedUrl.hostname;
|
|
360
|
+
const serverPort = parsedUrl.port !== "" ? Number.parseInt(parsedUrl.port, 10) : parsedUrl.protocol === "https:" ? 443 : 80;
|
|
361
|
+
let statusCodeValue = SPAN_STATUS_CODE_UNSET;
|
|
362
|
+
if (statusCode >= 400) statusCodeValue = SPAN_STATUS_CODE_ERROR;
|
|
363
|
+
const resourceType = detectResourceType(await getResponseHeaderValue(response, "content-type"), url);
|
|
364
|
+
const attributes = {
|
|
365
|
+
"http.request.method": method,
|
|
366
|
+
"url.full": url,
|
|
367
|
+
"url.path": parsedUrl.pathname,
|
|
368
|
+
"server.address": serverAddress,
|
|
369
|
+
"server.port": serverPort,
|
|
370
|
+
"http.response.status_code": statusCode,
|
|
371
|
+
"http.resource.type": resourceType,
|
|
372
|
+
"browser.request.route_association": requestTraceContext.routeAssociation
|
|
373
|
+
};
|
|
374
|
+
if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
|
|
375
|
+
if (statusCodeValue === SPAN_STATUS_CODE_ERROR) attributes["error.type"] = statusCode.toString();
|
|
376
|
+
const networkSpan = {
|
|
377
|
+
traceId: requestTraceContext.traceId,
|
|
378
|
+
spanId: requestTraceContext.spanId,
|
|
379
|
+
parentSpanId: requestTraceContext.parentSpanId,
|
|
380
|
+
name: `HTTP ${method}`,
|
|
381
|
+
kind: SPAN_KIND_CLIENT,
|
|
382
|
+
startTime,
|
|
383
|
+
endTime,
|
|
384
|
+
status: { code: statusCodeValue },
|
|
385
|
+
attributes,
|
|
386
|
+
events: [],
|
|
387
|
+
serviceName: "playwright-browser"
|
|
388
|
+
};
|
|
389
|
+
traceContext.addSpan(networkSpan);
|
|
390
|
+
}
|
|
391
|
+
async function getResponseHeaderValue(response, name) {
|
|
392
|
+
try {
|
|
393
|
+
return await response.headerValue(name);
|
|
394
|
+
} catch {
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
//#endregion
|
|
399
|
+
//#region src/fixture/playwright-opentelemetry-fixture.ts
|
|
400
|
+
function createPlaywrightOtelTest(testBase) {
|
|
401
|
+
return testBase.extend({
|
|
402
|
+
playwrightOpentelemetry: [void 0, { option: true }],
|
|
403
|
+
_playwrightOpentelemetryReporterCheck: [async ({}, use, workerInfo) => {
|
|
404
|
+
if (!hasPlaywrightOpentelemetryReporter(workerInfo.config.reporter)) throw new Error(MISSING_PLAYWRIGHT_OPENTELEMETRY_REPORTER_ERROR);
|
|
405
|
+
await use();
|
|
406
|
+
}, {
|
|
407
|
+
scope: "worker",
|
|
408
|
+
auto: true
|
|
409
|
+
}],
|
|
410
|
+
testTraceInfo: [async ({ playwright }, use, testInfo) => {
|
|
411
|
+
const outputDir = node_path.default.dirname(testInfo.outputDir);
|
|
412
|
+
await use({
|
|
413
|
+
testId: testInfo.testId,
|
|
414
|
+
outputDir
|
|
415
|
+
});
|
|
416
|
+
}, { auto: true }],
|
|
417
|
+
testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
|
|
418
|
+
const config = require_config.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
419
|
+
const traceContext = await require_config.createTestTraceContext(testInfo);
|
|
420
|
+
await use(traceContext);
|
|
421
|
+
await require_config.flushFixtureSpans(traceContext, config, {
|
|
422
|
+
trace: config.trace ?? trace,
|
|
423
|
+
testInfo
|
|
424
|
+
});
|
|
425
|
+
}, { auto: true }],
|
|
426
|
+
browserPageTracker: [async ({ testTraceContext }, use) => {
|
|
427
|
+
const tracker = new BrowserPageTracker(testTraceContext);
|
|
428
|
+
await use(tracker);
|
|
429
|
+
tracker.finishAll();
|
|
430
|
+
}, { auto: true }],
|
|
431
|
+
context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker }, use) => {
|
|
432
|
+
const config = require_config.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
433
|
+
context.route("**", async (route, request) => {
|
|
434
|
+
browserPageTracker.startDocumentNavigation(request);
|
|
435
|
+
const networkParent = browserPageTracker.getNetworkParent(request);
|
|
436
|
+
const spanId = storeRequestTraceContext({
|
|
437
|
+
request,
|
|
438
|
+
traceContext: testTraceContext,
|
|
439
|
+
parentSpanId: networkParent.spanId,
|
|
440
|
+
routeAssociation: networkParent.routeAssociation
|
|
441
|
+
});
|
|
442
|
+
if (config.propagateTraceHeaders) {
|
|
443
|
+
await propagateRouteTraceHeaders({
|
|
444
|
+
route,
|
|
445
|
+
request,
|
|
446
|
+
traceId: testTraceContext.traceId,
|
|
447
|
+
spanId
|
|
448
|
+
});
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
await route.fallback();
|
|
452
|
+
});
|
|
453
|
+
await use(context);
|
|
454
|
+
},
|
|
455
|
+
page: async ({ page, testTraceContext, browserPageTracker }, use) => {
|
|
456
|
+
browserPageTracker.registerPage(page);
|
|
457
|
+
page.on("close", () => browserPageTracker.unregisterPage(page));
|
|
458
|
+
page.on("console", (message) => {
|
|
459
|
+
browserPageTracker.recordConsoleMessage(page, message);
|
|
460
|
+
});
|
|
461
|
+
page.on("pageerror", (error) => {
|
|
462
|
+
browserPageTracker.recordPageError(page, error);
|
|
463
|
+
});
|
|
464
|
+
page.on("framenavigated", (frame) => {
|
|
465
|
+
if (frame === page.mainFrame()) browserPageTracker.handleFrameNavigated(page, frame.url());
|
|
466
|
+
});
|
|
467
|
+
const pendingRequests = /* @__PURE__ */ new Map();
|
|
468
|
+
page.on("response", (response) => {
|
|
469
|
+
pendingRequests.set(response.request(), response);
|
|
470
|
+
});
|
|
471
|
+
page.on("requestfinished", async (request) => {
|
|
472
|
+
const response = pendingRequests.get(request);
|
|
473
|
+
pendingRequests.delete(request);
|
|
474
|
+
if (!response) return;
|
|
475
|
+
await fixtureCaptureRequestResponse({
|
|
476
|
+
request,
|
|
477
|
+
response,
|
|
478
|
+
traceContext: testTraceContext
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
await use(page);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
//#endregion
|
|
4
486
|
//#region src/fixture/index.ts
|
|
5
|
-
const test =
|
|
487
|
+
const test = createPlaywrightOtelTest(_playwright_test.test);
|
|
6
488
|
//#endregion
|
|
7
|
-
exports.createPlaywrightOtelTest = require_playwright_opentelemetry_fixture.createPlaywrightOtelTest;
|
|
8
489
|
exports.test = test;
|
|
9
490
|
Object.keys(_playwright_test).forEach(function(k) {
|
|
10
491
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
package/dist/fixture.d.cts
CHANGED
|
@@ -1,7 +1,55 @@
|
|
|
1
1
|
import { n as PlaywrightOpentelemetryUseOptions, r as PlaywrightTraceOption, t as PlaywrightOpentelemetryConfig } from "./config-Db932l_s.cjs";
|
|
2
|
-
import { n as
|
|
2
|
+
import { n as SpanEvent, t as Span } from "./otel-D0ztpic2.cjs";
|
|
3
|
+
import { ConsoleMessage, Page, Request } from "@playwright/test";
|
|
3
4
|
export * from "@playwright/test";
|
|
4
5
|
|
|
6
|
+
//#region src/fixture/trace-context.d.ts
|
|
7
|
+
interface PlaywrightOtelTraceContextAttachment {
|
|
8
|
+
traceId: string;
|
|
9
|
+
rootSpanId: string;
|
|
10
|
+
}
|
|
11
|
+
type FixtureSpan = Omit<Span, "events"> & {
|
|
12
|
+
events: SpanEvent[];
|
|
13
|
+
};
|
|
14
|
+
interface NetworkRequestTraceContext {
|
|
15
|
+
traceId: string;
|
|
16
|
+
spanId: string;
|
|
17
|
+
parentSpanId: string;
|
|
18
|
+
routeAssociation: "active-route" | "active-page" | "root";
|
|
19
|
+
}
|
|
20
|
+
interface TestTraceContext extends PlaywrightOtelTraceContextAttachment {
|
|
21
|
+
spans: FixtureSpan[];
|
|
22
|
+
requestContexts: WeakMap<object, NetworkRequestTraceContext>;
|
|
23
|
+
addSpan(span: FixtureSpan): void;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/fixture/browser-page-tracker.d.ts
|
|
27
|
+
declare class BrowserPageTracker {
|
|
28
|
+
private readonly traceContext;
|
|
29
|
+
private nextPageId;
|
|
30
|
+
private pageStates;
|
|
31
|
+
private pages;
|
|
32
|
+
constructor(traceContext: TestTraceContext);
|
|
33
|
+
registerPage(page: Page): void;
|
|
34
|
+
unregisterPage(page: Page, endTime?: Date): void;
|
|
35
|
+
finishAll(endTime?: Date): void;
|
|
36
|
+
startDocumentNavigation(request: Request): void;
|
|
37
|
+
handleFrameNavigated(page: Page, url: string): void;
|
|
38
|
+
getNetworkParent(request: Request): {
|
|
39
|
+
spanId: string;
|
|
40
|
+
routeAssociation: "active-route" | "active-page" | "root";
|
|
41
|
+
};
|
|
42
|
+
recordConsoleMessage(page: Page, message: ConsoleMessage, time?: Date): void;
|
|
43
|
+
recordPageError(page: Page, error: Error, time?: Date): void;
|
|
44
|
+
private startDocumentPageSpan;
|
|
45
|
+
private startRouteSpan;
|
|
46
|
+
private finishPageSpans;
|
|
47
|
+
private finishRouteSpan;
|
|
48
|
+
private getActiveBrowserSpan;
|
|
49
|
+
private stateFor;
|
|
50
|
+
private createBrowserSpan;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
5
53
|
//#region src/fixture/index.d.ts
|
|
6
54
|
declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & PlaywrightOpentelemetryUseOptions & {
|
|
7
55
|
testTraceInfo: {
|
|
@@ -14,4 +62,4 @@ declare const test: import("@playwright/test").TestType<import("@playwright/test
|
|
|
14
62
|
_playwrightOpentelemetryReporterCheck: void;
|
|
15
63
|
}>;
|
|
16
64
|
//#endregion
|
|
17
|
-
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption,
|
|
65
|
+
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, test };
|
package/dist/fixture.d.mts
CHANGED
|
@@ -1,7 +1,55 @@
|
|
|
1
1
|
import { n as PlaywrightOpentelemetryUseOptions, r as PlaywrightTraceOption, t as PlaywrightOpentelemetryConfig } from "./config-Db932l_s.mjs";
|
|
2
|
-
import { n as
|
|
2
|
+
import { n as SpanEvent, t as Span } from "./otel-D0ztpic2.mjs";
|
|
3
|
+
import { ConsoleMessage, Page, Request } from "@playwright/test";
|
|
3
4
|
export * from "@playwright/test";
|
|
4
5
|
|
|
6
|
+
//#region src/fixture/trace-context.d.ts
|
|
7
|
+
interface PlaywrightOtelTraceContextAttachment {
|
|
8
|
+
traceId: string;
|
|
9
|
+
rootSpanId: string;
|
|
10
|
+
}
|
|
11
|
+
type FixtureSpan = Omit<Span, "events"> & {
|
|
12
|
+
events: SpanEvent[];
|
|
13
|
+
};
|
|
14
|
+
interface NetworkRequestTraceContext {
|
|
15
|
+
traceId: string;
|
|
16
|
+
spanId: string;
|
|
17
|
+
parentSpanId: string;
|
|
18
|
+
routeAssociation: "active-route" | "active-page" | "root";
|
|
19
|
+
}
|
|
20
|
+
interface TestTraceContext extends PlaywrightOtelTraceContextAttachment {
|
|
21
|
+
spans: FixtureSpan[];
|
|
22
|
+
requestContexts: WeakMap<object, NetworkRequestTraceContext>;
|
|
23
|
+
addSpan(span: FixtureSpan): void;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/fixture/browser-page-tracker.d.ts
|
|
27
|
+
declare class BrowserPageTracker {
|
|
28
|
+
private readonly traceContext;
|
|
29
|
+
private nextPageId;
|
|
30
|
+
private pageStates;
|
|
31
|
+
private pages;
|
|
32
|
+
constructor(traceContext: TestTraceContext);
|
|
33
|
+
registerPage(page: Page): void;
|
|
34
|
+
unregisterPage(page: Page, endTime?: Date): void;
|
|
35
|
+
finishAll(endTime?: Date): void;
|
|
36
|
+
startDocumentNavigation(request: Request): void;
|
|
37
|
+
handleFrameNavigated(page: Page, url: string): void;
|
|
38
|
+
getNetworkParent(request: Request): {
|
|
39
|
+
spanId: string;
|
|
40
|
+
routeAssociation: "active-route" | "active-page" | "root";
|
|
41
|
+
};
|
|
42
|
+
recordConsoleMessage(page: Page, message: ConsoleMessage, time?: Date): void;
|
|
43
|
+
recordPageError(page: Page, error: Error, time?: Date): void;
|
|
44
|
+
private startDocumentPageSpan;
|
|
45
|
+
private startRouteSpan;
|
|
46
|
+
private finishPageSpans;
|
|
47
|
+
private finishRouteSpan;
|
|
48
|
+
private getActiveBrowserSpan;
|
|
49
|
+
private stateFor;
|
|
50
|
+
private createBrowserSpan;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
5
53
|
//#region src/fixture/index.d.ts
|
|
6
54
|
declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & PlaywrightOpentelemetryUseOptions & {
|
|
7
55
|
testTraceInfo: {
|
|
@@ -14,4 +62,4 @@ declare const test: import("@playwright/test").TestType<import("@playwright/test
|
|
|
14
62
|
_playwrightOpentelemetryReporterCheck: void;
|
|
15
63
|
}>;
|
|
16
64
|
//#endregion
|
|
17
|
-
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption,
|
|
65
|
+
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, test };
|