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