playwright-opentelemetry 0.5.0 → 0.6.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-B9i3jm5s.d.cts +15 -0
- package/dist/config-B9i3jm5s.d.mts +15 -0
- package/dist/fixture/factory.cjs +2 -2
- package/dist/fixture/factory.d.cts +1 -5
- package/dist/fixture/factory.d.mts +1 -5
- package/dist/fixture/factory.mjs +1 -1
- package/dist/fixture-1Zc7Gp0b.d.cts +61 -0
- package/dist/{factory-kMxwg_DI.cjs → fixture-C85kKbWA.cjs} +193 -100
- package/dist/{factory-Df7HwxXO.mjs → fixture-CQtQM60Z.mjs} +192 -99
- package/dist/fixture-IJvYGCtD.d.mts +61 -0
- package/dist/fixture.cjs +3 -3
- package/dist/fixture.d.cts +13 -3
- package/dist/fixture.d.mts +13 -3
- package/dist/fixture.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +1 -1
- package/dist/otel-B-kvMiiq.d.cts +18 -0
- package/dist/otel-B-kvMiiq.d.mts +18 -0
- package/dist/reporter-DaCojFom.d.cts +25 -0
- package/dist/reporter-DaCojFom.d.mts +25 -0
- package/dist/reporter-S_gsTMix.mjs +429 -0
- package/dist/reporter-XVwaSQDK.cjs +436 -0
- package/dist/reporter.cjs +1 -1
- package/dist/reporter.d.cts +2 -2
- package/dist/reporter.d.mts +2 -2
- package/dist/reporter.mjs +1 -1
- package/dist/trace-context-88H-vhOr.cjs +286 -0
- package/dist/trace-context-e11YEu8B.mjs +205 -0
- package/package.json +1 -1
- package/dist/index-BNfDd8Mg.d.cts +0 -45
- package/dist/index-BNfDd8Mg.d.mts +0 -45
- package/dist/reporter-BE9S9CtV.mjs +0 -461
- package/dist/reporter-BzHSG-gx.cjs +0 -468
- package/dist/trace-files-B6bmvwUq.mjs +0 -218
- package/dist/trace-files-DTK0XBIq.cjs +0 -325
|
@@ -1,79 +1,150 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as resolvePlaywrightOpentelemetryConfig, i as flushFixtureSpans, r as createTestTraceContext, s as generateSpanId } from "./trace-context-e11YEu8B.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";
|
|
5
|
+
const BROWSER_ROUTE_SPAN_NAME = "browser.route";
|
|
5
6
|
const BROWSER_SERVICE_NAME = "playwright-browser";
|
|
6
7
|
const SPAN_STATUS_CODE_UNSET$1 = 0;
|
|
7
8
|
var BrowserPageTracker = class {
|
|
8
|
-
|
|
9
|
-
outputDir;
|
|
9
|
+
traceContext;
|
|
10
10
|
nextPageId = 1;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.testId = testId;
|
|
16
|
-
this.outputDir = outputDir;
|
|
11
|
+
pageStates = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
pages = /* @__PURE__ */ new Set();
|
|
13
|
+
constructor(traceContext) {
|
|
14
|
+
this.traceContext = traceContext;
|
|
17
15
|
}
|
|
18
16
|
registerPage(page) {
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
17
|
+
this.stateFor(page);
|
|
18
|
+
this.pages.add(page);
|
|
19
|
+
}
|
|
20
|
+
unregisterPage(page, endTime = /* @__PURE__ */ new Date()) {
|
|
21
|
+
this.finishPageSpans(page, endTime);
|
|
22
|
+
this.pages.delete(page);
|
|
23
|
+
}
|
|
24
|
+
finishAll(endTime = /* @__PURE__ */ new Date()) {
|
|
25
|
+
for (const page of this.pages) this.finishPageSpans(page, endTime);
|
|
26
|
+
this.pages.clear();
|
|
21
27
|
}
|
|
22
28
|
startDocumentNavigation(request) {
|
|
23
29
|
if (!isMainFrameNavigationRequest(request)) return;
|
|
24
30
|
const page = pageForRequest(request);
|
|
25
31
|
if (!page) return;
|
|
26
|
-
this.
|
|
32
|
+
this.startDocumentPageSpan(page, request.url(), /* @__PURE__ */ new Date());
|
|
27
33
|
}
|
|
28
34
|
handleFrameNavigated(page, url) {
|
|
29
|
-
const
|
|
30
|
-
|
|
35
|
+
const state = this.stateFor(page);
|
|
36
|
+
const previousUrl = state.lastUrl;
|
|
37
|
+
state.lastUrl = url;
|
|
31
38
|
if (!previousUrl || previousUrl === "about:blank") return;
|
|
32
|
-
if (!shouldCreateSameDocumentPageSpan(previousUrl, url,
|
|
33
|
-
this.
|
|
39
|
+
if (!shouldCreateSameDocumentPageSpan(previousUrl, url, state.activeRouteSpan?.url)) return;
|
|
40
|
+
this.startRouteSpan(page, url, previousUrl, /* @__PURE__ */ new Date());
|
|
34
41
|
}
|
|
35
|
-
|
|
42
|
+
getNetworkParent(request) {
|
|
36
43
|
const page = pageForRequest(request);
|
|
37
|
-
if (!page) return
|
|
38
|
-
|
|
44
|
+
if (!page) return {
|
|
45
|
+
spanId: this.traceContext.rootSpanId,
|
|
46
|
+
routeAssociation: "root"
|
|
47
|
+
};
|
|
48
|
+
const state = this.stateFor(page);
|
|
49
|
+
if (state.activeRouteSpan) return {
|
|
50
|
+
spanId: state.activeRouteSpan.span.spanId,
|
|
51
|
+
routeAssociation: "active-route"
|
|
52
|
+
};
|
|
53
|
+
if (state.activeDocumentSpan) return {
|
|
54
|
+
spanId: state.activeDocumentSpan.span.spanId,
|
|
55
|
+
routeAssociation: "active-page"
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
spanId: this.traceContext.rootSpanId,
|
|
59
|
+
routeAssociation: "root"
|
|
60
|
+
};
|
|
39
61
|
}
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const startTime = /* @__PURE__ */ new Date();
|
|
46
|
-
const attributes = pageAttributes(pageId, url, navigationType, previousUrl);
|
|
47
|
-
const span = {
|
|
48
|
-
traceId,
|
|
49
|
-
spanId,
|
|
50
|
-
parentSpanId,
|
|
62
|
+
startDocumentPageSpan(page, url, startTime) {
|
|
63
|
+
const state = this.stateFor(page);
|
|
64
|
+
this.finishPageSpans(page, startTime);
|
|
65
|
+
const span = this.createBrowserSpan({
|
|
66
|
+
pageId: state.pageId,
|
|
51
67
|
name: BROWSER_PAGE_SPAN_NAME,
|
|
68
|
+
url,
|
|
69
|
+
navigationType: "document",
|
|
70
|
+
parentSpanId: this.traceContext.rootSpanId,
|
|
71
|
+
startTime
|
|
72
|
+
});
|
|
73
|
+
state.activeDocumentSpan = {
|
|
74
|
+
span,
|
|
75
|
+
url
|
|
76
|
+
};
|
|
77
|
+
state.documentUrl = url;
|
|
78
|
+
state.lastUrl = url;
|
|
79
|
+
this.traceContext.addSpan(span);
|
|
80
|
+
}
|
|
81
|
+
startRouteSpan(page, url, previousUrl, startTime) {
|
|
82
|
+
const state = this.stateFor(page);
|
|
83
|
+
this.finishRouteSpan(state, startTime);
|
|
84
|
+
const span = this.createBrowserSpan({
|
|
85
|
+
pageId: state.pageId,
|
|
86
|
+
name: BROWSER_ROUTE_SPAN_NAME,
|
|
87
|
+
url,
|
|
88
|
+
navigationType: "same-document",
|
|
89
|
+
parentSpanId: state.activeDocumentSpan?.span.spanId ?? this.traceContext.rootSpanId,
|
|
90
|
+
startTime,
|
|
91
|
+
previousUrl,
|
|
92
|
+
documentUrl: state.documentUrl
|
|
93
|
+
});
|
|
94
|
+
state.activeRouteSpan = {
|
|
95
|
+
span,
|
|
96
|
+
url
|
|
97
|
+
};
|
|
98
|
+
this.traceContext.addSpan(span);
|
|
99
|
+
}
|
|
100
|
+
finishPageSpans(page, endTime) {
|
|
101
|
+
const state = this.pageStates.get(page);
|
|
102
|
+
if (!state) return;
|
|
103
|
+
this.finishRouteSpan(state, endTime);
|
|
104
|
+
if (state.activeDocumentSpan) {
|
|
105
|
+
state.activeDocumentSpan.span.endTime = endTime;
|
|
106
|
+
state.activeDocumentSpan = void 0;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
finishRouteSpan(state, endTime) {
|
|
110
|
+
if (state.activeRouteSpan) {
|
|
111
|
+
state.activeRouteSpan.span.endTime = endTime;
|
|
112
|
+
state.activeRouteSpan = void 0;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
stateFor(page) {
|
|
116
|
+
const existing = this.pageStates.get(page);
|
|
117
|
+
if (existing) return existing;
|
|
118
|
+
const state = {
|
|
119
|
+
pageId: `page-${this.nextPageId++}`,
|
|
120
|
+
lastUrl: page.url()
|
|
121
|
+
};
|
|
122
|
+
this.pageStates.set(page, state);
|
|
123
|
+
return state;
|
|
124
|
+
}
|
|
125
|
+
createBrowserSpan({ pageId, name, url, navigationType, parentSpanId, startTime, previousUrl, documentUrl }) {
|
|
126
|
+
return {
|
|
127
|
+
traceId: this.traceContext.traceId,
|
|
128
|
+
spanId: generateSpanId(),
|
|
129
|
+
parentSpanId,
|
|
130
|
+
name,
|
|
52
131
|
startTime,
|
|
53
132
|
endTime: startTime,
|
|
54
133
|
status: { code: SPAN_STATUS_CODE_UNSET$1 },
|
|
55
|
-
attributes
|
|
134
|
+
attributes: pageAttributes({
|
|
135
|
+
pageId,
|
|
136
|
+
url,
|
|
137
|
+
navigationType,
|
|
138
|
+
previousUrl,
|
|
139
|
+
documentUrl
|
|
140
|
+
}),
|
|
56
141
|
serviceName: BROWSER_SERVICE_NAME
|
|
57
142
|
};
|
|
58
|
-
this.activePageSpans.set(page, {
|
|
59
|
-
pageId,
|
|
60
|
-
spanId,
|
|
61
|
-
url
|
|
62
|
-
});
|
|
63
|
-
this.lastFrameUrls.set(page, url);
|
|
64
|
-
writeBrowserPageSpan(this.outputDir, this.testId, span);
|
|
65
|
-
}
|
|
66
|
-
pageIdFor(page) {
|
|
67
|
-
const existing = this.pageIds.get(page);
|
|
68
|
-
if (existing) return existing;
|
|
69
|
-
const pageId = `page-${this.nextPageId++}`;
|
|
70
|
-
this.pageIds.set(page, pageId);
|
|
71
|
-
return pageId;
|
|
72
143
|
}
|
|
73
144
|
};
|
|
74
|
-
function pageAttributes(pageId, url, navigationType, previousUrl) {
|
|
145
|
+
function pageAttributes({ pageId, url, navigationType, previousUrl, documentUrl }) {
|
|
75
146
|
const attributes = {
|
|
76
|
-
"browser.resource.type": "page",
|
|
147
|
+
"browser.resource.type": navigationType === "document" ? "page" : "route",
|
|
77
148
|
"browser.page.id": pageId,
|
|
78
149
|
"browser.page.navigation.type": navigationType,
|
|
79
150
|
"url.full": url
|
|
@@ -83,7 +154,8 @@ function pageAttributes(pageId, url, navigationType, previousUrl) {
|
|
|
83
154
|
attributes["url.path"] = parsedUrl.pathname;
|
|
84
155
|
if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
|
|
85
156
|
} catch {}
|
|
86
|
-
if (previousUrl) attributes["browser.
|
|
157
|
+
if (previousUrl) attributes["browser.route.previous_url"] = previousUrl;
|
|
158
|
+
if (documentUrl) attributes["browser.document.url"] = documentUrl;
|
|
87
159
|
return attributes;
|
|
88
160
|
}
|
|
89
161
|
function isMainFrameNavigationRequest(request) {
|
|
@@ -119,27 +191,16 @@ function shouldCreateSameDocumentPageSpan(previousUrl, nextUrl, activePageUrl) {
|
|
|
119
191
|
//#region src/fixture/network-propagator.ts
|
|
120
192
|
/**
|
|
121
193
|
* Intercepts network requests to propagate trace context via traceparent header.
|
|
122
|
-
* Also records the parent span ID for later correlation by the response handler.
|
|
123
|
-
*
|
|
124
|
-
* This function only:
|
|
125
|
-
* 1. Creates a span ID for the request
|
|
126
|
-
* 2. Injects the traceparent header
|
|
127
|
-
* 3. Writes a parent file with the current parent span ID
|
|
128
|
-
*
|
|
129
|
-
* The actual span data (timing, status, attributes) is captured by
|
|
130
|
-
* fixtureCaptureRequestResponse when the response is received.
|
|
131
|
-
*
|
|
132
194
|
* @param options - The propagator options
|
|
133
195
|
*/
|
|
134
|
-
async function fixtureOtelHeaderPropagator({ route, request,
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
testId,
|
|
196
|
+
async function fixtureOtelHeaderPropagator({ route, request, traceContext, parentSpanId, routeAssociation }) {
|
|
197
|
+
const spanId = generateSpanId();
|
|
198
|
+
const traceHeader = `00-${traceContext.traceId}-${spanId}-01`;
|
|
199
|
+
traceContext.requestContexts.set(request, {
|
|
200
|
+
traceId: traceContext.traceId,
|
|
201
|
+
spanId,
|
|
141
202
|
parentSpanId,
|
|
142
|
-
|
|
203
|
+
routeAssociation
|
|
143
204
|
});
|
|
144
205
|
await route.fallback({ headers: {
|
|
145
206
|
...request.headers(),
|
|
@@ -147,6 +208,23 @@ async function fixtureOtelHeaderPropagator({ route, request, testId, outputDir,
|
|
|
147
208
|
} });
|
|
148
209
|
}
|
|
149
210
|
//#endregion
|
|
211
|
+
//#region src/fixture/reporter-config.ts
|
|
212
|
+
const PLAYWRIGHT_OPENTELEMETRY_REPORTER_NAMES = new Set(["playwright-opentelemetry", "playwright-opentelemetry/reporter"]);
|
|
213
|
+
const PLAYWRIGHT_OPENTELEMETRY_REPORTER_PATHS = ["dist/reporter.mjs", "dist/reporter.cjs"];
|
|
214
|
+
const MISSING_PLAYWRIGHT_OPENTELEMETRY_REPORTER_ERROR = `playwright-opentelemetry fixture is enabled, but the reporter is missing.
|
|
215
|
+
|
|
216
|
+
Add it to playwright.config.ts:
|
|
217
|
+
|
|
218
|
+
reporter: [["playwright-opentelemetry/reporter"]]`;
|
|
219
|
+
function hasPlaywrightOpentelemetryReporter(reporter) {
|
|
220
|
+
return reporter.some(([reporterName]) => isPlaywrightOpentelemetryReporterName(reporterName));
|
|
221
|
+
}
|
|
222
|
+
function isPlaywrightOpentelemetryReporterName(reporterName) {
|
|
223
|
+
if (PLAYWRIGHT_OPENTELEMETRY_REPORTER_NAMES.has(reporterName)) return true;
|
|
224
|
+
const normalizedReporterName = reporterName.replace(/\\/g, "/");
|
|
225
|
+
return PLAYWRIGHT_OPENTELEMETRY_REPORTER_PATHS.some((reporterPath) => normalizedReporterName === reporterPath || normalizedReporterName.endsWith(`/${reporterPath}`));
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
150
228
|
//#region src/fixture/request-response-capture.ts
|
|
151
229
|
/**
|
|
152
230
|
* Detects the resource type based on Content-Type header with URL extension fallback.
|
|
@@ -207,28 +285,17 @@ const SPAN_KIND_CLIENT = 3;
|
|
|
207
285
|
const SPAN_STATUS_CODE_UNSET = 0;
|
|
208
286
|
const SPAN_STATUS_CODE_ERROR = 2;
|
|
209
287
|
/**
|
|
210
|
-
* Captures request/response data and
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* This function:
|
|
214
|
-
* 1. Extracts the traceparent header to find the parent file
|
|
215
|
-
* 2. Reads the parent span ID from the parent file
|
|
216
|
-
* 3. Builds the complete span with all HTTP attributes
|
|
217
|
-
* 4. Writes the network span for the reporter to collect
|
|
288
|
+
* Captures request/response data and stores the complete network span in the
|
|
289
|
+
* current test trace context. Called after the request has completed.
|
|
218
290
|
*
|
|
219
291
|
* @param options - The capture options
|
|
220
292
|
*/
|
|
221
|
-
async function fixtureCaptureRequestResponse({ request, response,
|
|
293
|
+
async function fixtureCaptureRequestResponse({ request, response, traceContext }) {
|
|
222
294
|
const url = request.url();
|
|
223
295
|
const method = request.method();
|
|
224
296
|
const statusCode = response.status();
|
|
225
|
-
const
|
|
226
|
-
if (!
|
|
227
|
-
const parentSpanId = readNetworkSpanParent(outputDir, testId, traceHeader);
|
|
228
|
-
if (!parentSpanId) return;
|
|
229
|
-
const parts = traceHeader.split("-");
|
|
230
|
-
if (parts.length !== 4) return;
|
|
231
|
-
const [, traceId, spanId] = parts;
|
|
297
|
+
const requestTraceContext = traceContext.requestContexts.get(request);
|
|
298
|
+
if (!requestTraceContext) return;
|
|
232
299
|
const timing = request.timing();
|
|
233
300
|
const startTime = new Date(timing.startTime);
|
|
234
301
|
const endTime = timing.responseEnd >= 0 ? new Date(timing.startTime + timing.responseEnd) : new Date(timing.startTime);
|
|
@@ -237,7 +304,7 @@ async function fixtureCaptureRequestResponse({ request, response, testId, output
|
|
|
237
304
|
const serverPort = parsedUrl.port !== "" ? Number.parseInt(parsedUrl.port, 10) : parsedUrl.protocol === "https:" ? 443 : 80;
|
|
238
305
|
let statusCodeValue = SPAN_STATUS_CODE_UNSET;
|
|
239
306
|
if (statusCode >= 400) statusCodeValue = SPAN_STATUS_CODE_ERROR;
|
|
240
|
-
const resourceType = detectResourceType(await response
|
|
307
|
+
const resourceType = detectResourceType(await getResponseHeaderValue(response, "content-type"), url);
|
|
241
308
|
const attributes = {
|
|
242
309
|
"http.request.method": method,
|
|
243
310
|
"url.full": url,
|
|
@@ -245,14 +312,15 @@ async function fixtureCaptureRequestResponse({ request, response, testId, output
|
|
|
245
312
|
"server.address": serverAddress,
|
|
246
313
|
"server.port": serverPort,
|
|
247
314
|
"http.response.status_code": statusCode,
|
|
248
|
-
"http.resource.type": resourceType
|
|
315
|
+
"http.resource.type": resourceType,
|
|
316
|
+
"browser.request.route_association": requestTraceContext.routeAssociation
|
|
249
317
|
};
|
|
250
318
|
if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
|
|
251
319
|
if (statusCodeValue === SPAN_STATUS_CODE_ERROR) attributes["error.type"] = statusCode.toString();
|
|
252
|
-
|
|
253
|
-
traceId,
|
|
254
|
-
spanId,
|
|
255
|
-
parentSpanId,
|
|
320
|
+
const networkSpan = {
|
|
321
|
+
traceId: requestTraceContext.traceId,
|
|
322
|
+
spanId: requestTraceContext.spanId,
|
|
323
|
+
parentSpanId: requestTraceContext.parentSpanId,
|
|
256
324
|
name: `HTTP ${method}`,
|
|
257
325
|
kind: SPAN_KIND_CLIENT,
|
|
258
326
|
startTime,
|
|
@@ -260,12 +328,28 @@ async function fixtureCaptureRequestResponse({ request, response, testId, output
|
|
|
260
328
|
status: { code: statusCodeValue },
|
|
261
329
|
attributes,
|
|
262
330
|
serviceName: "playwright-browser"
|
|
263
|
-
}
|
|
331
|
+
};
|
|
332
|
+
traceContext.addSpan(networkSpan);
|
|
333
|
+
}
|
|
334
|
+
async function getResponseHeaderValue(response, name) {
|
|
335
|
+
try {
|
|
336
|
+
return await response.headerValue(name);
|
|
337
|
+
} catch {
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
264
340
|
}
|
|
265
341
|
//#endregion
|
|
266
|
-
//#region src/fixture/
|
|
342
|
+
//#region src/fixture/fixture.ts
|
|
267
343
|
function createPlaywrightOtelTest(testBase) {
|
|
268
344
|
return testBase.extend({
|
|
345
|
+
playwrightOpentelemetry: [void 0, { option: true }],
|
|
346
|
+
_playwrightOpentelemetryReporterCheck: [async ({}, use, workerInfo) => {
|
|
347
|
+
if (!hasPlaywrightOpentelemetryReporter(workerInfo.config.reporter)) throw new Error(MISSING_PLAYWRIGHT_OPENTELEMETRY_REPORTER_ERROR);
|
|
348
|
+
await use();
|
|
349
|
+
}, {
|
|
350
|
+
scope: "worker",
|
|
351
|
+
auto: true
|
|
352
|
+
}],
|
|
269
353
|
testTraceInfo: [async ({ playwright }, use, testInfo) => {
|
|
270
354
|
const outputDir = path.dirname(testInfo.outputDir);
|
|
271
355
|
await use({
|
|
@@ -273,24 +357,34 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
273
357
|
outputDir
|
|
274
358
|
});
|
|
275
359
|
}, { auto: true }],
|
|
276
|
-
|
|
277
|
-
|
|
360
|
+
testTraceContext: [async ({ playwrightOpentelemetry }, use, testInfo) => {
|
|
361
|
+
const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
362
|
+
const traceContext = await createTestTraceContext(testInfo);
|
|
363
|
+
await use(traceContext);
|
|
364
|
+
await flushFixtureSpans(traceContext, config, testInfo);
|
|
365
|
+
}, { auto: true }],
|
|
366
|
+
browserPageTracker: [async ({ testTraceContext }, use) => {
|
|
367
|
+
const tracker = new BrowserPageTracker(testTraceContext);
|
|
368
|
+
await use(tracker);
|
|
369
|
+
tracker.finishAll();
|
|
278
370
|
}, { auto: true }],
|
|
279
|
-
context: async ({ context,
|
|
371
|
+
context: async ({ context, testTraceContext, browserPageTracker }, use) => {
|
|
280
372
|
context.route("**", async (route, request) => {
|
|
281
373
|
browserPageTracker.startDocumentNavigation(request);
|
|
374
|
+
const networkParent = browserPageTracker.getNetworkParent(request);
|
|
282
375
|
await fixtureOtelHeaderPropagator({
|
|
283
376
|
route,
|
|
284
377
|
request,
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
378
|
+
traceContext: testTraceContext,
|
|
379
|
+
parentSpanId: networkParent.spanId,
|
|
380
|
+
routeAssociation: networkParent.routeAssociation
|
|
288
381
|
});
|
|
289
382
|
});
|
|
290
383
|
await use(context);
|
|
291
384
|
},
|
|
292
|
-
page: async ({ page,
|
|
385
|
+
page: async ({ page, testTraceContext, browserPageTracker }, use) => {
|
|
293
386
|
browserPageTracker.registerPage(page);
|
|
387
|
+
page.on("close", () => browserPageTracker.unregisterPage(page));
|
|
294
388
|
page.on("framenavigated", (frame) => {
|
|
295
389
|
if (frame === page.mainFrame()) browserPageTracker.handleFrameNavigated(page, frame.url());
|
|
296
390
|
});
|
|
@@ -305,8 +399,7 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
305
399
|
await fixtureCaptureRequestResponse({
|
|
306
400
|
request,
|
|
307
401
|
response,
|
|
308
|
-
|
|
309
|
-
outputDir
|
|
402
|
+
traceContext: testTraceContext
|
|
310
403
|
});
|
|
311
404
|
});
|
|
312
405
|
await use(page);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { n as PlaywrightOpentelemetryUseOptions } from "./config-B9i3jm5s.mjs";
|
|
2
|
+
import { t as Span } from "./otel-B-kvMiiq.mjs";
|
|
3
|
+
import { Page, Request, test } from "@playwright/test";
|
|
4
|
+
|
|
5
|
+
//#region src/fixture/trace-context.d.ts
|
|
6
|
+
interface PlaywrightOtelTraceContextAttachment {
|
|
7
|
+
traceId: string;
|
|
8
|
+
rootSpanId: string;
|
|
9
|
+
}
|
|
10
|
+
interface NetworkRequestTraceContext {
|
|
11
|
+
traceId: string;
|
|
12
|
+
spanId: string;
|
|
13
|
+
parentSpanId: string;
|
|
14
|
+
routeAssociation: "active-route" | "active-page" | "root";
|
|
15
|
+
}
|
|
16
|
+
interface TestTraceContext extends PlaywrightOtelTraceContextAttachment {
|
|
17
|
+
spans: Span[];
|
|
18
|
+
requestContexts: WeakMap<object, NetworkRequestTraceContext>;
|
|
19
|
+
addSpan(span: Span): void;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/fixture/browser-page-tracker.d.ts
|
|
23
|
+
declare class BrowserPageTracker {
|
|
24
|
+
private readonly traceContext;
|
|
25
|
+
private nextPageId;
|
|
26
|
+
private pageStates;
|
|
27
|
+
private pages;
|
|
28
|
+
constructor(traceContext: TestTraceContext);
|
|
29
|
+
registerPage(page: Page): void;
|
|
30
|
+
unregisterPage(page: Page, endTime?: Date): void;
|
|
31
|
+
finishAll(endTime?: Date): void;
|
|
32
|
+
startDocumentNavigation(request: Request): void;
|
|
33
|
+
handleFrameNavigated(page: Page, url: string): void;
|
|
34
|
+
getNetworkParent(request: Request): {
|
|
35
|
+
spanId: string;
|
|
36
|
+
routeAssociation: "active-route" | "active-page" | "root";
|
|
37
|
+
};
|
|
38
|
+
private startDocumentPageSpan;
|
|
39
|
+
private startRouteSpan;
|
|
40
|
+
private finishPageSpans;
|
|
41
|
+
private finishRouteSpan;
|
|
42
|
+
private stateFor;
|
|
43
|
+
private createBrowserSpan;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/fixture/fixture.d.ts
|
|
47
|
+
type TestTraceInfo = {
|
|
48
|
+
testId: string;
|
|
49
|
+
outputDir: string;
|
|
50
|
+
};
|
|
51
|
+
type PlaywrightOpentelemetryFixtures = {
|
|
52
|
+
testTraceInfo: TestTraceInfo;
|
|
53
|
+
testTraceContext: TestTraceContext;
|
|
54
|
+
browserPageTracker: BrowserPageTracker;
|
|
55
|
+
};
|
|
56
|
+
type PlaywrightOpentelemetryWorkerFixtures = {
|
|
57
|
+
_playwrightOpentelemetryReporterCheck: void;
|
|
58
|
+
};
|
|
59
|
+
declare function createPlaywrightOtelTest<T extends typeof test>(testBase: T): import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & PlaywrightOpentelemetryUseOptions & PlaywrightOpentelemetryFixtures, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions & PlaywrightOpentelemetryWorkerFixtures>;
|
|
60
|
+
//#endregion
|
|
61
|
+
export { BrowserPageTracker as n, TestTraceContext as r, createPlaywrightOtelTest as t };
|
package/dist/fixture.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_fixture = require("./fixture-C85kKbWA.cjs");
|
|
3
3
|
let _playwright_test = require("@playwright/test");
|
|
4
4
|
//#region src/fixture/index.ts
|
|
5
|
-
const test =
|
|
5
|
+
const test = require_fixture.createPlaywrightOtelTest(_playwright_test.test);
|
|
6
6
|
//#endregion
|
|
7
|
-
exports.createPlaywrightOtelTest =
|
|
7
|
+
exports.createPlaywrightOtelTest = require_fixture.createPlaywrightOtelTest;
|
|
8
8
|
exports.test = test;
|
|
9
9
|
Object.keys(_playwright_test).forEach(function(k) {
|
|
10
10
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
package/dist/fixture.d.cts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-B9i3jm5s.cjs";
|
|
2
|
+
import { n as BrowserPageTracker, r as TestTraceContext, t as createPlaywrightOtelTest } from "./fixture-1Zc7Gp0b.cjs";
|
|
2
3
|
export * from "@playwright/test";
|
|
3
4
|
|
|
4
5
|
//#region src/fixture/index.d.ts
|
|
5
|
-
declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions
|
|
6
|
+
declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & PlaywrightOpentelemetryUseOptions & {
|
|
7
|
+
testTraceInfo: {
|
|
8
|
+
testId: string;
|
|
9
|
+
outputDir: string;
|
|
10
|
+
};
|
|
11
|
+
testTraceContext: TestTraceContext;
|
|
12
|
+
browserPageTracker: BrowserPageTracker;
|
|
13
|
+
}, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions & {
|
|
14
|
+
_playwrightOpentelemetryReporterCheck: void;
|
|
15
|
+
}>;
|
|
6
16
|
//#endregion
|
|
7
|
-
export { createPlaywrightOtelTest, test };
|
|
17
|
+
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, createPlaywrightOtelTest, test };
|
package/dist/fixture.d.mts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-B9i3jm5s.mjs";
|
|
2
|
+
import { n as BrowserPageTracker, r as TestTraceContext, t as createPlaywrightOtelTest } from "./fixture-IJvYGCtD.mjs";
|
|
2
3
|
export * from "@playwright/test";
|
|
3
4
|
|
|
4
5
|
//#region src/fixture/index.d.ts
|
|
5
|
-
declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions
|
|
6
|
+
declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & PlaywrightOpentelemetryUseOptions & {
|
|
7
|
+
testTraceInfo: {
|
|
8
|
+
testId: string;
|
|
9
|
+
outputDir: string;
|
|
10
|
+
};
|
|
11
|
+
testTraceContext: TestTraceContext;
|
|
12
|
+
browserPageTracker: BrowserPageTracker;
|
|
13
|
+
}, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions & {
|
|
14
|
+
_playwrightOpentelemetryReporterCheck: void;
|
|
15
|
+
}>;
|
|
6
16
|
//#endregion
|
|
7
|
-
export { createPlaywrightOtelTest, test };
|
|
17
|
+
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, createPlaywrightOtelTest, test };
|
package/dist/fixture.mjs
CHANGED
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
|
|
1
|
+
import { n as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-B9i3jm5s.cjs";
|
|
2
|
+
import { t as PlaywrightOpentelemetryReporter } from "./reporter-DaCojFom.cjs";
|
|
3
|
+
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, PlaywrightOpentelemetryReporter as default };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
|
|
1
|
+
import { n as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-B9i3jm5s.mjs";
|
|
2
|
+
import { t as PlaywrightOpentelemetryReporter } from "./reporter-DaCojFom.mjs";
|
|
3
|
+
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, PlaywrightOpentelemetryReporter as default };
|
package/dist/index.mjs
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/shared/otel.d.ts
|
|
2
|
+
type SpanAttributeValue = string | number | boolean | string[];
|
|
3
|
+
type Span = {
|
|
4
|
+
traceId: string;
|
|
5
|
+
spanId: string;
|
|
6
|
+
parentSpanId?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
startTime: Date;
|
|
9
|
+
endTime: Date;
|
|
10
|
+
attributes: Record<string, SpanAttributeValue>;
|
|
11
|
+
status: {
|
|
12
|
+
code: number;
|
|
13
|
+
};
|
|
14
|
+
kind?: number; /** Service name for this span (if different from default). */
|
|
15
|
+
serviceName?: string;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { Span as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/shared/otel.d.ts
|
|
2
|
+
type SpanAttributeValue = string | number | boolean | string[];
|
|
3
|
+
type Span = {
|
|
4
|
+
traceId: string;
|
|
5
|
+
spanId: string;
|
|
6
|
+
parentSpanId?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
startTime: Date;
|
|
9
|
+
endTime: Date;
|
|
10
|
+
attributes: Record<string, SpanAttributeValue>;
|
|
11
|
+
status: {
|
|
12
|
+
code: number;
|
|
13
|
+
};
|
|
14
|
+
kind?: number; /** Service name for this span (if different from default). */
|
|
15
|
+
serviceName?: string;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { Span as t };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FullConfig, FullResult, Reporter, Suite, TestCase, TestResult, TestStep } from "@playwright/test/reporter";
|
|
2
|
+
|
|
3
|
+
//#region src/reporter/reporter.d.ts
|
|
4
|
+
declare class PlaywrightOpentelemetryReporter implements Reporter {
|
|
5
|
+
private spanBatches;
|
|
6
|
+
private pendingTraceArtifacts;
|
|
7
|
+
private rootDir?;
|
|
8
|
+
private playwrightVersion?;
|
|
9
|
+
private debug;
|
|
10
|
+
constructor();
|
|
11
|
+
onBegin(config: FullConfig, _suite: Suite): void;
|
|
12
|
+
onTestBegin(_test: TestCase, _result: TestResult): void;
|
|
13
|
+
onStepBegin(_test: TestCase, _result: TestResult, _step: TestStep): void;
|
|
14
|
+
onStepEnd(_test: TestCase, _result: TestResult, _step: TestStep): void;
|
|
15
|
+
onTestEnd(test: TestCase, result: TestResult): void;
|
|
16
|
+
onEnd(_result: FullResult): Promise<void>;
|
|
17
|
+
private prepareTraceArtifact;
|
|
18
|
+
private processTestStep;
|
|
19
|
+
onStdOut(chunk: string | Buffer, _test: TestCase, _result: TestResult): void;
|
|
20
|
+
onStdErr(chunk: string | Buffer, _test: TestCase, _result: TestResult): void;
|
|
21
|
+
printsToStdio(): boolean;
|
|
22
|
+
private sendScreenshotsZipToTraceApi;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { PlaywrightOpentelemetryReporter as t };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FullConfig, FullResult, Reporter, Suite, TestCase, TestResult, TestStep } from "@playwright/test/reporter";
|
|
2
|
+
|
|
3
|
+
//#region src/reporter/reporter.d.ts
|
|
4
|
+
declare class PlaywrightOpentelemetryReporter implements Reporter {
|
|
5
|
+
private spanBatches;
|
|
6
|
+
private pendingTraceArtifacts;
|
|
7
|
+
private rootDir?;
|
|
8
|
+
private playwrightVersion?;
|
|
9
|
+
private debug;
|
|
10
|
+
constructor();
|
|
11
|
+
onBegin(config: FullConfig, _suite: Suite): void;
|
|
12
|
+
onTestBegin(_test: TestCase, _result: TestResult): void;
|
|
13
|
+
onStepBegin(_test: TestCase, _result: TestResult, _step: TestStep): void;
|
|
14
|
+
onStepEnd(_test: TestCase, _result: TestResult, _step: TestStep): void;
|
|
15
|
+
onTestEnd(test: TestCase, result: TestResult): void;
|
|
16
|
+
onEnd(_result: FullResult): Promise<void>;
|
|
17
|
+
private prepareTraceArtifact;
|
|
18
|
+
private processTestStep;
|
|
19
|
+
onStdOut(chunk: string | Buffer, _test: TestCase, _result: TestResult): void;
|
|
20
|
+
onStdErr(chunk: string | Buffer, _test: TestCase, _result: TestResult): void;
|
|
21
|
+
printsToStdio(): boolean;
|
|
22
|
+
private sendScreenshotsZipToTraceApi;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { PlaywrightOpentelemetryReporter as t };
|