playwright-opentelemetry 0.6.1 → 0.7.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/{trace-context-Cck0LEoL.mjs → config-B9rx_m23.mjs} +65 -33
- package/dist/{trace-context-Dd2Fmx9q.cjs → config-C8VVYvBv.cjs} +70 -32
- package/dist/config-Db932l_s.d.cts +27 -0
- package/dist/config-Db932l_s.d.mts +27 -0
- package/dist/fixture/factory.cjs +2 -2
- package/dist/fixture/factory.d.cts +1 -1
- package/dist/fixture/factory.d.mts +1 -1
- package/dist/fixture/factory.mjs +1 -1
- package/dist/fixture.cjs +3 -3
- package/dist/fixture.d.cts +3 -3
- package/dist/fixture.d.mts +3 -3
- package/dist/fixture.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/{otel-B-kvMiiq.d.cts → otel-D0ztpic2.d.cts} +9 -2
- package/dist/{otel-B-kvMiiq.d.mts → otel-D0ztpic2.d.mts} +9 -2
- package/dist/{fixture-KBHTI5WC.cjs → playwright-opentelemetry-fixture-CGLwOCBm.cjs} +91 -18
- package/dist/{fixture-C3xMi3bo.mjs → playwright-opentelemetry-fixture-DABcsfrU.mjs} +86 -13
- package/dist/{fixture-IJvYGCtD.d.mts → playwright-opentelemetry-fixture-Dx53ybJd.d.cts} +12 -6
- package/dist/{fixture-1Zc7Gp0b.d.cts → playwright-opentelemetry-fixture-xHcfAc5d.d.mts} +12 -6
- package/dist/{reporter-D-ONZUZE.mjs → reporter-CtflXoLs.mjs} +57 -21
- package/dist/{reporter-pVDPoXTx.cjs → reporter-D4iIeblG.cjs} +72 -36
- package/dist/reporter.cjs +1 -1
- package/dist/reporter.mjs +1 -1
- package/package.json +1 -1
- package/dist/config-B9i3jm5s.d.cts +0 -15
- package/dist/config-B9i3jm5s.d.mts +0 -15
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_config = require("./config-C8VVYvBv.cjs");
|
|
2
2
|
let node_path = require("node:path");
|
|
3
|
-
node_path =
|
|
3
|
+
node_path = require_config.__toESM(node_path, 1);
|
|
4
4
|
//#region src/fixture/browser-page-tracker.ts
|
|
5
5
|
const BROWSER_PAGE_SPAN_NAME = "browser.page";
|
|
6
6
|
const BROWSER_ROUTE_SPAN_NAME = "browser.route";
|
|
@@ -60,6 +60,38 @@ var BrowserPageTracker = class {
|
|
|
60
60
|
routeAssociation: "root"
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
+
recordConsoleMessage(page, message, time = /* @__PURE__ */ new Date()) {
|
|
64
|
+
const activeSpan = this.getActiveBrowserSpan(page);
|
|
65
|
+
if (!activeSpan) return;
|
|
66
|
+
const type = message.type();
|
|
67
|
+
const attributes = {
|
|
68
|
+
message: message.text(),
|
|
69
|
+
"browser.console.type": type,
|
|
70
|
+
"severity.text": consoleSeverityText(type)
|
|
71
|
+
};
|
|
72
|
+
const location = message.location();
|
|
73
|
+
if (location.url) attributes["code.file.path"] = location.url;
|
|
74
|
+
const line = consoleLocationLine(location);
|
|
75
|
+
if (line !== void 0) attributes["code.line.number"] = line + 1;
|
|
76
|
+
activeSpan.events.push({
|
|
77
|
+
name: "log",
|
|
78
|
+
time,
|
|
79
|
+
attributes
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
recordPageError(page, error, time = /* @__PURE__ */ new Date()) {
|
|
83
|
+
const activeSpan = this.getActiveBrowserSpan(page);
|
|
84
|
+
if (!activeSpan) return;
|
|
85
|
+
const attributes = {};
|
|
86
|
+
if (error.name) attributes["exception.type"] = error.name;
|
|
87
|
+
if (error.message) attributes["exception.message"] = error.message;
|
|
88
|
+
if (error.stack) attributes["exception.stacktrace"] = error.stack;
|
|
89
|
+
activeSpan.events.push({
|
|
90
|
+
name: "exception",
|
|
91
|
+
time,
|
|
92
|
+
attributes
|
|
93
|
+
});
|
|
94
|
+
}
|
|
63
95
|
startDocumentPageSpan(page, url, startTime) {
|
|
64
96
|
const state = this.stateFor(page);
|
|
65
97
|
this.finishPageSpans(page, startTime);
|
|
@@ -113,6 +145,10 @@ var BrowserPageTracker = class {
|
|
|
113
145
|
state.activeRouteSpan = void 0;
|
|
114
146
|
}
|
|
115
147
|
}
|
|
148
|
+
getActiveBrowserSpan(page) {
|
|
149
|
+
const state = this.pageStates.get(page);
|
|
150
|
+
return state?.activeRouteSpan?.span ?? state?.activeDocumentSpan?.span;
|
|
151
|
+
}
|
|
116
152
|
stateFor(page) {
|
|
117
153
|
const existing = this.pageStates.get(page);
|
|
118
154
|
if (existing) return existing;
|
|
@@ -126,7 +162,7 @@ var BrowserPageTracker = class {
|
|
|
126
162
|
createBrowserSpan({ pageId, name, url, navigationType, parentSpanId, startTime, previousUrl, documentUrl }) {
|
|
127
163
|
return {
|
|
128
164
|
traceId: this.traceContext.traceId,
|
|
129
|
-
spanId:
|
|
165
|
+
spanId: require_config.generateSpanId(),
|
|
130
166
|
parentSpanId,
|
|
131
167
|
name,
|
|
132
168
|
startTime,
|
|
@@ -139,10 +175,24 @@ var BrowserPageTracker = class {
|
|
|
139
175
|
previousUrl,
|
|
140
176
|
documentUrl
|
|
141
177
|
}),
|
|
178
|
+
events: [],
|
|
142
179
|
serviceName: BROWSER_SERVICE_NAME
|
|
143
180
|
};
|
|
144
181
|
}
|
|
145
182
|
};
|
|
183
|
+
function consoleSeverityText(type) {
|
|
184
|
+
switch (type) {
|
|
185
|
+
case "debug": return "DEBUG";
|
|
186
|
+
case "warning": return "WARN";
|
|
187
|
+
case "error":
|
|
188
|
+
case "assert": return "ERROR";
|
|
189
|
+
case "trace": return "TRACE";
|
|
190
|
+
default: return "INFO";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function consoleLocationLine(location) {
|
|
194
|
+
return location.line ?? location.lineNumber;
|
|
195
|
+
}
|
|
146
196
|
function pageAttributes({ pageId, url, navigationType, previousUrl, documentUrl }) {
|
|
147
197
|
const attributes = {
|
|
148
198
|
"browser.resource.type": navigationType === "document" ? "page" : "route",
|
|
@@ -190,19 +240,22 @@ function shouldCreateSameDocumentPageSpan(previousUrl, nextUrl, activePageUrl) {
|
|
|
190
240
|
}
|
|
191
241
|
//#endregion
|
|
192
242
|
//#region src/fixture/network-propagator.ts
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
* @param options - The propagator options
|
|
196
|
-
*/
|
|
197
|
-
async function fixtureOtelHeaderPropagator({ route, request, traceContext, parentSpanId, routeAssociation }) {
|
|
198
|
-
const spanId = require_trace_context.generateSpanId();
|
|
199
|
-
const traceHeader = `00-${traceContext.traceId}-${spanId}-01`;
|
|
243
|
+
function storeRequestTraceContext({ request, traceContext, parentSpanId, routeAssociation }) {
|
|
244
|
+
const spanId = require_config.generateSpanId();
|
|
200
245
|
traceContext.requestContexts.set(request, {
|
|
201
246
|
traceId: traceContext.traceId,
|
|
202
247
|
spanId,
|
|
203
248
|
parentSpanId,
|
|
204
249
|
routeAssociation
|
|
205
250
|
});
|
|
251
|
+
return spanId;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Intercepts network requests to propagate trace context via traceparent header.
|
|
255
|
+
* @param options - The propagator options
|
|
256
|
+
*/
|
|
257
|
+
async function propagateRouteTraceHeaders({ route, request, traceId, spanId }) {
|
|
258
|
+
const traceHeader = `00-${traceId}-${spanId}-01`;
|
|
206
259
|
await route.fallback({ headers: {
|
|
207
260
|
...request.headers(),
|
|
208
261
|
traceparent: traceHeader
|
|
@@ -328,6 +381,7 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
|
|
|
328
381
|
endTime,
|
|
329
382
|
status: { code: statusCodeValue },
|
|
330
383
|
attributes,
|
|
384
|
+
events: [],
|
|
331
385
|
serviceName: "playwright-browser"
|
|
332
386
|
};
|
|
333
387
|
traceContext.addSpan(networkSpan);
|
|
@@ -340,7 +394,7 @@ async function getResponseHeaderValue(response, name) {
|
|
|
340
394
|
}
|
|
341
395
|
}
|
|
342
396
|
//#endregion
|
|
343
|
-
//#region src/fixture/fixture.ts
|
|
397
|
+
//#region src/fixture/playwright-opentelemetry-fixture.ts
|
|
344
398
|
function createPlaywrightOtelTest(testBase) {
|
|
345
399
|
return testBase.extend({
|
|
346
400
|
playwrightOpentelemetry: [void 0, { option: true }],
|
|
@@ -358,34 +412,53 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
358
412
|
outputDir
|
|
359
413
|
});
|
|
360
414
|
}, { auto: true }],
|
|
361
|
-
testTraceContext: [async ({ playwrightOpentelemetry }, use, testInfo) => {
|
|
362
|
-
const config =
|
|
363
|
-
const traceContext = await
|
|
415
|
+
testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
|
|
416
|
+
const config = require_config.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
417
|
+
const traceContext = await require_config.createTestTraceContext(testInfo);
|
|
364
418
|
await use(traceContext);
|
|
365
|
-
await
|
|
419
|
+
await require_config.flushFixtureSpans(traceContext, config, {
|
|
420
|
+
trace: config.trace ?? trace,
|
|
421
|
+
testInfo
|
|
422
|
+
});
|
|
366
423
|
}, { auto: true }],
|
|
367
424
|
browserPageTracker: [async ({ testTraceContext }, use) => {
|
|
368
425
|
const tracker = new BrowserPageTracker(testTraceContext);
|
|
369
426
|
await use(tracker);
|
|
370
427
|
tracker.finishAll();
|
|
371
428
|
}, { auto: true }],
|
|
372
|
-
context: async ({ context, testTraceContext, browserPageTracker }, use) => {
|
|
429
|
+
context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker }, use) => {
|
|
430
|
+
const config = require_config.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
373
431
|
context.route("**", async (route, request) => {
|
|
374
432
|
browserPageTracker.startDocumentNavigation(request);
|
|
375
433
|
const networkParent = browserPageTracker.getNetworkParent(request);
|
|
376
|
-
|
|
377
|
-
route,
|
|
434
|
+
const spanId = storeRequestTraceContext({
|
|
378
435
|
request,
|
|
379
436
|
traceContext: testTraceContext,
|
|
380
437
|
parentSpanId: networkParent.spanId,
|
|
381
438
|
routeAssociation: networkParent.routeAssociation
|
|
382
439
|
});
|
|
440
|
+
if (config.propagateTraceHeaders) {
|
|
441
|
+
await propagateRouteTraceHeaders({
|
|
442
|
+
route,
|
|
443
|
+
request,
|
|
444
|
+
traceId: testTraceContext.traceId,
|
|
445
|
+
spanId
|
|
446
|
+
});
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
await route.fallback();
|
|
383
450
|
});
|
|
384
451
|
await use(context);
|
|
385
452
|
},
|
|
386
453
|
page: async ({ page, testTraceContext, browserPageTracker }, use) => {
|
|
387
454
|
browserPageTracker.registerPage(page);
|
|
388
455
|
page.on("close", () => browserPageTracker.unregisterPage(page));
|
|
456
|
+
page.on("console", (message) => {
|
|
457
|
+
browserPageTracker.recordConsoleMessage(page, message);
|
|
458
|
+
});
|
|
459
|
+
page.on("pageerror", (error) => {
|
|
460
|
+
browserPageTracker.recordPageError(page, error);
|
|
461
|
+
});
|
|
389
462
|
page.on("framenavigated", (frame) => {
|
|
390
463
|
if (frame === page.mainFrame()) browserPageTracker.handleFrameNavigated(page, frame.url());
|
|
391
464
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as flushFixtureSpans, c as generateSpanId, i as createTestTraceContext, t as resolvePlaywrightOpentelemetryConfig } from "./config-B9rx_m23.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";
|
|
@@ -59,6 +59,38 @@ var BrowserPageTracker = class {
|
|
|
59
59
|
routeAssociation: "root"
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
+
recordConsoleMessage(page, message, time = /* @__PURE__ */ new Date()) {
|
|
63
|
+
const activeSpan = this.getActiveBrowserSpan(page);
|
|
64
|
+
if (!activeSpan) return;
|
|
65
|
+
const type = message.type();
|
|
66
|
+
const attributes = {
|
|
67
|
+
message: message.text(),
|
|
68
|
+
"browser.console.type": type,
|
|
69
|
+
"severity.text": consoleSeverityText(type)
|
|
70
|
+
};
|
|
71
|
+
const location = message.location();
|
|
72
|
+
if (location.url) attributes["code.file.path"] = location.url;
|
|
73
|
+
const line = consoleLocationLine(location);
|
|
74
|
+
if (line !== void 0) attributes["code.line.number"] = line + 1;
|
|
75
|
+
activeSpan.events.push({
|
|
76
|
+
name: "log",
|
|
77
|
+
time,
|
|
78
|
+
attributes
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
recordPageError(page, error, time = /* @__PURE__ */ new Date()) {
|
|
82
|
+
const activeSpan = this.getActiveBrowserSpan(page);
|
|
83
|
+
if (!activeSpan) return;
|
|
84
|
+
const attributes = {};
|
|
85
|
+
if (error.name) attributes["exception.type"] = error.name;
|
|
86
|
+
if (error.message) attributes["exception.message"] = error.message;
|
|
87
|
+
if (error.stack) attributes["exception.stacktrace"] = error.stack;
|
|
88
|
+
activeSpan.events.push({
|
|
89
|
+
name: "exception",
|
|
90
|
+
time,
|
|
91
|
+
attributes
|
|
92
|
+
});
|
|
93
|
+
}
|
|
62
94
|
startDocumentPageSpan(page, url, startTime) {
|
|
63
95
|
const state = this.stateFor(page);
|
|
64
96
|
this.finishPageSpans(page, startTime);
|
|
@@ -112,6 +144,10 @@ var BrowserPageTracker = class {
|
|
|
112
144
|
state.activeRouteSpan = void 0;
|
|
113
145
|
}
|
|
114
146
|
}
|
|
147
|
+
getActiveBrowserSpan(page) {
|
|
148
|
+
const state = this.pageStates.get(page);
|
|
149
|
+
return state?.activeRouteSpan?.span ?? state?.activeDocumentSpan?.span;
|
|
150
|
+
}
|
|
115
151
|
stateFor(page) {
|
|
116
152
|
const existing = this.pageStates.get(page);
|
|
117
153
|
if (existing) return existing;
|
|
@@ -138,10 +174,24 @@ var BrowserPageTracker = class {
|
|
|
138
174
|
previousUrl,
|
|
139
175
|
documentUrl
|
|
140
176
|
}),
|
|
177
|
+
events: [],
|
|
141
178
|
serviceName: BROWSER_SERVICE_NAME
|
|
142
179
|
};
|
|
143
180
|
}
|
|
144
181
|
};
|
|
182
|
+
function consoleSeverityText(type) {
|
|
183
|
+
switch (type) {
|
|
184
|
+
case "debug": return "DEBUG";
|
|
185
|
+
case "warning": return "WARN";
|
|
186
|
+
case "error":
|
|
187
|
+
case "assert": return "ERROR";
|
|
188
|
+
case "trace": return "TRACE";
|
|
189
|
+
default: return "INFO";
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function consoleLocationLine(location) {
|
|
193
|
+
return location.line ?? location.lineNumber;
|
|
194
|
+
}
|
|
145
195
|
function pageAttributes({ pageId, url, navigationType, previousUrl, documentUrl }) {
|
|
146
196
|
const attributes = {
|
|
147
197
|
"browser.resource.type": navigationType === "document" ? "page" : "route",
|
|
@@ -189,19 +239,22 @@ function shouldCreateSameDocumentPageSpan(previousUrl, nextUrl, activePageUrl) {
|
|
|
189
239
|
}
|
|
190
240
|
//#endregion
|
|
191
241
|
//#region src/fixture/network-propagator.ts
|
|
192
|
-
|
|
193
|
-
* Intercepts network requests to propagate trace context via traceparent header.
|
|
194
|
-
* @param options - The propagator options
|
|
195
|
-
*/
|
|
196
|
-
async function fixtureOtelHeaderPropagator({ route, request, traceContext, parentSpanId, routeAssociation }) {
|
|
242
|
+
function storeRequestTraceContext({ request, traceContext, parentSpanId, routeAssociation }) {
|
|
197
243
|
const spanId = generateSpanId();
|
|
198
|
-
const traceHeader = `00-${traceContext.traceId}-${spanId}-01`;
|
|
199
244
|
traceContext.requestContexts.set(request, {
|
|
200
245
|
traceId: traceContext.traceId,
|
|
201
246
|
spanId,
|
|
202
247
|
parentSpanId,
|
|
203
248
|
routeAssociation
|
|
204
249
|
});
|
|
250
|
+
return spanId;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Intercepts network requests to propagate trace context via traceparent header.
|
|
254
|
+
* @param options - The propagator options
|
|
255
|
+
*/
|
|
256
|
+
async function propagateRouteTraceHeaders({ route, request, traceId, spanId }) {
|
|
257
|
+
const traceHeader = `00-${traceId}-${spanId}-01`;
|
|
205
258
|
await route.fallback({ headers: {
|
|
206
259
|
...request.headers(),
|
|
207
260
|
traceparent: traceHeader
|
|
@@ -327,6 +380,7 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
|
|
|
327
380
|
endTime,
|
|
328
381
|
status: { code: statusCodeValue },
|
|
329
382
|
attributes,
|
|
383
|
+
events: [],
|
|
330
384
|
serviceName: "playwright-browser"
|
|
331
385
|
};
|
|
332
386
|
traceContext.addSpan(networkSpan);
|
|
@@ -339,7 +393,7 @@ async function getResponseHeaderValue(response, name) {
|
|
|
339
393
|
}
|
|
340
394
|
}
|
|
341
395
|
//#endregion
|
|
342
|
-
//#region src/fixture/fixture.ts
|
|
396
|
+
//#region src/fixture/playwright-opentelemetry-fixture.ts
|
|
343
397
|
function createPlaywrightOtelTest(testBase) {
|
|
344
398
|
return testBase.extend({
|
|
345
399
|
playwrightOpentelemetry: [void 0, { option: true }],
|
|
@@ -357,34 +411,53 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
357
411
|
outputDir
|
|
358
412
|
});
|
|
359
413
|
}, { auto: true }],
|
|
360
|
-
testTraceContext: [async ({ playwrightOpentelemetry }, use, testInfo) => {
|
|
414
|
+
testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
|
|
361
415
|
const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
362
416
|
const traceContext = await createTestTraceContext(testInfo);
|
|
363
417
|
await use(traceContext);
|
|
364
|
-
await flushFixtureSpans(traceContext, config,
|
|
418
|
+
await flushFixtureSpans(traceContext, config, {
|
|
419
|
+
trace: config.trace ?? trace,
|
|
420
|
+
testInfo
|
|
421
|
+
});
|
|
365
422
|
}, { auto: true }],
|
|
366
423
|
browserPageTracker: [async ({ testTraceContext }, use) => {
|
|
367
424
|
const tracker = new BrowserPageTracker(testTraceContext);
|
|
368
425
|
await use(tracker);
|
|
369
426
|
tracker.finishAll();
|
|
370
427
|
}, { auto: true }],
|
|
371
|
-
context: async ({ context, testTraceContext, browserPageTracker }, use) => {
|
|
428
|
+
context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker }, use) => {
|
|
429
|
+
const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
372
430
|
context.route("**", async (route, request) => {
|
|
373
431
|
browserPageTracker.startDocumentNavigation(request);
|
|
374
432
|
const networkParent = browserPageTracker.getNetworkParent(request);
|
|
375
|
-
|
|
376
|
-
route,
|
|
433
|
+
const spanId = storeRequestTraceContext({
|
|
377
434
|
request,
|
|
378
435
|
traceContext: testTraceContext,
|
|
379
436
|
parentSpanId: networkParent.spanId,
|
|
380
437
|
routeAssociation: networkParent.routeAssociation
|
|
381
438
|
});
|
|
439
|
+
if (config.propagateTraceHeaders) {
|
|
440
|
+
await propagateRouteTraceHeaders({
|
|
441
|
+
route,
|
|
442
|
+
request,
|
|
443
|
+
traceId: testTraceContext.traceId,
|
|
444
|
+
spanId
|
|
445
|
+
});
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
await route.fallback();
|
|
382
449
|
});
|
|
383
450
|
await use(context);
|
|
384
451
|
},
|
|
385
452
|
page: async ({ page, testTraceContext, browserPageTracker }, use) => {
|
|
386
453
|
browserPageTracker.registerPage(page);
|
|
387
454
|
page.on("close", () => browserPageTracker.unregisterPage(page));
|
|
455
|
+
page.on("console", (message) => {
|
|
456
|
+
browserPageTracker.recordConsoleMessage(page, message);
|
|
457
|
+
});
|
|
458
|
+
page.on("pageerror", (error) => {
|
|
459
|
+
browserPageTracker.recordPageError(page, error);
|
|
460
|
+
});
|
|
388
461
|
page.on("framenavigated", (frame) => {
|
|
389
462
|
if (frame === page.mainFrame()) browserPageTracker.handleFrameNavigated(page, frame.url());
|
|
390
463
|
});
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { n as PlaywrightOpentelemetryUseOptions } from "./config-
|
|
2
|
-
import { t as Span } from "./otel-
|
|
3
|
-
import { Page, Request, test } from "@playwright/test";
|
|
1
|
+
import { n as PlaywrightOpentelemetryUseOptions } from "./config-Db932l_s.cjs";
|
|
2
|
+
import { n as SpanEvent, t as Span } from "./otel-D0ztpic2.cjs";
|
|
3
|
+
import { ConsoleMessage, Page, Request, test } from "@playwright/test";
|
|
4
4
|
|
|
5
5
|
//#region src/fixture/trace-context.d.ts
|
|
6
6
|
interface PlaywrightOtelTraceContextAttachment {
|
|
7
7
|
traceId: string;
|
|
8
8
|
rootSpanId: string;
|
|
9
9
|
}
|
|
10
|
+
type FixtureSpan = Omit<Span, "events"> & {
|
|
11
|
+
events: SpanEvent[];
|
|
12
|
+
};
|
|
10
13
|
interface NetworkRequestTraceContext {
|
|
11
14
|
traceId: string;
|
|
12
15
|
spanId: string;
|
|
@@ -14,9 +17,9 @@ interface NetworkRequestTraceContext {
|
|
|
14
17
|
routeAssociation: "active-route" | "active-page" | "root";
|
|
15
18
|
}
|
|
16
19
|
interface TestTraceContext extends PlaywrightOtelTraceContextAttachment {
|
|
17
|
-
spans:
|
|
20
|
+
spans: FixtureSpan[];
|
|
18
21
|
requestContexts: WeakMap<object, NetworkRequestTraceContext>;
|
|
19
|
-
addSpan(span:
|
|
22
|
+
addSpan(span: FixtureSpan): void;
|
|
20
23
|
}
|
|
21
24
|
//#endregion
|
|
22
25
|
//#region src/fixture/browser-page-tracker.d.ts
|
|
@@ -35,15 +38,18 @@ declare class BrowserPageTracker {
|
|
|
35
38
|
spanId: string;
|
|
36
39
|
routeAssociation: "active-route" | "active-page" | "root";
|
|
37
40
|
};
|
|
41
|
+
recordConsoleMessage(page: Page, message: ConsoleMessage, time?: Date): void;
|
|
42
|
+
recordPageError(page: Page, error: Error, time?: Date): void;
|
|
38
43
|
private startDocumentPageSpan;
|
|
39
44
|
private startRouteSpan;
|
|
40
45
|
private finishPageSpans;
|
|
41
46
|
private finishRouteSpan;
|
|
47
|
+
private getActiveBrowserSpan;
|
|
42
48
|
private stateFor;
|
|
43
49
|
private createBrowserSpan;
|
|
44
50
|
}
|
|
45
51
|
//#endregion
|
|
46
|
-
//#region src/fixture/fixture.d.ts
|
|
52
|
+
//#region src/fixture/playwright-opentelemetry-fixture.d.ts
|
|
47
53
|
type TestTraceInfo = {
|
|
48
54
|
testId: string;
|
|
49
55
|
outputDir: string;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { n as PlaywrightOpentelemetryUseOptions } from "./config-
|
|
2
|
-
import { t as Span } from "./otel-
|
|
3
|
-
import { Page, Request, test } from "@playwright/test";
|
|
1
|
+
import { n as PlaywrightOpentelemetryUseOptions } from "./config-Db932l_s.mjs";
|
|
2
|
+
import { n as SpanEvent, t as Span } from "./otel-D0ztpic2.mjs";
|
|
3
|
+
import { ConsoleMessage, Page, Request, test } from "@playwright/test";
|
|
4
4
|
|
|
5
5
|
//#region src/fixture/trace-context.d.ts
|
|
6
6
|
interface PlaywrightOtelTraceContextAttachment {
|
|
7
7
|
traceId: string;
|
|
8
8
|
rootSpanId: string;
|
|
9
9
|
}
|
|
10
|
+
type FixtureSpan = Omit<Span, "events"> & {
|
|
11
|
+
events: SpanEvent[];
|
|
12
|
+
};
|
|
10
13
|
interface NetworkRequestTraceContext {
|
|
11
14
|
traceId: string;
|
|
12
15
|
spanId: string;
|
|
@@ -14,9 +17,9 @@ interface NetworkRequestTraceContext {
|
|
|
14
17
|
routeAssociation: "active-route" | "active-page" | "root";
|
|
15
18
|
}
|
|
16
19
|
interface TestTraceContext extends PlaywrightOtelTraceContextAttachment {
|
|
17
|
-
spans:
|
|
20
|
+
spans: FixtureSpan[];
|
|
18
21
|
requestContexts: WeakMap<object, NetworkRequestTraceContext>;
|
|
19
|
-
addSpan(span:
|
|
22
|
+
addSpan(span: FixtureSpan): void;
|
|
20
23
|
}
|
|
21
24
|
//#endregion
|
|
22
25
|
//#region src/fixture/browser-page-tracker.d.ts
|
|
@@ -35,15 +38,18 @@ declare class BrowserPageTracker {
|
|
|
35
38
|
spanId: string;
|
|
36
39
|
routeAssociation: "active-route" | "active-page" | "root";
|
|
37
40
|
};
|
|
41
|
+
recordConsoleMessage(page: Page, message: ConsoleMessage, time?: Date): void;
|
|
42
|
+
recordPageError(page: Page, error: Error, time?: Date): void;
|
|
38
43
|
private startDocumentPageSpan;
|
|
39
44
|
private startRouteSpan;
|
|
40
45
|
private finishPageSpans;
|
|
41
46
|
private finishRouteSpan;
|
|
47
|
+
private getActiveBrowserSpan;
|
|
42
48
|
private stateFor;
|
|
43
49
|
private createBrowserSpan;
|
|
44
50
|
}
|
|
45
51
|
//#endregion
|
|
46
|
-
//#region src/fixture/fixture.d.ts
|
|
52
|
+
//#region src/fixture/playwright-opentelemetry-fixture.d.ts
|
|
47
53
|
type TestTraceInfo = {
|
|
48
54
|
testId: string;
|
|
49
55
|
outputDir: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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-B9rx_m23.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import { BlobReader, BlobWriter, ZipReader, ZipWriter } from "@zip.js/zip.js";
|
|
@@ -142,11 +142,16 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
142
142
|
onStepBegin(_test, _result, _step) {}
|
|
143
143
|
onStepEnd(_test, _result, _step) {}
|
|
144
144
|
onTestEnd(test, result) {
|
|
145
|
-
const testId = test.id;
|
|
146
|
-
const outputDir = getTestOutputDir(test);
|
|
147
145
|
const config = getTestConfig(test);
|
|
148
|
-
const { traceId, rootSpanId: testSpanId } = readTraceContextAttachment(result, testId, config.storeTraceZip);
|
|
149
146
|
const traceAttachment = result.attachments.find((attachment) => attachment.name === "trace" && attachment.contentType === "application/zip" && attachment.path);
|
|
147
|
+
if (!(config.trace === null ? Boolean(traceAttachment) : shouldRetainPlaywrightTrace(config.trace, {
|
|
148
|
+
expectedStatus: test.expectedStatus,
|
|
149
|
+
retry: result.retry,
|
|
150
|
+
status: result.status
|
|
151
|
+
}))) return;
|
|
152
|
+
const testId = test.id;
|
|
153
|
+
const outputDir = getTestOutputDir(test);
|
|
154
|
+
const { traceId, rootSpanId: testSpanId } = readTraceContextAttachment(result, testId);
|
|
150
155
|
const fixtureSpans = config.storeTraceZip ? readFixtureSpansAttachment(result, testId) : [];
|
|
151
156
|
result.attachments.push({
|
|
152
157
|
name: "playwright-opentelemetry-trace-id",
|
|
@@ -176,15 +181,16 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
176
181
|
if (stepSpan.startTime < minStartTime) minStartTime = stepSpan.startTime;
|
|
177
182
|
if (stepSpan.endTime > maxEndTime) maxEndTime = stepSpan.endTime;
|
|
178
183
|
}
|
|
179
|
-
const
|
|
184
|
+
const span = {
|
|
180
185
|
traceId,
|
|
181
186
|
spanId: testSpanId,
|
|
182
187
|
name: TEST_SPAN_NAME,
|
|
183
188
|
startTime: minStartTime,
|
|
184
189
|
endTime: maxEndTime,
|
|
185
|
-
attributes
|
|
186
|
-
|
|
187
|
-
}
|
|
190
|
+
attributes
|
|
191
|
+
};
|
|
192
|
+
if (result.status !== test.expectedStatus) span.status = { code: 2 };
|
|
193
|
+
const testSpans = [span, ...stepSpans];
|
|
188
194
|
this.spanBatches.push({
|
|
189
195
|
spans: testSpans,
|
|
190
196
|
config
|
|
@@ -250,9 +256,8 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
250
256
|
return { traceZipBlob };
|
|
251
257
|
}
|
|
252
258
|
processTestStep(test, step, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds) {
|
|
253
|
-
const isInternalFixture = step.category === "fixture" && step.location?.file.includes("playwright-opentelemetry") && (step.location?.file.endsWith("fixture.mjs") || step.location?.file.endsWith("fixture/index.ts"));
|
|
254
259
|
const stepId = getStepId(test, step);
|
|
255
|
-
if (
|
|
260
|
+
if (isInternalFixtureStep(step)) {
|
|
256
261
|
skippedStepIds.add(stepId);
|
|
257
262
|
processedSteps.delete(stepId);
|
|
258
263
|
if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds);
|
|
@@ -265,6 +270,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
265
270
|
const currentTitlePath = [...parentTitlePath, step.title];
|
|
266
271
|
const existingSpan = processedSteps.get(stepId);
|
|
267
272
|
if (existingSpan) {
|
|
273
|
+
if (step.error) existingSpan.status = errorStatus(step.error.message);
|
|
268
274
|
if (step.location && !existingSpan.attributes["code.file.path"]) {
|
|
269
275
|
const { file, line } = step.location;
|
|
270
276
|
const relativePath = this.rootDir ? path.relative(this.rootDir, file) : file;
|
|
@@ -290,9 +296,9 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
290
296
|
name: TEST_STEP_SPAN_NAME,
|
|
291
297
|
startTime: step.startTime,
|
|
292
298
|
endTime: new Date(step.startTime.getTime() + step.duration),
|
|
293
|
-
attributes
|
|
294
|
-
status: { code: step.error ? 2 : 1 }
|
|
299
|
+
attributes
|
|
295
300
|
};
|
|
301
|
+
if (step.error) stepSpan.status = errorStatus(step.error.message);
|
|
296
302
|
processedSteps.set(stepId, stepSpan);
|
|
297
303
|
if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, stepSpan.spanId, traceId, currentTitlePath, processedSteps, skippedStepIds);
|
|
298
304
|
}
|
|
@@ -347,15 +353,12 @@ function addDestinationSpans(destinations, spans, options) {
|
|
|
347
353
|
options
|
|
348
354
|
});
|
|
349
355
|
}
|
|
350
|
-
function readTraceContextAttachment(result, testId
|
|
356
|
+
function readTraceContextAttachment(result, testId) {
|
|
351
357
|
const attachment = result.attachments.find((attachment) => attachment.name === TRACE_CONTEXT_ATTACHMENT_NAME);
|
|
352
|
-
if (!attachment?.body) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
};
|
|
357
|
-
throw new Error(`playwright-opentelemetry fixture missing for test ${testId}: expected ${TRACE_CONTEXT_ATTACHMENT_NAME} attachment. Import test from "playwright-opentelemetry/fixture" or wrap your base test with createPlaywrightOtelTest().`);
|
|
358
|
-
}
|
|
358
|
+
if (!attachment?.body) return {
|
|
359
|
+
traceId: generateTraceId(),
|
|
360
|
+
rootSpanId: generateSpanId()
|
|
361
|
+
};
|
|
359
362
|
let parsed;
|
|
360
363
|
try {
|
|
361
364
|
parsed = JSON.parse(attachment.body.toString("utf-8"));
|
|
@@ -381,7 +384,7 @@ function parseFixtureSpan(value, testId, index) {
|
|
|
381
384
|
if (!isRecord(value)) throw invalidFixtureSpanError(testId, index);
|
|
382
385
|
const startTime = parseAttachmentDate(value.startTime);
|
|
383
386
|
const endTime = parseAttachmentDate(value.endTime);
|
|
384
|
-
if (typeof value.traceId !== "string" || typeof value.spanId !== "string" || typeof value.name !== "string" || !startTime || !endTime || !isSpanAttributes(value.attributes) || !isSpanStatus(value.status)) throw invalidFixtureSpanError(testId, index);
|
|
387
|
+
if (typeof value.traceId !== "string" || typeof value.spanId !== "string" || typeof value.name !== "string" || !startTime || !endTime || !isSpanAttributes(value.attributes) || !isSpanEvents(value.events) || value.status !== void 0 && !isSpanStatus(value.status)) throw invalidFixtureSpanError(testId, index);
|
|
385
388
|
return {
|
|
386
389
|
traceId: value.traceId,
|
|
387
390
|
spanId: value.spanId,
|
|
@@ -390,6 +393,11 @@ function parseFixtureSpan(value, testId, index) {
|
|
|
390
393
|
startTime,
|
|
391
394
|
endTime,
|
|
392
395
|
attributes: value.attributes,
|
|
396
|
+
events: value.events.map((event) => ({
|
|
397
|
+
name: event.name,
|
|
398
|
+
time: parseAttachmentDate(event.time),
|
|
399
|
+
attributes: event.attributes
|
|
400
|
+
})),
|
|
393
401
|
status: value.status,
|
|
394
402
|
kind: typeof value.kind === "number" ? value.kind : void 0,
|
|
395
403
|
serviceName: typeof value.serviceName === "string" ? value.serviceName : void 0
|
|
@@ -406,10 +414,38 @@ function parseAttachmentDate(value) {
|
|
|
406
414
|
function isSpanStatus(value) {
|
|
407
415
|
return isRecord(value) && typeof value.code === "number";
|
|
408
416
|
}
|
|
417
|
+
const ANSI_ESCAPE_PATTERN = /[\u001b\u009b][[\]()#;?]*(?:(?:(?:[a-zA-Z\d]*(?:;[a-zA-Z\d]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))/g;
|
|
418
|
+
const ORPHANED_ANSI_SGR_PATTERN = /\[(?:\d{1,3};)*\d{1,3}m/g;
|
|
419
|
+
function errorStatus(message) {
|
|
420
|
+
if (!message) return { code: 2 };
|
|
421
|
+
const cleanedMessage = cleanErrorMessage(message);
|
|
422
|
+
return cleanedMessage ? {
|
|
423
|
+
code: 2,
|
|
424
|
+
message: cleanedMessage
|
|
425
|
+
} : { code: 2 };
|
|
426
|
+
}
|
|
427
|
+
function cleanErrorMessage(message) {
|
|
428
|
+
return message.replace(ANSI_ESCAPE_PATTERN, "").replace(ORPHANED_ANSI_SGR_PATTERN, "").replace(/\r\n?/g, "\n").trim();
|
|
429
|
+
}
|
|
430
|
+
function isInternalFixtureStep(step) {
|
|
431
|
+
if (step.category !== "fixture" || !step.location?.file) return false;
|
|
432
|
+
const file = step.location.file.replace(/\\/g, "/");
|
|
433
|
+
return INTERNAL_FIXTURE_FILE_PATTERNS.some((pattern) => pattern.test(file));
|
|
434
|
+
}
|
|
435
|
+
const INTERNAL_FIXTURE_FILE_PATTERNS = [
|
|
436
|
+
/(?:^|\/)dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
|
|
437
|
+
/(?:^|\/)playwright-opentelemetry\/dist\/fixture\.(?:mjs|cjs|js)$/,
|
|
438
|
+
/(?:^|\/)playwright-opentelemetry\/dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
|
|
439
|
+
/(?:^|\/)playwright-opentelemetry\/dist\/fixture\/index\.(?:mjs|cjs|js)$/,
|
|
440
|
+
/(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/playwright-opentelemetry-fixture\.ts$/
|
|
441
|
+
];
|
|
409
442
|
function isSpanAttributes(value) {
|
|
410
443
|
if (!isRecord(value)) return false;
|
|
411
444
|
return Object.values(value).every((attributeValue) => typeof attributeValue === "string" || typeof attributeValue === "number" || typeof attributeValue === "boolean" || Array.isArray(attributeValue) && attributeValue.every((item) => typeof item === "string"));
|
|
412
445
|
}
|
|
446
|
+
function isSpanEvents(value) {
|
|
447
|
+
return Array.isArray(value) && value.every((event) => isRecord(event) && typeof event.name === "string" && parseAttachmentDate(event.time) !== void 0 && (event.attributes === void 0 || isSpanAttributes(event.attributes)));
|
|
448
|
+
}
|
|
413
449
|
function isRecord(value) {
|
|
414
450
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
415
451
|
}
|