playwright-opentelemetry 0.6.0 → 0.6.2
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 → config-2S21d575.d.cts} +1 -0
- package/dist/{config-B9i3jm5s.d.mts → config-2S21d575.d.mts} +1 -0
- package/dist/{trace-context-e11YEu8B.mjs → config-DtRqsWLc.mjs} +44 -34
- package/dist/{trace-context-88H-vhOr.cjs → config-DyCIVAMs.cjs} +43 -33
- 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 +2 -2
- package/dist/fixture.d.mts +2 -2
- package/dist/fixture.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- 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-CQtQM60Z.mjs → playwright-opentelemetry-fixture-B1ZK-LqY.mjs} +81 -11
- package/dist/{fixture-IJvYGCtD.d.mts → playwright-opentelemetry-fixture-BGWT93Zw.d.mts} +12 -6
- package/dist/{fixture-1Zc7Gp0b.d.cts → playwright-opentelemetry-fixture-OLGl3MWO.d.cts} +12 -6
- package/dist/{fixture-C85kKbWA.cjs → playwright-opentelemetry-fixture-S6naMJss.cjs} +87 -17
- package/dist/{reporter-XVwaSQDK.cjs → reporter-B5naKhOY.cjs} +65 -34
- package/dist/{reporter-S_gsTMix.mjs → reporter-BCfhex03.mjs} +50 -19
- package/dist/reporter.cjs +1 -1
- package/dist/reporter.mjs +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region package.json
|
|
2
|
-
var version = "0.6.
|
|
2
|
+
var version = "0.6.2";
|
|
3
3
|
//#endregion
|
|
4
4
|
//#region src/shared/otel.ts
|
|
5
5
|
/** Generate a random 32-character hex trace ID. */
|
|
@@ -54,7 +54,12 @@ function buildResourceSpan(spans, serviceName, playwrightVersion) {
|
|
|
54
54
|
endTimeUnixNano: dateToNanoseconds(span.endTime),
|
|
55
55
|
attributes: toOtlpAttributes(span.attributes),
|
|
56
56
|
droppedAttributesCount: 0,
|
|
57
|
-
events: []
|
|
57
|
+
events: (span.events ?? []).map((event) => ({
|
|
58
|
+
name: event.name,
|
|
59
|
+
timeUnixNano: dateToNanoseconds(event.time),
|
|
60
|
+
attributes: toOtlpAttributes(event.attributes ?? {}),
|
|
61
|
+
droppedAttributesCount: 0
|
|
62
|
+
})),
|
|
58
63
|
droppedEventsCount: 0,
|
|
59
64
|
status: span.status,
|
|
60
65
|
links: [],
|
|
@@ -114,36 +119,6 @@ async function sendSpans(spans, options) {
|
|
|
114
119
|
}
|
|
115
120
|
}
|
|
116
121
|
//#endregion
|
|
117
|
-
//#region src/shared/config.ts
|
|
118
|
-
function resolvePlaywrightOpentelemetryConfig(config, options = {}) {
|
|
119
|
-
const envOtlpHeaders = parseOtlpHeaders(process.env.OTEL_EXPORTER_OTLP_HEADERS);
|
|
120
|
-
const envTraceApiHeaders = parseOtlpHeaders(process.env.PLAYWRIGHT_TRACE_API_HEADERS);
|
|
121
|
-
const debugEnv = process.env.PLAYWRIGHT_OPENTELEMETRY_DEBUG;
|
|
122
|
-
const resolvedConfig = {
|
|
123
|
-
otlpEndpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || config?.otlpEndpoint || "",
|
|
124
|
-
otlpHeaders: {
|
|
125
|
-
...config?.otlpHeaders,
|
|
126
|
-
...envOtlpHeaders
|
|
127
|
-
},
|
|
128
|
-
playwrightTraceApiEndpoint: process.env.PLAYWRIGHT_TRACE_API_ENDPOINT || config?.playwrightTraceApiEndpoint || "",
|
|
129
|
-
playwrightTraceApiHeaders: {
|
|
130
|
-
...config?.playwrightTraceApiHeaders,
|
|
131
|
-
...envTraceApiHeaders
|
|
132
|
-
},
|
|
133
|
-
storeTraceZip: config?.storeTraceZip === true,
|
|
134
|
-
serviceName: process.env.OTEL_SERVICE_NAME || config?.serviceName || "playwright-tests",
|
|
135
|
-
debug: debugEnv === void 0 ? config?.debug ?? false : debugEnv === "1" || debugEnv === "true"
|
|
136
|
-
};
|
|
137
|
-
if (options.requireDestination === true && !hasPlaywrightOpentelemetryDestination(resolvedConfig)) throw new Error(getConfigurationErrorMessage());
|
|
138
|
-
return resolvedConfig;
|
|
139
|
-
}
|
|
140
|
-
function hasPlaywrightOpentelemetryDestination(config) {
|
|
141
|
-
return Boolean(config.otlpEndpoint || config.playwrightTraceApiEndpoint || config.storeTraceZip);
|
|
142
|
-
}
|
|
143
|
-
function getConfigurationErrorMessage() {
|
|
144
|
-
return "playwright-opentelemetry reporter requires an OTLP endpoint, trace API endpoint, or storeTraceZip to be configured.\n\nYou can configure it using environment variables:\n\n export OTEL_EXPORTER_OTLP_ENDPOINT=\"https://api.honeycomb.io\"\n export OTEL_EXPORTER_OTLP_HEADERS=\"x-honeycomb-team=YOUR_API_KEY\"\n export OTEL_SERVICE_NAME=\"my-service\"\n\nOr via playwright.config.ts:\n\nimport { defineConfig } from '@playwright/test';\nimport type { PlaywrightOpentelemetryUseOptions } from 'playwright-opentelemetry/fixture';\n\nexport default defineConfig<PlaywrightOpentelemetryUseOptions>({\n use: {\n playwrightOpentelemetry: {\n otlpEndpoint: 'http://localhost:4317/v1/traces',\n otlpHeaders: {\n Authorization: 'Bearer YOUR_TOKEN',\n },\n serviceName: 'my-service',\n },\n },\n reporter: [['playwright-opentelemetry/reporter']],\n});\n\nNote: Environment variables take precedence over use.playwrightOpentelemetry options.\n";
|
|
145
|
-
}
|
|
146
|
-
//#endregion
|
|
147
122
|
//#region src/fixture/trace-context.ts
|
|
148
123
|
const TRACE_CONTEXT_ATTACHMENT_NAME = "playwright-opentelemetry-trace-context";
|
|
149
124
|
const FIXTURE_SPANS_ATTACHMENT_NAME = "playwright-opentelemetry-fixture-spans";
|
|
@@ -186,7 +161,11 @@ function serializeSpanForAttachment(span) {
|
|
|
186
161
|
return {
|
|
187
162
|
...span,
|
|
188
163
|
startTime: span.startTime.toISOString(),
|
|
189
|
-
endTime: span.endTime.toISOString()
|
|
164
|
+
endTime: span.endTime.toISOString(),
|
|
165
|
+
events: span.events.map((event) => ({
|
|
166
|
+
...event,
|
|
167
|
+
time: event.time.toISOString()
|
|
168
|
+
}))
|
|
190
169
|
};
|
|
191
170
|
}
|
|
192
171
|
function fixtureSpanDestinations(config) {
|
|
@@ -202,4 +181,35 @@ function fixtureSpanDestinations(config) {
|
|
|
202
181
|
return destinations;
|
|
203
182
|
}
|
|
204
183
|
//#endregion
|
|
205
|
-
|
|
184
|
+
//#region src/shared/config.ts
|
|
185
|
+
function resolvePlaywrightOpentelemetryConfig(config, options = {}) {
|
|
186
|
+
const envOtlpHeaders = parseOtlpHeaders(process.env.OTEL_EXPORTER_OTLP_HEADERS);
|
|
187
|
+
const envTraceApiHeaders = parseOtlpHeaders(process.env.PLAYWRIGHT_TRACE_API_HEADERS);
|
|
188
|
+
const debugEnv = process.env.PLAYWRIGHT_OPENTELEMETRY_DEBUG;
|
|
189
|
+
const resolvedConfig = {
|
|
190
|
+
otlpEndpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || config?.otlpEndpoint || "",
|
|
191
|
+
otlpHeaders: {
|
|
192
|
+
...config?.otlpHeaders,
|
|
193
|
+
...envOtlpHeaders
|
|
194
|
+
},
|
|
195
|
+
playwrightTraceApiEndpoint: process.env.PLAYWRIGHT_TRACE_API_ENDPOINT || config?.playwrightTraceApiEndpoint || "",
|
|
196
|
+
playwrightTraceApiHeaders: {
|
|
197
|
+
...config?.playwrightTraceApiHeaders,
|
|
198
|
+
...envTraceApiHeaders
|
|
199
|
+
},
|
|
200
|
+
storeTraceZip: config?.storeTraceZip === true,
|
|
201
|
+
propagateTraceHeaders: config?.propagateTraceHeaders ?? true,
|
|
202
|
+
serviceName: process.env.OTEL_SERVICE_NAME || config?.serviceName || "playwright-tests",
|
|
203
|
+
debug: debugEnv === void 0 ? config?.debug ?? false : debugEnv === "1" || debugEnv === "true"
|
|
204
|
+
};
|
|
205
|
+
if (options.requireDestination === true && !hasPlaywrightOpentelemetryDestination(resolvedConfig)) throw new Error(getConfigurationErrorMessage());
|
|
206
|
+
return resolvedConfig;
|
|
207
|
+
}
|
|
208
|
+
function hasPlaywrightOpentelemetryDestination(config) {
|
|
209
|
+
return Boolean(config.otlpEndpoint || config.playwrightTraceApiEndpoint || config.storeTraceZip);
|
|
210
|
+
}
|
|
211
|
+
function getConfigurationErrorMessage() {
|
|
212
|
+
return "playwright-opentelemetry reporter requires an OTLP endpoint, trace API endpoint, or storeTraceZip to be configured.\n\nYou can configure it using environment variables:\n\n export OTEL_EXPORTER_OTLP_ENDPOINT=\"https://api.honeycomb.io\"\n export OTEL_EXPORTER_OTLP_HEADERS=\"x-honeycomb-team=YOUR_API_KEY\"\n export OTEL_SERVICE_NAME=\"my-service\"\n\nOr via playwright.config.ts:\n\nimport { defineConfig } from '@playwright/test';\nimport type { PlaywrightOpentelemetryUseOptions } from 'playwright-opentelemetry/fixture';\n\nexport default defineConfig<PlaywrightOpentelemetryUseOptions>({\n use: {\n playwrightOpentelemetry: {\n otlpEndpoint: 'http://localhost:4317/v1/traces',\n otlpHeaders: {\n Authorization: 'Bearer YOUR_TOKEN',\n },\n serviceName: 'my-service',\n },\n },\n reporter: [['playwright-opentelemetry/reporter']],\n});\n\nNote: Environment variables take precedence over use.playwrightOpentelemetry options.\n";
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
export { flushFixtureSpans as a, generateTraceId as c, createTestTraceContext as i, sendSpans as l, FIXTURE_SPANS_ATTACHMENT_NAME as n, buildOtlpRequest as o, TRACE_CONTEXT_ATTACHMENT_NAME as r, generateSpanId as s, resolvePlaywrightOpentelemetryConfig as t };
|
|
@@ -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.6.
|
|
24
|
+
var version = "0.6.2";
|
|
25
25
|
//#endregion
|
|
26
26
|
//#region src/shared/otel.ts
|
|
27
27
|
/** Generate a random 32-character hex trace ID. */
|
|
@@ -76,7 +76,12 @@ function buildResourceSpan(spans, serviceName, playwrightVersion) {
|
|
|
76
76
|
endTimeUnixNano: dateToNanoseconds(span.endTime),
|
|
77
77
|
attributes: toOtlpAttributes(span.attributes),
|
|
78
78
|
droppedAttributesCount: 0,
|
|
79
|
-
events: []
|
|
79
|
+
events: (span.events ?? []).map((event) => ({
|
|
80
|
+
name: event.name,
|
|
81
|
+
timeUnixNano: dateToNanoseconds(event.time),
|
|
82
|
+
attributes: toOtlpAttributes(event.attributes ?? {}),
|
|
83
|
+
droppedAttributesCount: 0
|
|
84
|
+
})),
|
|
80
85
|
droppedEventsCount: 0,
|
|
81
86
|
status: span.status,
|
|
82
87
|
links: [],
|
|
@@ -136,36 +141,6 @@ async function sendSpans(spans, options) {
|
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
//#endregion
|
|
139
|
-
//#region src/shared/config.ts
|
|
140
|
-
function resolvePlaywrightOpentelemetryConfig(config, options = {}) {
|
|
141
|
-
const envOtlpHeaders = parseOtlpHeaders(process.env.OTEL_EXPORTER_OTLP_HEADERS);
|
|
142
|
-
const envTraceApiHeaders = parseOtlpHeaders(process.env.PLAYWRIGHT_TRACE_API_HEADERS);
|
|
143
|
-
const debugEnv = process.env.PLAYWRIGHT_OPENTELEMETRY_DEBUG;
|
|
144
|
-
const resolvedConfig = {
|
|
145
|
-
otlpEndpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || config?.otlpEndpoint || "",
|
|
146
|
-
otlpHeaders: {
|
|
147
|
-
...config?.otlpHeaders,
|
|
148
|
-
...envOtlpHeaders
|
|
149
|
-
},
|
|
150
|
-
playwrightTraceApiEndpoint: process.env.PLAYWRIGHT_TRACE_API_ENDPOINT || config?.playwrightTraceApiEndpoint || "",
|
|
151
|
-
playwrightTraceApiHeaders: {
|
|
152
|
-
...config?.playwrightTraceApiHeaders,
|
|
153
|
-
...envTraceApiHeaders
|
|
154
|
-
},
|
|
155
|
-
storeTraceZip: config?.storeTraceZip === true,
|
|
156
|
-
serviceName: process.env.OTEL_SERVICE_NAME || config?.serviceName || "playwright-tests",
|
|
157
|
-
debug: debugEnv === void 0 ? config?.debug ?? false : debugEnv === "1" || debugEnv === "true"
|
|
158
|
-
};
|
|
159
|
-
if (options.requireDestination === true && !hasPlaywrightOpentelemetryDestination(resolvedConfig)) throw new Error(getConfigurationErrorMessage());
|
|
160
|
-
return resolvedConfig;
|
|
161
|
-
}
|
|
162
|
-
function hasPlaywrightOpentelemetryDestination(config) {
|
|
163
|
-
return Boolean(config.otlpEndpoint || config.playwrightTraceApiEndpoint || config.storeTraceZip);
|
|
164
|
-
}
|
|
165
|
-
function getConfigurationErrorMessage() {
|
|
166
|
-
return "playwright-opentelemetry reporter requires an OTLP endpoint, trace API endpoint, or storeTraceZip to be configured.\n\nYou can configure it using environment variables:\n\n export OTEL_EXPORTER_OTLP_ENDPOINT=\"https://api.honeycomb.io\"\n export OTEL_EXPORTER_OTLP_HEADERS=\"x-honeycomb-team=YOUR_API_KEY\"\n export OTEL_SERVICE_NAME=\"my-service\"\n\nOr via playwright.config.ts:\n\nimport { defineConfig } from '@playwright/test';\nimport type { PlaywrightOpentelemetryUseOptions } from 'playwright-opentelemetry/fixture';\n\nexport default defineConfig<PlaywrightOpentelemetryUseOptions>({\n use: {\n playwrightOpentelemetry: {\n otlpEndpoint: 'http://localhost:4317/v1/traces',\n otlpHeaders: {\n Authorization: 'Bearer YOUR_TOKEN',\n },\n serviceName: 'my-service',\n },\n },\n reporter: [['playwright-opentelemetry/reporter']],\n});\n\nNote: Environment variables take precedence over use.playwrightOpentelemetry options.\n";
|
|
167
|
-
}
|
|
168
|
-
//#endregion
|
|
169
144
|
//#region src/fixture/trace-context.ts
|
|
170
145
|
const TRACE_CONTEXT_ATTACHMENT_NAME = "playwright-opentelemetry-trace-context";
|
|
171
146
|
const FIXTURE_SPANS_ATTACHMENT_NAME = "playwright-opentelemetry-fixture-spans";
|
|
@@ -208,7 +183,11 @@ function serializeSpanForAttachment(span) {
|
|
|
208
183
|
return {
|
|
209
184
|
...span,
|
|
210
185
|
startTime: span.startTime.toISOString(),
|
|
211
|
-
endTime: span.endTime.toISOString()
|
|
186
|
+
endTime: span.endTime.toISOString(),
|
|
187
|
+
events: span.events.map((event) => ({
|
|
188
|
+
...event,
|
|
189
|
+
time: event.time.toISOString()
|
|
190
|
+
}))
|
|
212
191
|
};
|
|
213
192
|
}
|
|
214
193
|
function fixtureSpanDestinations(config) {
|
|
@@ -224,6 +203,37 @@ function fixtureSpanDestinations(config) {
|
|
|
224
203
|
return destinations;
|
|
225
204
|
}
|
|
226
205
|
//#endregion
|
|
206
|
+
//#region src/shared/config.ts
|
|
207
|
+
function resolvePlaywrightOpentelemetryConfig(config, options = {}) {
|
|
208
|
+
const envOtlpHeaders = parseOtlpHeaders(process.env.OTEL_EXPORTER_OTLP_HEADERS);
|
|
209
|
+
const envTraceApiHeaders = parseOtlpHeaders(process.env.PLAYWRIGHT_TRACE_API_HEADERS);
|
|
210
|
+
const debugEnv = process.env.PLAYWRIGHT_OPENTELEMETRY_DEBUG;
|
|
211
|
+
const resolvedConfig = {
|
|
212
|
+
otlpEndpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || config?.otlpEndpoint || "",
|
|
213
|
+
otlpHeaders: {
|
|
214
|
+
...config?.otlpHeaders,
|
|
215
|
+
...envOtlpHeaders
|
|
216
|
+
},
|
|
217
|
+
playwrightTraceApiEndpoint: process.env.PLAYWRIGHT_TRACE_API_ENDPOINT || config?.playwrightTraceApiEndpoint || "",
|
|
218
|
+
playwrightTraceApiHeaders: {
|
|
219
|
+
...config?.playwrightTraceApiHeaders,
|
|
220
|
+
...envTraceApiHeaders
|
|
221
|
+
},
|
|
222
|
+
storeTraceZip: config?.storeTraceZip === true,
|
|
223
|
+
propagateTraceHeaders: config?.propagateTraceHeaders ?? true,
|
|
224
|
+
serviceName: process.env.OTEL_SERVICE_NAME || config?.serviceName || "playwright-tests",
|
|
225
|
+
debug: debugEnv === void 0 ? config?.debug ?? false : debugEnv === "1" || debugEnv === "true"
|
|
226
|
+
};
|
|
227
|
+
if (options.requireDestination === true && !hasPlaywrightOpentelemetryDestination(resolvedConfig)) throw new Error(getConfigurationErrorMessage());
|
|
228
|
+
return resolvedConfig;
|
|
229
|
+
}
|
|
230
|
+
function hasPlaywrightOpentelemetryDestination(config) {
|
|
231
|
+
return Boolean(config.otlpEndpoint || config.playwrightTraceApiEndpoint || config.storeTraceZip);
|
|
232
|
+
}
|
|
233
|
+
function getConfigurationErrorMessage() {
|
|
234
|
+
return "playwright-opentelemetry reporter requires an OTLP endpoint, trace API endpoint, or storeTraceZip to be configured.\n\nYou can configure it using environment variables:\n\n export OTEL_EXPORTER_OTLP_ENDPOINT=\"https://api.honeycomb.io\"\n export OTEL_EXPORTER_OTLP_HEADERS=\"x-honeycomb-team=YOUR_API_KEY\"\n export OTEL_SERVICE_NAME=\"my-service\"\n\nOr via playwright.config.ts:\n\nimport { defineConfig } from '@playwright/test';\nimport type { PlaywrightOpentelemetryUseOptions } from 'playwright-opentelemetry/fixture';\n\nexport default defineConfig<PlaywrightOpentelemetryUseOptions>({\n use: {\n playwrightOpentelemetry: {\n otlpEndpoint: 'http://localhost:4317/v1/traces',\n otlpHeaders: {\n Authorization: 'Bearer YOUR_TOKEN',\n },\n serviceName: 'my-service',\n },\n },\n reporter: [['playwright-opentelemetry/reporter']],\n});\n\nNote: Environment variables take precedence over use.playwrightOpentelemetry options.\n";
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
227
237
|
Object.defineProperty(exports, "FIXTURE_SPANS_ATTACHMENT_NAME", {
|
|
228
238
|
enumerable: true,
|
|
229
239
|
get: function() {
|
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_playwright_opentelemetry_fixture = require("../playwright-opentelemetry-fixture-S6naMJss.cjs");
|
|
3
|
+
exports.createPlaywrightOtelTest = require_playwright_opentelemetry_fixture.createPlaywrightOtelTest;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createPlaywrightOtelTest } from "../fixture-
|
|
1
|
+
import { t as createPlaywrightOtelTest } from "../playwright-opentelemetry-fixture-OLGl3MWO.cjs";
|
|
2
2
|
export { createPlaywrightOtelTest };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createPlaywrightOtelTest } from "../fixture-
|
|
1
|
+
import { t as createPlaywrightOtelTest } from "../playwright-opentelemetry-fixture-BGWT93Zw.mjs";
|
|
2
2
|
export { createPlaywrightOtelTest };
|
package/dist/fixture/factory.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createPlaywrightOtelTest } from "../fixture-
|
|
1
|
+
import { t as createPlaywrightOtelTest } from "../playwright-opentelemetry-fixture-B1ZK-LqY.mjs";
|
|
2
2
|
export { createPlaywrightOtelTest };
|
package/dist/fixture.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_playwright_opentelemetry_fixture = require("./playwright-opentelemetry-fixture-S6naMJss.cjs");
|
|
3
3
|
let _playwright_test = require("@playwright/test");
|
|
4
4
|
//#region src/fixture/index.ts
|
|
5
|
-
const test =
|
|
5
|
+
const test = require_playwright_opentelemetry_fixture.createPlaywrightOtelTest(_playwright_test.test);
|
|
6
6
|
//#endregion
|
|
7
|
-
exports.createPlaywrightOtelTest =
|
|
7
|
+
exports.createPlaywrightOtelTest = require_playwright_opentelemetry_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,5 +1,5 @@
|
|
|
1
|
-
import { n as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
2
|
-
import { n as BrowserPageTracker, r as TestTraceContext, t as createPlaywrightOtelTest } from "./fixture-
|
|
1
|
+
import { n as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-2S21d575.cjs";
|
|
2
|
+
import { n as BrowserPageTracker, r as TestTraceContext, t as createPlaywrightOtelTest } from "./playwright-opentelemetry-fixture-OLGl3MWO.cjs";
|
|
3
3
|
export * from "@playwright/test";
|
|
4
4
|
|
|
5
5
|
//#region src/fixture/index.d.ts
|
package/dist/fixture.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
2
|
-
import { n as BrowserPageTracker, r as TestTraceContext, t as createPlaywrightOtelTest } from "./fixture-
|
|
1
|
+
import { n as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-2S21d575.mjs";
|
|
2
|
+
import { n as BrowserPageTracker, r as TestTraceContext, t as createPlaywrightOtelTest } from "./playwright-opentelemetry-fixture-BGWT93Zw.mjs";
|
|
3
3
|
export * from "@playwright/test";
|
|
4
4
|
|
|
5
5
|
//#region src/fixture/index.d.ts
|
package/dist/fixture.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createPlaywrightOtelTest } from "./fixture-
|
|
1
|
+
import { t as createPlaywrightOtelTest } from "./playwright-opentelemetry-fixture-B1ZK-LqY.mjs";
|
|
2
2
|
import { test as test$1 } from "@playwright/test";
|
|
3
3
|
export * from "@playwright/test";
|
|
4
4
|
//#region src/fixture/index.ts
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
1
|
+
import { n as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-2S21d575.cjs";
|
|
2
2
|
import { t as PlaywrightOpentelemetryReporter } from "./reporter-DaCojFom.cjs";
|
|
3
3
|
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, PlaywrightOpentelemetryReporter as default };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
1
|
+
import { n as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-2S21d575.mjs";
|
|
2
2
|
import { t as PlaywrightOpentelemetryReporter } from "./reporter-DaCojFom.mjs";
|
|
3
3
|
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, PlaywrightOpentelemetryReporter as default };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
//#region src/shared/otel.d.ts
|
|
2
2
|
type SpanAttributeValue = string | number | boolean | string[];
|
|
3
|
+
type SpanEvent = {
|
|
4
|
+
name: string;
|
|
5
|
+
time: Date;
|
|
6
|
+
attributes?: Record<string, SpanAttributeValue>;
|
|
7
|
+
};
|
|
3
8
|
type Span = {
|
|
4
9
|
traceId: string;
|
|
5
10
|
spanId: string;
|
|
@@ -8,11 +13,13 @@ type Span = {
|
|
|
8
13
|
startTime: Date;
|
|
9
14
|
endTime: Date;
|
|
10
15
|
attributes: Record<string, SpanAttributeValue>;
|
|
11
|
-
|
|
16
|
+
events?: SpanEvent[];
|
|
17
|
+
status?: {
|
|
12
18
|
code: number;
|
|
19
|
+
message?: string;
|
|
13
20
|
};
|
|
14
21
|
kind?: number; /** Service name for this span (if different from default). */
|
|
15
22
|
serviceName?: string;
|
|
16
23
|
};
|
|
17
24
|
//#endregion
|
|
18
|
-
export { Span as t };
|
|
25
|
+
export { SpanEvent as n, Span as t };
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
//#region src/shared/otel.d.ts
|
|
2
2
|
type SpanAttributeValue = string | number | boolean | string[];
|
|
3
|
+
type SpanEvent = {
|
|
4
|
+
name: string;
|
|
5
|
+
time: Date;
|
|
6
|
+
attributes?: Record<string, SpanAttributeValue>;
|
|
7
|
+
};
|
|
3
8
|
type Span = {
|
|
4
9
|
traceId: string;
|
|
5
10
|
spanId: string;
|
|
@@ -8,11 +13,13 @@ type Span = {
|
|
|
8
13
|
startTime: Date;
|
|
9
14
|
endTime: Date;
|
|
10
15
|
attributes: Record<string, SpanAttributeValue>;
|
|
11
|
-
|
|
16
|
+
events?: SpanEvent[];
|
|
17
|
+
status?: {
|
|
12
18
|
code: number;
|
|
19
|
+
message?: string;
|
|
13
20
|
};
|
|
14
21
|
kind?: number; /** Service name for this span (if different from default). */
|
|
15
22
|
serviceName?: string;
|
|
16
23
|
};
|
|
17
24
|
//#endregion
|
|
18
|
-
export { Span as t };
|
|
25
|
+
export { SpanEvent as n, Span as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as flushFixtureSpans, i as createTestTraceContext, s as generateSpanId, t as resolvePlaywrightOpentelemetryConfig } from "./config-DtRqsWLc.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 }],
|
|
@@ -368,23 +422,39 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
368
422
|
await use(tracker);
|
|
369
423
|
tracker.finishAll();
|
|
370
424
|
}, { auto: true }],
|
|
371
|
-
context: async ({ context, testTraceContext, browserPageTracker }, use) => {
|
|
425
|
+
context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker }, use) => {
|
|
426
|
+
const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
372
427
|
context.route("**", async (route, request) => {
|
|
373
428
|
browserPageTracker.startDocumentNavigation(request);
|
|
374
429
|
const networkParent = browserPageTracker.getNetworkParent(request);
|
|
375
|
-
|
|
376
|
-
route,
|
|
430
|
+
const spanId = storeRequestTraceContext({
|
|
377
431
|
request,
|
|
378
432
|
traceContext: testTraceContext,
|
|
379
433
|
parentSpanId: networkParent.spanId,
|
|
380
434
|
routeAssociation: networkParent.routeAssociation
|
|
381
435
|
});
|
|
436
|
+
if (config.propagateTraceHeaders) {
|
|
437
|
+
await propagateRouteTraceHeaders({
|
|
438
|
+
route,
|
|
439
|
+
request,
|
|
440
|
+
traceId: testTraceContext.traceId,
|
|
441
|
+
spanId
|
|
442
|
+
});
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
await route.fallback();
|
|
382
446
|
});
|
|
383
447
|
await use(context);
|
|
384
448
|
},
|
|
385
449
|
page: async ({ page, testTraceContext, browserPageTracker }, use) => {
|
|
386
450
|
browserPageTracker.registerPage(page);
|
|
387
451
|
page.on("close", () => browserPageTracker.unregisterPage(page));
|
|
452
|
+
page.on("console", (message) => {
|
|
453
|
+
browserPageTracker.recordConsoleMessage(page, message);
|
|
454
|
+
});
|
|
455
|
+
page.on("pageerror", (error) => {
|
|
456
|
+
browserPageTracker.recordPageError(page, error);
|
|
457
|
+
});
|
|
388
458
|
page.on("framenavigated", (frame) => {
|
|
389
459
|
if (frame === page.mainFrame()) browserPageTracker.handleFrameNavigated(page, frame.url());
|
|
390
460
|
});
|
|
@@ -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-2S21d575.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,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-2S21d575.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,6 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_config = require("./config-DyCIVAMs.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 }],
|
|
@@ -359,33 +413,49 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
359
413
|
});
|
|
360
414
|
}, { auto: true }],
|
|
361
415
|
testTraceContext: [async ({ playwrightOpentelemetry }, use, testInfo) => {
|
|
362
|
-
const config =
|
|
363
|
-
const traceContext = await
|
|
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, testInfo);
|
|
366
420
|
}, { auto: true }],
|
|
367
421
|
browserPageTracker: [async ({ testTraceContext }, use) => {
|
|
368
422
|
const tracker = new BrowserPageTracker(testTraceContext);
|
|
369
423
|
await use(tracker);
|
|
370
424
|
tracker.finishAll();
|
|
371
425
|
}, { auto: true }],
|
|
372
|
-
context: async ({ context, testTraceContext, browserPageTracker }, use) => {
|
|
426
|
+
context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker }, use) => {
|
|
427
|
+
const config = require_config.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
373
428
|
context.route("**", async (route, request) => {
|
|
374
429
|
browserPageTracker.startDocumentNavigation(request);
|
|
375
430
|
const networkParent = browserPageTracker.getNetworkParent(request);
|
|
376
|
-
|
|
377
|
-
route,
|
|
431
|
+
const spanId = storeRequestTraceContext({
|
|
378
432
|
request,
|
|
379
433
|
traceContext: testTraceContext,
|
|
380
434
|
parentSpanId: networkParent.spanId,
|
|
381
435
|
routeAssociation: networkParent.routeAssociation
|
|
382
436
|
});
|
|
437
|
+
if (config.propagateTraceHeaders) {
|
|
438
|
+
await propagateRouteTraceHeaders({
|
|
439
|
+
route,
|
|
440
|
+
request,
|
|
441
|
+
traceId: testTraceContext.traceId,
|
|
442
|
+
spanId
|
|
443
|
+
});
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
await route.fallback();
|
|
383
447
|
});
|
|
384
448
|
await use(context);
|
|
385
449
|
},
|
|
386
450
|
page: async ({ page, testTraceContext, browserPageTracker }, use) => {
|
|
387
451
|
browserPageTracker.registerPage(page);
|
|
388
452
|
page.on("close", () => browserPageTracker.unregisterPage(page));
|
|
453
|
+
page.on("console", (message) => {
|
|
454
|
+
browserPageTracker.recordConsoleMessage(page, message);
|
|
455
|
+
});
|
|
456
|
+
page.on("pageerror", (error) => {
|
|
457
|
+
browserPageTracker.recordPageError(page, error);
|
|
458
|
+
});
|
|
389
459
|
page.on("framenavigated", (frame) => {
|
|
390
460
|
if (frame === page.mainFrame()) browserPageTracker.handleFrameNavigated(page, frame.url());
|
|
391
461
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_config = require("./config-DyCIVAMs.cjs");
|
|
2
2
|
let node_path = require("node:path");
|
|
3
|
-
node_path =
|
|
3
|
+
node_path = require_config.__toESM(node_path, 1);
|
|
4
4
|
let node_fs_promises = require("node:fs/promises");
|
|
5
|
-
node_fs_promises =
|
|
5
|
+
node_fs_promises = require_config.__toESM(node_fs_promises, 1);
|
|
6
6
|
let _zip_js_zip_js = require("@zip.js/zip.js");
|
|
7
7
|
//#region src/reporter/otel-attributes.ts
|
|
8
8
|
const ATTR_CODE_FILE_PATH = "code.file.path";
|
|
@@ -71,12 +71,12 @@ async function createScreenshotsZip(screenshots) {
|
|
|
71
71
|
}
|
|
72
72
|
async function createTraceZipBlob(options) {
|
|
73
73
|
const { spans, fixtureSpans, serviceName, playwrightVersion, screenshots } = options;
|
|
74
|
-
const otlpRequest =
|
|
74
|
+
const otlpRequest = require_config.buildOtlpRequest(spans, serviceName, playwrightVersion);
|
|
75
75
|
const traceJson = JSON.stringify(otlpRequest, null, 2);
|
|
76
76
|
const zipWriter = new _zip_js_zip_js.ZipWriter(new _zip_js_zip_js.BlobWriter("application/zip"));
|
|
77
77
|
await zipWriter.add("traces/playwright-opentelemetry.json", new Blob([traceJson]).stream());
|
|
78
78
|
if (fixtureSpans.length > 0) {
|
|
79
|
-
const fixtureOtlpRequest =
|
|
79
|
+
const fixtureOtlpRequest = require_config.buildOtlpRequest(fixtureSpans, "playwright-browser", playwrightVersion);
|
|
80
80
|
await zipWriter.add("traces/playwright-browser.json", new Blob([JSON.stringify(fixtureOtlpRequest, null, 2)]).stream());
|
|
81
81
|
}
|
|
82
82
|
await addScreenshotsToZip(zipWriter, screenshots);
|
|
@@ -136,7 +136,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
136
136
|
this.playwrightVersion = config.version;
|
|
137
137
|
const projects = Array.isArray(config.projects) ? config.projects : [];
|
|
138
138
|
for (const project of projects) {
|
|
139
|
-
const resolvedConfig =
|
|
139
|
+
const resolvedConfig = require_config.resolvePlaywrightOpentelemetryConfig(getProjectPlaywrightOpentelemetryConfig(project), { requireDestination: true });
|
|
140
140
|
this.debug ||= resolvedConfig.debug;
|
|
141
141
|
}
|
|
142
142
|
}
|
|
@@ -147,7 +147,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
147
147
|
const testId = test.id;
|
|
148
148
|
const outputDir = getTestOutputDir(test);
|
|
149
149
|
const config = getTestConfig(test);
|
|
150
|
-
const { traceId, rootSpanId: testSpanId } = readTraceContextAttachment(result, testId
|
|
150
|
+
const { traceId, rootSpanId: testSpanId } = readTraceContextAttachment(result, testId);
|
|
151
151
|
const traceAttachment = result.attachments.find((attachment) => attachment.name === "trace" && attachment.contentType === "application/zip" && attachment.path);
|
|
152
152
|
const fixtureSpans = config.storeTraceZip ? readFixtureSpansAttachment(result, testId) : [];
|
|
153
153
|
result.attachments.push({
|
|
@@ -178,15 +178,16 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
178
178
|
if (stepSpan.startTime < minStartTime) minStartTime = stepSpan.startTime;
|
|
179
179
|
if (stepSpan.endTime > maxEndTime) maxEndTime = stepSpan.endTime;
|
|
180
180
|
}
|
|
181
|
-
const
|
|
181
|
+
const span = {
|
|
182
182
|
traceId,
|
|
183
183
|
spanId: testSpanId,
|
|
184
184
|
name: TEST_SPAN_NAME,
|
|
185
185
|
startTime: minStartTime,
|
|
186
186
|
endTime: maxEndTime,
|
|
187
|
-
attributes
|
|
188
|
-
|
|
189
|
-
}
|
|
187
|
+
attributes
|
|
188
|
+
};
|
|
189
|
+
if (result.status !== test.expectedStatus) span.status = { code: 2 };
|
|
190
|
+
const testSpans = [span, ...stepSpans];
|
|
190
191
|
this.spanBatches.push({
|
|
191
192
|
spans: testSpans,
|
|
192
193
|
config
|
|
@@ -231,7 +232,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
231
232
|
debug: batch.config.debug
|
|
232
233
|
});
|
|
233
234
|
}
|
|
234
|
-
for (const destination of destinations.values()) await
|
|
235
|
+
for (const destination of destinations.values()) await require_config.sendSpans(destination.spans, destination.options);
|
|
235
236
|
}
|
|
236
237
|
async prepareTraceArtifact(options) {
|
|
237
238
|
const screenshots = options.traceAttachmentPath ? await extractScreenshotsFromPlaywrightTrace(options.traceAttachmentPath) : /* @__PURE__ */ new Map();
|
|
@@ -252,9 +253,8 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
252
253
|
return { traceZipBlob };
|
|
253
254
|
}
|
|
254
255
|
processTestStep(test, step, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds) {
|
|
255
|
-
const isInternalFixture = step.category === "fixture" && step.location?.file.includes("playwright-opentelemetry") && (step.location?.file.endsWith("fixture.mjs") || step.location?.file.endsWith("fixture/index.ts"));
|
|
256
256
|
const stepId = getStepId(test, step);
|
|
257
|
-
if (
|
|
257
|
+
if (isInternalFixtureStep(step)) {
|
|
258
258
|
skippedStepIds.add(stepId);
|
|
259
259
|
processedSteps.delete(stepId);
|
|
260
260
|
if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds);
|
|
@@ -267,6 +267,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
267
267
|
const currentTitlePath = [...parentTitlePath, step.title];
|
|
268
268
|
const existingSpan = processedSteps.get(stepId);
|
|
269
269
|
if (existingSpan) {
|
|
270
|
+
if (step.error) existingSpan.status = errorStatus(step.error.message);
|
|
270
271
|
if (step.location && !existingSpan.attributes["code.file.path"]) {
|
|
271
272
|
const { file, line } = step.location;
|
|
272
273
|
const relativePath = this.rootDir ? node_path.default.relative(this.rootDir, file) : file;
|
|
@@ -287,14 +288,14 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
287
288
|
}
|
|
288
289
|
const stepSpan = {
|
|
289
290
|
traceId,
|
|
290
|
-
spanId:
|
|
291
|
+
spanId: require_config.generateSpanId(),
|
|
291
292
|
parentSpanId,
|
|
292
293
|
name: TEST_STEP_SPAN_NAME,
|
|
293
294
|
startTime: step.startTime,
|
|
294
295
|
endTime: new Date(step.startTime.getTime() + step.duration),
|
|
295
|
-
attributes
|
|
296
|
-
status: { code: step.error ? 2 : 1 }
|
|
296
|
+
attributes
|
|
297
297
|
};
|
|
298
|
+
if (step.error) stepSpan.status = errorStatus(step.error.message);
|
|
298
299
|
processedSteps.set(stepId, stepSpan);
|
|
299
300
|
if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, stepSpan.spanId, traceId, currentTitlePath, processedSteps, skippedStepIds);
|
|
300
301
|
}
|
|
@@ -330,7 +331,7 @@ function getProjectPlaywrightOpentelemetryConfig(project) {
|
|
|
330
331
|
return project?.use?.playwrightOpentelemetry;
|
|
331
332
|
}
|
|
332
333
|
function getTestConfig(test) {
|
|
333
|
-
return
|
|
334
|
+
return require_config.resolvePlaywrightOpentelemetryConfig(getProjectPlaywrightOpentelemetryConfig(test.parent.project()), { requireDestination: true });
|
|
334
335
|
}
|
|
335
336
|
function getTestOutputDir(test) {
|
|
336
337
|
const outputDir = test.parent.project()?.outputDir;
|
|
@@ -349,41 +350,38 @@ function addDestinationSpans(destinations, spans, options) {
|
|
|
349
350
|
options
|
|
350
351
|
});
|
|
351
352
|
}
|
|
352
|
-
function readTraceContextAttachment(result, testId
|
|
353
|
-
const attachment = result.attachments.find((attachment) => attachment.name ===
|
|
354
|
-
if (!attachment?.body) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
};
|
|
359
|
-
throw new Error(`playwright-opentelemetry fixture missing for test ${testId}: expected ${require_trace_context.TRACE_CONTEXT_ATTACHMENT_NAME} attachment. Import test from "playwright-opentelemetry/fixture" or wrap your base test with createPlaywrightOtelTest().`);
|
|
360
|
-
}
|
|
353
|
+
function readTraceContextAttachment(result, testId) {
|
|
354
|
+
const attachment = result.attachments.find((attachment) => attachment.name === require_config.TRACE_CONTEXT_ATTACHMENT_NAME);
|
|
355
|
+
if (!attachment?.body) return {
|
|
356
|
+
traceId: require_config.generateTraceId(),
|
|
357
|
+
rootSpanId: require_config.generateSpanId()
|
|
358
|
+
};
|
|
361
359
|
let parsed;
|
|
362
360
|
try {
|
|
363
361
|
parsed = JSON.parse(attachment.body.toString("utf-8"));
|
|
364
362
|
} catch (error) {
|
|
365
|
-
throw new Error(`Invalid ${
|
|
363
|
+
throw new Error(`Invalid ${require_config.TRACE_CONTEXT_ATTACHMENT_NAME} attachment for test ${testId}: ${error}`);
|
|
366
364
|
}
|
|
367
|
-
if (!isTraceContextAttachment(parsed)) throw new Error(`Invalid ${
|
|
365
|
+
if (!isTraceContextAttachment(parsed)) throw new Error(`Invalid ${require_config.TRACE_CONTEXT_ATTACHMENT_NAME} attachment for test ${testId}: expected { traceId, rootSpanId }`);
|
|
368
366
|
return parsed;
|
|
369
367
|
}
|
|
370
368
|
function readFixtureSpansAttachment(result, testId) {
|
|
371
|
-
const attachment = result.attachments.find((attachment) => attachment.name ===
|
|
369
|
+
const attachment = result.attachments.find((attachment) => attachment.name === require_config.FIXTURE_SPANS_ATTACHMENT_NAME);
|
|
372
370
|
if (!attachment?.body) return [];
|
|
373
371
|
let parsed;
|
|
374
372
|
try {
|
|
375
373
|
parsed = JSON.parse(attachment.body.toString("utf-8"));
|
|
376
374
|
} catch (error) {
|
|
377
|
-
throw new Error(`Invalid ${
|
|
375
|
+
throw new Error(`Invalid ${require_config.FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: ${error}`);
|
|
378
376
|
}
|
|
379
|
-
if (!isRecord(parsed) || !Array.isArray(parsed.spans)) throw new Error(`Invalid ${
|
|
377
|
+
if (!isRecord(parsed) || !Array.isArray(parsed.spans)) throw new Error(`Invalid ${require_config.FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: expected { spans }`);
|
|
380
378
|
return parsed.spans.map((span, index) => parseFixtureSpan(span, testId, index));
|
|
381
379
|
}
|
|
382
380
|
function parseFixtureSpan(value, testId, index) {
|
|
383
381
|
if (!isRecord(value)) throw invalidFixtureSpanError(testId, index);
|
|
384
382
|
const startTime = parseAttachmentDate(value.startTime);
|
|
385
383
|
const endTime = parseAttachmentDate(value.endTime);
|
|
386
|
-
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);
|
|
384
|
+
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);
|
|
387
385
|
return {
|
|
388
386
|
traceId: value.traceId,
|
|
389
387
|
spanId: value.spanId,
|
|
@@ -392,13 +390,18 @@ function parseFixtureSpan(value, testId, index) {
|
|
|
392
390
|
startTime,
|
|
393
391
|
endTime,
|
|
394
392
|
attributes: value.attributes,
|
|
393
|
+
events: value.events.map((event) => ({
|
|
394
|
+
name: event.name,
|
|
395
|
+
time: parseAttachmentDate(event.time),
|
|
396
|
+
attributes: event.attributes
|
|
397
|
+
})),
|
|
395
398
|
status: value.status,
|
|
396
399
|
kind: typeof value.kind === "number" ? value.kind : void 0,
|
|
397
400
|
serviceName: typeof value.serviceName === "string" ? value.serviceName : void 0
|
|
398
401
|
};
|
|
399
402
|
}
|
|
400
403
|
function invalidFixtureSpanError(testId, index) {
|
|
401
|
-
return /* @__PURE__ */ new Error(`Invalid ${
|
|
404
|
+
return /* @__PURE__ */ new Error(`Invalid ${require_config.FIXTURE_SPANS_ATTACHMENT_NAME} attachment for test ${testId}: invalid span at index ${index}`);
|
|
402
405
|
}
|
|
403
406
|
function parseAttachmentDate(value) {
|
|
404
407
|
if (typeof value !== "string") return;
|
|
@@ -408,10 +411,38 @@ function parseAttachmentDate(value) {
|
|
|
408
411
|
function isSpanStatus(value) {
|
|
409
412
|
return isRecord(value) && typeof value.code === "number";
|
|
410
413
|
}
|
|
414
|
+
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;
|
|
415
|
+
const ORPHANED_ANSI_SGR_PATTERN = /\[(?:\d{1,3};)*\d{1,3}m/g;
|
|
416
|
+
function errorStatus(message) {
|
|
417
|
+
if (!message) return { code: 2 };
|
|
418
|
+
const cleanedMessage = cleanErrorMessage(message);
|
|
419
|
+
return cleanedMessage ? {
|
|
420
|
+
code: 2,
|
|
421
|
+
message: cleanedMessage
|
|
422
|
+
} : { code: 2 };
|
|
423
|
+
}
|
|
424
|
+
function cleanErrorMessage(message) {
|
|
425
|
+
return message.replace(ANSI_ESCAPE_PATTERN, "").replace(ORPHANED_ANSI_SGR_PATTERN, "").replace(/\r\n?/g, "\n").trim();
|
|
426
|
+
}
|
|
427
|
+
function isInternalFixtureStep(step) {
|
|
428
|
+
if (step.category !== "fixture" || !step.location?.file) return false;
|
|
429
|
+
const file = step.location.file.replace(/\\/g, "/");
|
|
430
|
+
return INTERNAL_FIXTURE_FILE_PATTERNS.some((pattern) => pattern.test(file));
|
|
431
|
+
}
|
|
432
|
+
const INTERNAL_FIXTURE_FILE_PATTERNS = [
|
|
433
|
+
/(?:^|\/)dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
|
|
434
|
+
/(?:^|\/)playwright-opentelemetry\/dist\/fixture\.(?:mjs|cjs|js)$/,
|
|
435
|
+
/(?:^|\/)playwright-opentelemetry\/dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
|
|
436
|
+
/(?:^|\/)playwright-opentelemetry\/dist\/fixture\/index\.(?:mjs|cjs|js)$/,
|
|
437
|
+
/(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/playwright-opentelemetry-fixture\.ts$/
|
|
438
|
+
];
|
|
411
439
|
function isSpanAttributes(value) {
|
|
412
440
|
if (!isRecord(value)) return false;
|
|
413
441
|
return Object.values(value).every((attributeValue) => typeof attributeValue === "string" || typeof attributeValue === "number" || typeof attributeValue === "boolean" || Array.isArray(attributeValue) && attributeValue.every((item) => typeof item === "string"));
|
|
414
442
|
}
|
|
443
|
+
function isSpanEvents(value) {
|
|
444
|
+
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)));
|
|
445
|
+
}
|
|
415
446
|
function isRecord(value) {
|
|
416
447
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
417
448
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as generateTraceId, l as sendSpans, n as FIXTURE_SPANS_ATTACHMENT_NAME, o as buildOtlpRequest, r as TRACE_CONTEXT_ATTACHMENT_NAME, s as generateSpanId, t as resolvePlaywrightOpentelemetryConfig } from "./config-DtRqsWLc.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";
|
|
@@ -145,7 +145,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
145
145
|
const testId = test.id;
|
|
146
146
|
const outputDir = getTestOutputDir(test);
|
|
147
147
|
const config = getTestConfig(test);
|
|
148
|
-
const { traceId, rootSpanId: testSpanId } = readTraceContextAttachment(result, testId
|
|
148
|
+
const { traceId, rootSpanId: testSpanId } = readTraceContextAttachment(result, testId);
|
|
149
149
|
const traceAttachment = result.attachments.find((attachment) => attachment.name === "trace" && attachment.contentType === "application/zip" && attachment.path);
|
|
150
150
|
const fixtureSpans = config.storeTraceZip ? readFixtureSpansAttachment(result, testId) : [];
|
|
151
151
|
result.attachments.push({
|
|
@@ -176,15 +176,16 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
176
176
|
if (stepSpan.startTime < minStartTime) minStartTime = stepSpan.startTime;
|
|
177
177
|
if (stepSpan.endTime > maxEndTime) maxEndTime = stepSpan.endTime;
|
|
178
178
|
}
|
|
179
|
-
const
|
|
179
|
+
const span = {
|
|
180
180
|
traceId,
|
|
181
181
|
spanId: testSpanId,
|
|
182
182
|
name: TEST_SPAN_NAME,
|
|
183
183
|
startTime: minStartTime,
|
|
184
184
|
endTime: maxEndTime,
|
|
185
|
-
attributes
|
|
186
|
-
|
|
187
|
-
}
|
|
185
|
+
attributes
|
|
186
|
+
};
|
|
187
|
+
if (result.status !== test.expectedStatus) span.status = { code: 2 };
|
|
188
|
+
const testSpans = [span, ...stepSpans];
|
|
188
189
|
this.spanBatches.push({
|
|
189
190
|
spans: testSpans,
|
|
190
191
|
config
|
|
@@ -250,9 +251,8 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
250
251
|
return { traceZipBlob };
|
|
251
252
|
}
|
|
252
253
|
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
254
|
const stepId = getStepId(test, step);
|
|
255
|
-
if (
|
|
255
|
+
if (isInternalFixtureStep(step)) {
|
|
256
256
|
skippedStepIds.add(stepId);
|
|
257
257
|
processedSteps.delete(stepId);
|
|
258
258
|
if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds);
|
|
@@ -265,6 +265,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
265
265
|
const currentTitlePath = [...parentTitlePath, step.title];
|
|
266
266
|
const existingSpan = processedSteps.get(stepId);
|
|
267
267
|
if (existingSpan) {
|
|
268
|
+
if (step.error) existingSpan.status = errorStatus(step.error.message);
|
|
268
269
|
if (step.location && !existingSpan.attributes["code.file.path"]) {
|
|
269
270
|
const { file, line } = step.location;
|
|
270
271
|
const relativePath = this.rootDir ? path.relative(this.rootDir, file) : file;
|
|
@@ -290,9 +291,9 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
290
291
|
name: TEST_STEP_SPAN_NAME,
|
|
291
292
|
startTime: step.startTime,
|
|
292
293
|
endTime: new Date(step.startTime.getTime() + step.duration),
|
|
293
|
-
attributes
|
|
294
|
-
status: { code: step.error ? 2 : 1 }
|
|
294
|
+
attributes
|
|
295
295
|
};
|
|
296
|
+
if (step.error) stepSpan.status = errorStatus(step.error.message);
|
|
296
297
|
processedSteps.set(stepId, stepSpan);
|
|
297
298
|
if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, stepSpan.spanId, traceId, currentTitlePath, processedSteps, skippedStepIds);
|
|
298
299
|
}
|
|
@@ -347,15 +348,12 @@ function addDestinationSpans(destinations, spans, options) {
|
|
|
347
348
|
options
|
|
348
349
|
});
|
|
349
350
|
}
|
|
350
|
-
function readTraceContextAttachment(result, testId
|
|
351
|
+
function readTraceContextAttachment(result, testId) {
|
|
351
352
|
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
|
-
}
|
|
353
|
+
if (!attachment?.body) return {
|
|
354
|
+
traceId: generateTraceId(),
|
|
355
|
+
rootSpanId: generateSpanId()
|
|
356
|
+
};
|
|
359
357
|
let parsed;
|
|
360
358
|
try {
|
|
361
359
|
parsed = JSON.parse(attachment.body.toString("utf-8"));
|
|
@@ -381,7 +379,7 @@ function parseFixtureSpan(value, testId, index) {
|
|
|
381
379
|
if (!isRecord(value)) throw invalidFixtureSpanError(testId, index);
|
|
382
380
|
const startTime = parseAttachmentDate(value.startTime);
|
|
383
381
|
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);
|
|
382
|
+
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
383
|
return {
|
|
386
384
|
traceId: value.traceId,
|
|
387
385
|
spanId: value.spanId,
|
|
@@ -390,6 +388,11 @@ function parseFixtureSpan(value, testId, index) {
|
|
|
390
388
|
startTime,
|
|
391
389
|
endTime,
|
|
392
390
|
attributes: value.attributes,
|
|
391
|
+
events: value.events.map((event) => ({
|
|
392
|
+
name: event.name,
|
|
393
|
+
time: parseAttachmentDate(event.time),
|
|
394
|
+
attributes: event.attributes
|
|
395
|
+
})),
|
|
393
396
|
status: value.status,
|
|
394
397
|
kind: typeof value.kind === "number" ? value.kind : void 0,
|
|
395
398
|
serviceName: typeof value.serviceName === "string" ? value.serviceName : void 0
|
|
@@ -406,10 +409,38 @@ function parseAttachmentDate(value) {
|
|
|
406
409
|
function isSpanStatus(value) {
|
|
407
410
|
return isRecord(value) && typeof value.code === "number";
|
|
408
411
|
}
|
|
412
|
+
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;
|
|
413
|
+
const ORPHANED_ANSI_SGR_PATTERN = /\[(?:\d{1,3};)*\d{1,3}m/g;
|
|
414
|
+
function errorStatus(message) {
|
|
415
|
+
if (!message) return { code: 2 };
|
|
416
|
+
const cleanedMessage = cleanErrorMessage(message);
|
|
417
|
+
return cleanedMessage ? {
|
|
418
|
+
code: 2,
|
|
419
|
+
message: cleanedMessage
|
|
420
|
+
} : { code: 2 };
|
|
421
|
+
}
|
|
422
|
+
function cleanErrorMessage(message) {
|
|
423
|
+
return message.replace(ANSI_ESCAPE_PATTERN, "").replace(ORPHANED_ANSI_SGR_PATTERN, "").replace(/\r\n?/g, "\n").trim();
|
|
424
|
+
}
|
|
425
|
+
function isInternalFixtureStep(step) {
|
|
426
|
+
if (step.category !== "fixture" || !step.location?.file) return false;
|
|
427
|
+
const file = step.location.file.replace(/\\/g, "/");
|
|
428
|
+
return INTERNAL_FIXTURE_FILE_PATTERNS.some((pattern) => pattern.test(file));
|
|
429
|
+
}
|
|
430
|
+
const INTERNAL_FIXTURE_FILE_PATTERNS = [
|
|
431
|
+
/(?:^|\/)dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
|
|
432
|
+
/(?:^|\/)playwright-opentelemetry\/dist\/fixture\.(?:mjs|cjs|js)$/,
|
|
433
|
+
/(?:^|\/)playwright-opentelemetry\/dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
|
|
434
|
+
/(?:^|\/)playwright-opentelemetry\/dist\/fixture\/index\.(?:mjs|cjs|js)$/,
|
|
435
|
+
/(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/playwright-opentelemetry-fixture\.ts$/
|
|
436
|
+
];
|
|
409
437
|
function isSpanAttributes(value) {
|
|
410
438
|
if (!isRecord(value)) return false;
|
|
411
439
|
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
440
|
}
|
|
441
|
+
function isSpanEvents(value) {
|
|
442
|
+
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)));
|
|
443
|
+
}
|
|
413
444
|
function isRecord(value) {
|
|
414
445
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
415
446
|
}
|
package/dist/reporter.cjs
CHANGED
package/dist/reporter.mjs
CHANGED