playwright-opentelemetry 0.11.1 → 0.12.1
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-Dlhv7Jh9.cjs → config-CE5ph46B.cjs} +94 -22
- package/dist/{config-vP1SpMPF.mjs → config-CoP8kphA.mjs} +65 -23
- package/dist/{config-C_APEwdC.d.cts → config-D-3pnapc.d.cts} +1 -0
- package/dist/{config-C_APEwdC.d.mts → config-D-3pnapc.d.mts} +1 -0
- package/dist/fixture.cjs +130 -4
- package/dist/fixture.d.cts +1 -1
- package/dist/fixture.d.mts +1 -1
- package/dist/fixture.mjs +130 -4
- 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/{reporter-SVZk1e4Y.cjs → reporter-C5uzPmZH.cjs} +38 -12
- package/dist/{reporter-CeXM-i19.mjs → reporter-CeFtIXbG.mjs} +38 -12
- package/dist/reporter.cjs +1 -1
- package/dist/reporter.mjs +1 -1
- package/package.json +1 -1
|
@@ -21,7 +21,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region package.json
|
|
24
|
-
var version = "0.
|
|
24
|
+
var version = "0.12.1";
|
|
25
|
+
const PLAYWRIGHT_TRACE_API_SOURCE_HEADER = "x-playwright-otel-source";
|
|
26
|
+
const PLAYWRIGHT_TRACE_API_SOURCE_REPORTER = "reporter";
|
|
27
|
+
function withPlaywrightTraceApiHeaders(headers) {
|
|
28
|
+
return {
|
|
29
|
+
...headers,
|
|
30
|
+
[PLAYWRIGHT_TRACE_API_SOURCE_HEADER]: PLAYWRIGHT_TRACE_API_SOURCE_REPORTER
|
|
31
|
+
};
|
|
32
|
+
}
|
|
25
33
|
/** Generate a random 32-character hex trace ID. */
|
|
26
34
|
function generateTraceId() {
|
|
27
35
|
return Array.from({ length: 32 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
|
|
@@ -139,6 +147,11 @@ async function sendSpans(spans, options) {
|
|
|
139
147
|
}
|
|
140
148
|
}
|
|
141
149
|
//#endregion
|
|
150
|
+
//#region src/shared/destinations.ts
|
|
151
|
+
function filterRetainedDestinations(destinations, configTrace, shouldRetainTrace) {
|
|
152
|
+
return destinations.filter((destination) => destination.url && shouldRetainTrace(destination.trace ?? configTrace));
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
142
155
|
//#region src/shared/playwright-trace.ts
|
|
143
156
|
function shouldRetainPlaywrightTrace(trace, testInfo) {
|
|
144
157
|
const mode = normalizeTraceMode(trace);
|
|
@@ -154,6 +167,15 @@ function shouldRetainPlaywrightTrace(trace, testInfo) {
|
|
|
154
167
|
case "off": return false;
|
|
155
168
|
}
|
|
156
169
|
}
|
|
170
|
+
function couldRetainPlaywrightTrace(trace, testInfo) {
|
|
171
|
+
const expectedStatus = testInfo?.expectedStatus ?? "passed";
|
|
172
|
+
const failingStatus = expectedStatus === "passed" ? "failed" : "passed";
|
|
173
|
+
return shouldRetainPlaywrightTrace(trace, {
|
|
174
|
+
expectedStatus,
|
|
175
|
+
retry: testInfo?.retry,
|
|
176
|
+
status: failingStatus
|
|
177
|
+
});
|
|
178
|
+
}
|
|
157
179
|
function normalizeTraceMode(trace) {
|
|
158
180
|
const mode = typeof trace === "string" ? trace : trace?.mode ?? "off";
|
|
159
181
|
return mode === "retry-with-trace" ? "on-first-retry" : mode;
|
|
@@ -182,14 +204,37 @@ async function createTestTraceContext(testInfo) {
|
|
|
182
204
|
});
|
|
183
205
|
return traceContext;
|
|
184
206
|
}
|
|
207
|
+
async function registerExpectedTrace(traceContext, config, options) {
|
|
208
|
+
const couldRetainTrace = (trace) => couldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo);
|
|
209
|
+
const destinations = filterRetainedDestinations(config.playwrightTraceApiDestinations, config.trace, couldRetainTrace);
|
|
210
|
+
if (destinations.length === 0) return;
|
|
211
|
+
const failures = await Promise.all(destinations.map(async (destination) => {
|
|
212
|
+
try {
|
|
213
|
+
const response = await fetch(`${destination.url}/playwright-otel-reporter/v1/expected-trace`, {
|
|
214
|
+
method: "PUT",
|
|
215
|
+
headers: withPlaywrightTraceApiHeaders({
|
|
216
|
+
...destination.headers,
|
|
217
|
+
"x-trace-id": traceContext.traceId
|
|
218
|
+
})
|
|
219
|
+
});
|
|
220
|
+
if (!response.ok) {
|
|
221
|
+
const error = await response.text();
|
|
222
|
+
return `${destination.url}: ${response.status} ${response.statusText}, ${error}`;
|
|
223
|
+
}
|
|
224
|
+
} catch (error) {
|
|
225
|
+
return `${destination.url}: ${error instanceof Error ? error.message : String(error)}`;
|
|
226
|
+
}
|
|
227
|
+
}));
|
|
228
|
+
for (const failure of failures) if (failure) console.warn(`Failed to register expected Playwright trace ${traceContext.traceId}: ${failure}`);
|
|
229
|
+
}
|
|
185
230
|
async function flushFixtureSpans(traceContext, config, options) {
|
|
186
231
|
if (traceContext.spans.length === 0) return;
|
|
187
|
-
|
|
188
|
-
if (config.storeTraceZip && options.testInfo) await options.testInfo.attach(FIXTURE_SPANS_ATTACHMENT_NAME, {
|
|
232
|
+
const shouldRetainTrace = (trace) => shouldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo);
|
|
233
|
+
if (config.storeTraceZip && options.testInfo && shouldRetainTrace(config.trace)) await options.testInfo.attach(FIXTURE_SPANS_ATTACHMENT_NAME, {
|
|
189
234
|
body: JSON.stringify({ spans: traceContext.spans.map(serializeSpanForAttachment) }),
|
|
190
235
|
contentType: "application/json"
|
|
191
236
|
});
|
|
192
|
-
const destinations = fixtureSpanDestinations(config);
|
|
237
|
+
const destinations = fixtureSpanDestinations(config, shouldRetainTrace);
|
|
193
238
|
if (destinations.length === 0) return;
|
|
194
239
|
await Promise.all(destinations.map((destination) => sendSpans(traceContext.spans, {
|
|
195
240
|
tracesEndpoint: destination.tracesEndpoint,
|
|
@@ -209,22 +254,16 @@ function serializeSpanForAttachment(span) {
|
|
|
209
254
|
}))
|
|
210
255
|
};
|
|
211
256
|
}
|
|
212
|
-
function fixtureSpanDestinations(config) {
|
|
257
|
+
function fixtureSpanDestinations(config, shouldRetainTrace) {
|
|
213
258
|
const destinations = [];
|
|
214
|
-
for (const destination of config.playwrightTraceApiDestinations) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (!destination.url) continue;
|
|
223
|
-
destinations.push({
|
|
224
|
-
tracesEndpoint: destination.url,
|
|
225
|
-
headers: destination.headers
|
|
226
|
-
});
|
|
227
|
-
}
|
|
259
|
+
for (const destination of filterRetainedDestinations(config.playwrightTraceApiDestinations, config.trace, shouldRetainTrace)) destinations.push({
|
|
260
|
+
tracesEndpoint: `${destination.url}/v1/traces`,
|
|
261
|
+
headers: withPlaywrightTraceApiHeaders(destination.headers)
|
|
262
|
+
});
|
|
263
|
+
for (const destination of filterRetainedDestinations(config.otlpDestinations, config.trace, shouldRetainTrace)) destinations.push({
|
|
264
|
+
tracesEndpoint: destination.url,
|
|
265
|
+
headers: destination.headers
|
|
266
|
+
});
|
|
228
267
|
return destinations;
|
|
229
268
|
}
|
|
230
269
|
//#endregion
|
|
@@ -262,15 +301,18 @@ function resolveDestinationKind(options) {
|
|
|
262
301
|
let primaryDestination;
|
|
263
302
|
if (envEndpoint) primaryDestination = {
|
|
264
303
|
url: envEndpoint,
|
|
265
|
-
headers: parseOtlpHeaders(envHeaders)
|
|
304
|
+
headers: parseOtlpHeaders(envHeaders),
|
|
305
|
+
trace: null
|
|
266
306
|
};
|
|
267
307
|
else if (options.singular) primaryDestination = {
|
|
268
308
|
url: options.singular.url,
|
|
269
|
-
headers: { ...options.singular.headers }
|
|
309
|
+
headers: { ...options.singular.headers },
|
|
310
|
+
trace: options.singular.trace ?? null
|
|
270
311
|
};
|
|
271
312
|
const additionalDestinations = (options.plural ?? []).map((destination) => ({
|
|
272
313
|
url: destination.url,
|
|
273
|
-
headers: { ...destination.headers }
|
|
314
|
+
headers: { ...destination.headers },
|
|
315
|
+
trace: destination.trace ?? null
|
|
274
316
|
}));
|
|
275
317
|
return primaryDestination ? [primaryDestination, ...additionalDestinations] : additionalDestinations;
|
|
276
318
|
}
|
|
@@ -296,6 +338,18 @@ Object.defineProperty(exports, "FIXTURE_SPANS_ATTACHMENT_NAME", {
|
|
|
296
338
|
return FIXTURE_SPANS_ATTACHMENT_NAME;
|
|
297
339
|
}
|
|
298
340
|
});
|
|
341
|
+
Object.defineProperty(exports, "PLAYWRIGHT_TRACE_API_SOURCE_HEADER", {
|
|
342
|
+
enumerable: true,
|
|
343
|
+
get: function() {
|
|
344
|
+
return PLAYWRIGHT_TRACE_API_SOURCE_HEADER;
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
Object.defineProperty(exports, "PLAYWRIGHT_TRACE_API_SOURCE_REPORTER", {
|
|
348
|
+
enumerable: true,
|
|
349
|
+
get: function() {
|
|
350
|
+
return PLAYWRIGHT_TRACE_API_SOURCE_REPORTER;
|
|
351
|
+
}
|
|
352
|
+
});
|
|
299
353
|
Object.defineProperty(exports, "TRACE_CONTEXT_ATTACHMENT_NAME", {
|
|
300
354
|
enumerable: true,
|
|
301
355
|
get: function() {
|
|
@@ -320,6 +374,12 @@ Object.defineProperty(exports, "createTestTraceContext", {
|
|
|
320
374
|
return createTestTraceContext;
|
|
321
375
|
}
|
|
322
376
|
});
|
|
377
|
+
Object.defineProperty(exports, "filterRetainedDestinations", {
|
|
378
|
+
enumerable: true,
|
|
379
|
+
get: function() {
|
|
380
|
+
return filterRetainedDestinations;
|
|
381
|
+
}
|
|
382
|
+
});
|
|
323
383
|
Object.defineProperty(exports, "flushFixtureSpans", {
|
|
324
384
|
enumerable: true,
|
|
325
385
|
get: function() {
|
|
@@ -338,6 +398,12 @@ Object.defineProperty(exports, "generateTraceId", {
|
|
|
338
398
|
return generateTraceId;
|
|
339
399
|
}
|
|
340
400
|
});
|
|
401
|
+
Object.defineProperty(exports, "registerExpectedTrace", {
|
|
402
|
+
enumerable: true,
|
|
403
|
+
get: function() {
|
|
404
|
+
return registerExpectedTrace;
|
|
405
|
+
}
|
|
406
|
+
});
|
|
341
407
|
Object.defineProperty(exports, "resolvePlaywrightOpentelemetryConfig", {
|
|
342
408
|
enumerable: true,
|
|
343
409
|
get: function() {
|
|
@@ -356,3 +422,9 @@ Object.defineProperty(exports, "shouldRetainPlaywrightTrace", {
|
|
|
356
422
|
return shouldRetainPlaywrightTrace;
|
|
357
423
|
}
|
|
358
424
|
});
|
|
425
|
+
Object.defineProperty(exports, "withPlaywrightTraceApiHeaders", {
|
|
426
|
+
enumerable: true,
|
|
427
|
+
get: function() {
|
|
428
|
+
return withPlaywrightTraceApiHeaders;
|
|
429
|
+
}
|
|
430
|
+
});
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
//#region package.json
|
|
2
|
-
var version = "0.
|
|
2
|
+
var version = "0.12.1";
|
|
3
|
+
const PLAYWRIGHT_TRACE_API_SOURCE_HEADER = "x-playwright-otel-source";
|
|
4
|
+
const PLAYWRIGHT_TRACE_API_SOURCE_REPORTER = "reporter";
|
|
5
|
+
function withPlaywrightTraceApiHeaders(headers) {
|
|
6
|
+
return {
|
|
7
|
+
...headers,
|
|
8
|
+
[PLAYWRIGHT_TRACE_API_SOURCE_HEADER]: PLAYWRIGHT_TRACE_API_SOURCE_REPORTER
|
|
9
|
+
};
|
|
10
|
+
}
|
|
3
11
|
/** Generate a random 32-character hex trace ID. */
|
|
4
12
|
function generateTraceId() {
|
|
5
13
|
return Array.from({ length: 32 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
|
|
@@ -117,6 +125,11 @@ async function sendSpans(spans, options) {
|
|
|
117
125
|
}
|
|
118
126
|
}
|
|
119
127
|
//#endregion
|
|
128
|
+
//#region src/shared/destinations.ts
|
|
129
|
+
function filterRetainedDestinations(destinations, configTrace, shouldRetainTrace) {
|
|
130
|
+
return destinations.filter((destination) => destination.url && shouldRetainTrace(destination.trace ?? configTrace));
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
120
133
|
//#region src/shared/playwright-trace.ts
|
|
121
134
|
function shouldRetainPlaywrightTrace(trace, testInfo) {
|
|
122
135
|
const mode = normalizeTraceMode(trace);
|
|
@@ -132,6 +145,15 @@ function shouldRetainPlaywrightTrace(trace, testInfo) {
|
|
|
132
145
|
case "off": return false;
|
|
133
146
|
}
|
|
134
147
|
}
|
|
148
|
+
function couldRetainPlaywrightTrace(trace, testInfo) {
|
|
149
|
+
const expectedStatus = testInfo?.expectedStatus ?? "passed";
|
|
150
|
+
const failingStatus = expectedStatus === "passed" ? "failed" : "passed";
|
|
151
|
+
return shouldRetainPlaywrightTrace(trace, {
|
|
152
|
+
expectedStatus,
|
|
153
|
+
retry: testInfo?.retry,
|
|
154
|
+
status: failingStatus
|
|
155
|
+
});
|
|
156
|
+
}
|
|
135
157
|
function normalizeTraceMode(trace) {
|
|
136
158
|
const mode = typeof trace === "string" ? trace : trace?.mode ?? "off";
|
|
137
159
|
return mode === "retry-with-trace" ? "on-first-retry" : mode;
|
|
@@ -160,14 +182,37 @@ async function createTestTraceContext(testInfo) {
|
|
|
160
182
|
});
|
|
161
183
|
return traceContext;
|
|
162
184
|
}
|
|
185
|
+
async function registerExpectedTrace(traceContext, config, options) {
|
|
186
|
+
const couldRetainTrace = (trace) => couldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo);
|
|
187
|
+
const destinations = filterRetainedDestinations(config.playwrightTraceApiDestinations, config.trace, couldRetainTrace);
|
|
188
|
+
if (destinations.length === 0) return;
|
|
189
|
+
const failures = await Promise.all(destinations.map(async (destination) => {
|
|
190
|
+
try {
|
|
191
|
+
const response = await fetch(`${destination.url}/playwright-otel-reporter/v1/expected-trace`, {
|
|
192
|
+
method: "PUT",
|
|
193
|
+
headers: withPlaywrightTraceApiHeaders({
|
|
194
|
+
...destination.headers,
|
|
195
|
+
"x-trace-id": traceContext.traceId
|
|
196
|
+
})
|
|
197
|
+
});
|
|
198
|
+
if (!response.ok) {
|
|
199
|
+
const error = await response.text();
|
|
200
|
+
return `${destination.url}: ${response.status} ${response.statusText}, ${error}`;
|
|
201
|
+
}
|
|
202
|
+
} catch (error) {
|
|
203
|
+
return `${destination.url}: ${error instanceof Error ? error.message : String(error)}`;
|
|
204
|
+
}
|
|
205
|
+
}));
|
|
206
|
+
for (const failure of failures) if (failure) console.warn(`Failed to register expected Playwright trace ${traceContext.traceId}: ${failure}`);
|
|
207
|
+
}
|
|
163
208
|
async function flushFixtureSpans(traceContext, config, options) {
|
|
164
209
|
if (traceContext.spans.length === 0) return;
|
|
165
|
-
|
|
166
|
-
if (config.storeTraceZip && options.testInfo) await options.testInfo.attach(FIXTURE_SPANS_ATTACHMENT_NAME, {
|
|
210
|
+
const shouldRetainTrace = (trace) => shouldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo);
|
|
211
|
+
if (config.storeTraceZip && options.testInfo && shouldRetainTrace(config.trace)) await options.testInfo.attach(FIXTURE_SPANS_ATTACHMENT_NAME, {
|
|
167
212
|
body: JSON.stringify({ spans: traceContext.spans.map(serializeSpanForAttachment) }),
|
|
168
213
|
contentType: "application/json"
|
|
169
214
|
});
|
|
170
|
-
const destinations = fixtureSpanDestinations(config);
|
|
215
|
+
const destinations = fixtureSpanDestinations(config, shouldRetainTrace);
|
|
171
216
|
if (destinations.length === 0) return;
|
|
172
217
|
await Promise.all(destinations.map((destination) => sendSpans(traceContext.spans, {
|
|
173
218
|
tracesEndpoint: destination.tracesEndpoint,
|
|
@@ -187,22 +232,16 @@ function serializeSpanForAttachment(span) {
|
|
|
187
232
|
}))
|
|
188
233
|
};
|
|
189
234
|
}
|
|
190
|
-
function fixtureSpanDestinations(config) {
|
|
235
|
+
function fixtureSpanDestinations(config, shouldRetainTrace) {
|
|
191
236
|
const destinations = [];
|
|
192
|
-
for (const destination of config.playwrightTraceApiDestinations) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (!destination.url) continue;
|
|
201
|
-
destinations.push({
|
|
202
|
-
tracesEndpoint: destination.url,
|
|
203
|
-
headers: destination.headers
|
|
204
|
-
});
|
|
205
|
-
}
|
|
237
|
+
for (const destination of filterRetainedDestinations(config.playwrightTraceApiDestinations, config.trace, shouldRetainTrace)) destinations.push({
|
|
238
|
+
tracesEndpoint: `${destination.url}/v1/traces`,
|
|
239
|
+
headers: withPlaywrightTraceApiHeaders(destination.headers)
|
|
240
|
+
});
|
|
241
|
+
for (const destination of filterRetainedDestinations(config.otlpDestinations, config.trace, shouldRetainTrace)) destinations.push({
|
|
242
|
+
tracesEndpoint: destination.url,
|
|
243
|
+
headers: destination.headers
|
|
244
|
+
});
|
|
206
245
|
return destinations;
|
|
207
246
|
}
|
|
208
247
|
//#endregion
|
|
@@ -240,15 +279,18 @@ function resolveDestinationKind(options) {
|
|
|
240
279
|
let primaryDestination;
|
|
241
280
|
if (envEndpoint) primaryDestination = {
|
|
242
281
|
url: envEndpoint,
|
|
243
|
-
headers: parseOtlpHeaders(envHeaders)
|
|
282
|
+
headers: parseOtlpHeaders(envHeaders),
|
|
283
|
+
trace: null
|
|
244
284
|
};
|
|
245
285
|
else if (options.singular) primaryDestination = {
|
|
246
286
|
url: options.singular.url,
|
|
247
|
-
headers: { ...options.singular.headers }
|
|
287
|
+
headers: { ...options.singular.headers },
|
|
288
|
+
trace: options.singular.trace ?? null
|
|
248
289
|
};
|
|
249
290
|
const additionalDestinations = (options.plural ?? []).map((destination) => ({
|
|
250
291
|
url: destination.url,
|
|
251
|
-
headers: { ...destination.headers }
|
|
292
|
+
headers: { ...destination.headers },
|
|
293
|
+
trace: destination.trace ?? null
|
|
252
294
|
}));
|
|
253
295
|
return primaryDestination ? [primaryDestination, ...additionalDestinations] : additionalDestinations;
|
|
254
296
|
}
|
|
@@ -262,4 +304,4 @@ function getConfigurationErrorMessage() {
|
|
|
262
304
|
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\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: {\n url: 'http://localhost:4317/v1/traces',\n headers: {\n Authorization: 'Bearer YOUR_TOKEN',\n },\n },\n },\n },\n reporter: [['playwright-opentelemetry/reporter']],\n});\n\nNote: Environment variables take precedence over use.playwrightOpentelemetry options.\n";
|
|
263
305
|
}
|
|
264
306
|
//#endregion
|
|
265
|
-
export { createTestTraceContext as a,
|
|
307
|
+
export { createTestTraceContext as a, shouldRetainPlaywrightTrace as c, PLAYWRIGHT_TRACE_API_SOURCE_REPORTER as d, buildOtlpRequest as f, withPlaywrightTraceApiHeaders as g, sendSpans as h, TRACE_CONTEXT_ATTACHMENT_NAME as i, filterRetainedDestinations as l, generateTraceId as m, BROWSER_SERVICE_NAME as n, flushFixtureSpans as o, generateSpanId as p, FIXTURE_SPANS_ATTACHMENT_NAME as r, registerExpectedTrace as s, resolvePlaywrightOpentelemetryConfig as t, PLAYWRIGHT_TRACE_API_SOURCE_HEADER as u };
|
|
@@ -12,6 +12,7 @@ type PlaywrightTraceOption = PlaywrightTraceMode | "retry-with-trace" | {
|
|
|
12
12
|
type PlaywrightOpentelemetryDestination = {
|
|
13
13
|
url: string;
|
|
14
14
|
headers?: Record<string, string>;
|
|
15
|
+
trace?: PlaywrightTraceOption;
|
|
15
16
|
};
|
|
16
17
|
interface PlaywrightOpentelemetryConfig {
|
|
17
18
|
otlpEndpoint?: PlaywrightOpentelemetryDestination;
|
|
@@ -12,6 +12,7 @@ type PlaywrightTraceOption = PlaywrightTraceMode | "retry-with-trace" | {
|
|
|
12
12
|
type PlaywrightOpentelemetryDestination = {
|
|
13
13
|
url: string;
|
|
14
14
|
headers?: Record<string, string>;
|
|
15
|
+
trace?: PlaywrightTraceOption;
|
|
15
16
|
};
|
|
16
17
|
interface PlaywrightOpentelemetryConfig {
|
|
17
18
|
otlpEndpoint?: PlaywrightOpentelemetryDestination;
|
package/dist/fixture.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_config = require("./config-
|
|
2
|
+
const require_config = require("./config-CE5ph46B.cjs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
node_path = require_config.__toESM(node_path, 1);
|
|
5
5
|
let _playwright_test = require("@playwright/test");
|
|
6
6
|
//#region src/fixture/browser-page-tracker.ts
|
|
7
7
|
const BROWSER_PAGE_SPAN_NAME = "browser.page";
|
|
8
8
|
const BROWSER_ROUTE_SPAN_NAME = "browser.route";
|
|
9
|
-
const SPAN_STATUS_CODE_UNSET$
|
|
9
|
+
const SPAN_STATUS_CODE_UNSET$3 = 0;
|
|
10
10
|
var BrowserPageTracker = class {
|
|
11
11
|
traceContext;
|
|
12
12
|
nextPageId = 1;
|
|
@@ -168,7 +168,7 @@ var BrowserPageTracker = class {
|
|
|
168
168
|
name,
|
|
169
169
|
startTime,
|
|
170
170
|
endTime: startTime,
|
|
171
|
-
status: { code: SPAN_STATUS_CODE_UNSET$
|
|
171
|
+
status: { code: SPAN_STATUS_CODE_UNSET$3 },
|
|
172
172
|
attributes: pageAttributes({
|
|
173
173
|
pageId,
|
|
174
174
|
url,
|
|
@@ -263,6 +263,125 @@ async function propagateRouteTraceHeaders({ route, request, traceId, spanId }) {
|
|
|
263
263
|
} });
|
|
264
264
|
}
|
|
265
265
|
//#endregion
|
|
266
|
+
//#region src/fixture/api-request-capture.ts
|
|
267
|
+
const SPAN_KIND_CLIENT$2 = 3;
|
|
268
|
+
const SPAN_STATUS_CODE_UNSET$2 = 0;
|
|
269
|
+
const SPAN_STATUS_CODE_ERROR$2 = 2;
|
|
270
|
+
const CAPTURED_METHODS = new Set([
|
|
271
|
+
"delete",
|
|
272
|
+
"fetch",
|
|
273
|
+
"get",
|
|
274
|
+
"head",
|
|
275
|
+
"patch",
|
|
276
|
+
"post",
|
|
277
|
+
"put"
|
|
278
|
+
]);
|
|
279
|
+
function createCapturedApiRequestContext(request, traceContext) {
|
|
280
|
+
return new Proxy(request, { get(target, property, receiver) {
|
|
281
|
+
const value = Reflect.get(target, property, receiver);
|
|
282
|
+
if (typeof property !== "string" || !CAPTURED_METHODS.has(property)) return value;
|
|
283
|
+
if (typeof value !== "function") return value;
|
|
284
|
+
return async (...args) => {
|
|
285
|
+
const startTime = /* @__PURE__ */ new Date();
|
|
286
|
+
try {
|
|
287
|
+
const response = await value.apply(target, args);
|
|
288
|
+
traceContext.addSpan(createApiRequestSpan({
|
|
289
|
+
methodName: property,
|
|
290
|
+
args,
|
|
291
|
+
traceContext,
|
|
292
|
+
startTime,
|
|
293
|
+
endTime: /* @__PURE__ */ new Date(),
|
|
294
|
+
statusCode: response.status()
|
|
295
|
+
}));
|
|
296
|
+
return response;
|
|
297
|
+
} catch (error) {
|
|
298
|
+
traceContext.addSpan(createApiRequestSpan({
|
|
299
|
+
methodName: property,
|
|
300
|
+
args,
|
|
301
|
+
traceContext,
|
|
302
|
+
startTime,
|
|
303
|
+
endTime: /* @__PURE__ */ new Date(),
|
|
304
|
+
error
|
|
305
|
+
}));
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
} });
|
|
310
|
+
}
|
|
311
|
+
function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, error }) {
|
|
312
|
+
const method = getRequestMethod(methodName, args);
|
|
313
|
+
const attributes = createHttpAttributes$1({
|
|
314
|
+
method,
|
|
315
|
+
url: getRequestUrl(args[0]),
|
|
316
|
+
statusCode,
|
|
317
|
+
error
|
|
318
|
+
});
|
|
319
|
+
const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
|
|
320
|
+
return {
|
|
321
|
+
traceId: traceContext.traceId,
|
|
322
|
+
spanId: require_config.generateSpanId(),
|
|
323
|
+
parentSpanId: traceContext.rootSpanId,
|
|
324
|
+
name: `HTTP ${method}`,
|
|
325
|
+
kind: SPAN_KIND_CLIENT$2,
|
|
326
|
+
startTime,
|
|
327
|
+
endTime,
|
|
328
|
+
status: failed ? {
|
|
329
|
+
code: SPAN_STATUS_CODE_ERROR$2,
|
|
330
|
+
message: errorMessage$1(error)
|
|
331
|
+
} : { code: SPAN_STATUS_CODE_UNSET$2 },
|
|
332
|
+
attributes,
|
|
333
|
+
events: []
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function createHttpAttributes$1({ method, url, statusCode, error }) {
|
|
337
|
+
const attributes = {
|
|
338
|
+
"http.request.method": method,
|
|
339
|
+
"http.resource.type": "fetch",
|
|
340
|
+
"playwright.request.api": true,
|
|
341
|
+
"url.full": url
|
|
342
|
+
};
|
|
343
|
+
try {
|
|
344
|
+
const parsedUrl = new URL(url);
|
|
345
|
+
attributes["url.path"] = parsedUrl.pathname;
|
|
346
|
+
attributes["server.address"] = parsedUrl.hostname;
|
|
347
|
+
attributes["server.port"] = serverPort$1(parsedUrl);
|
|
348
|
+
if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
|
|
349
|
+
} catch {}
|
|
350
|
+
if (statusCode !== void 0) {
|
|
351
|
+
attributes["http.response.status_code"] = statusCode;
|
|
352
|
+
if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
|
|
353
|
+
} else if (error !== void 0) attributes["error.type"] = errorType$1(error);
|
|
354
|
+
return attributes;
|
|
355
|
+
}
|
|
356
|
+
function getRequestMethod(methodName, args) {
|
|
357
|
+
const options = getOptions(args[1]);
|
|
358
|
+
if (methodName === "fetch") {
|
|
359
|
+
const input = args[0];
|
|
360
|
+
return (options.method ?? (input instanceof Request ? input.method : void 0) ?? "GET").toUpperCase();
|
|
361
|
+
}
|
|
362
|
+
return methodName.toUpperCase();
|
|
363
|
+
}
|
|
364
|
+
function getRequestUrl(input) {
|
|
365
|
+
if (input instanceof Request) return input.url;
|
|
366
|
+
return String(input);
|
|
367
|
+
}
|
|
368
|
+
function getOptions(value) {
|
|
369
|
+
if (typeof value !== "object" || value === null || !("method" in value)) return {};
|
|
370
|
+
const method = value.method;
|
|
371
|
+
return typeof method === "string" ? { method } : {};
|
|
372
|
+
}
|
|
373
|
+
function serverPort$1(url) {
|
|
374
|
+
if (url.port) return Number.parseInt(url.port, 10);
|
|
375
|
+
return url.protocol === "https:" ? 443 : 80;
|
|
376
|
+
}
|
|
377
|
+
function errorType$1(error) {
|
|
378
|
+
if (error instanceof Error && error.name) return error.name;
|
|
379
|
+
return "Error";
|
|
380
|
+
}
|
|
381
|
+
function errorMessage$1(error) {
|
|
382
|
+
return error instanceof Error && error.message ? error.message : void 0;
|
|
383
|
+
}
|
|
384
|
+
//#endregion
|
|
266
385
|
//#region src/fixture/reporter-config.ts
|
|
267
386
|
const PLAYWRIGHT_OPENTELEMETRY_REPORTER_NAMES = new Set(["playwright-opentelemetry", "playwright-opentelemetry/reporter"]);
|
|
268
387
|
const PLAYWRIGHT_OPENTELEMETRY_REPORTER_PATHS = ["dist/reporter.mjs", "dist/reporter.cjs"];
|
|
@@ -530,9 +649,13 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
530
649
|
testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
|
|
531
650
|
const config = require_config.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
532
651
|
const traceContext = await require_config.createTestTraceContext(testInfo);
|
|
652
|
+
await require_config.registerExpectedTrace(traceContext, config, {
|
|
653
|
+
trace,
|
|
654
|
+
testInfo
|
|
655
|
+
});
|
|
533
656
|
await runWithTestFetchCapture(traceContext, () => use(traceContext));
|
|
534
657
|
await require_config.flushFixtureSpans(traceContext, config, {
|
|
535
|
-
trace
|
|
658
|
+
trace,
|
|
536
659
|
testInfo
|
|
537
660
|
});
|
|
538
661
|
}, { auto: true }],
|
|
@@ -541,6 +664,9 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
541
664
|
await use(tracker);
|
|
542
665
|
tracker.finishAll();
|
|
543
666
|
}, { auto: true }],
|
|
667
|
+
request: async ({ request, testTraceContext }, use) => {
|
|
668
|
+
await use(createCapturedApiRequestContext(request, testTraceContext));
|
|
669
|
+
},
|
|
544
670
|
context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker }, use) => {
|
|
545
671
|
const config = require_config.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
546
672
|
context.route("**", async (route, request) => {
|
package/dist/fixture.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
1
|
+
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-D-3pnapc.cjs";
|
|
2
2
|
import { n as SpanEvent, t as Span } from "./otel-D0ztpic2.cjs";
|
|
3
3
|
import { ConsoleMessage, Page, Request } from "@playwright/test";
|
|
4
4
|
export * from "@playwright/test";
|
package/dist/fixture.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
1
|
+
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-D-3pnapc.mjs";
|
|
2
2
|
import { n as SpanEvent, t as Span } from "./otel-D0ztpic2.mjs";
|
|
3
3
|
import { ConsoleMessage, Page, Request } from "@playwright/test";
|
|
4
4
|
export * from "@playwright/test";
|
package/dist/fixture.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { a as createTestTraceContext,
|
|
1
|
+
import { a as createTestTraceContext, n as BROWSER_SERVICE_NAME, o as flushFixtureSpans, p as generateSpanId, s as registerExpectedTrace, t as resolvePlaywrightOpentelemetryConfig } from "./config-CoP8kphA.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { test as test$1 } from "@playwright/test";
|
|
4
4
|
export * from "@playwright/test";
|
|
5
5
|
//#region src/fixture/browser-page-tracker.ts
|
|
6
6
|
const BROWSER_PAGE_SPAN_NAME = "browser.page";
|
|
7
7
|
const BROWSER_ROUTE_SPAN_NAME = "browser.route";
|
|
8
|
-
const SPAN_STATUS_CODE_UNSET$
|
|
8
|
+
const SPAN_STATUS_CODE_UNSET$3 = 0;
|
|
9
9
|
var BrowserPageTracker = class {
|
|
10
10
|
traceContext;
|
|
11
11
|
nextPageId = 1;
|
|
@@ -167,7 +167,7 @@ var BrowserPageTracker = class {
|
|
|
167
167
|
name,
|
|
168
168
|
startTime,
|
|
169
169
|
endTime: startTime,
|
|
170
|
-
status: { code: SPAN_STATUS_CODE_UNSET$
|
|
170
|
+
status: { code: SPAN_STATUS_CODE_UNSET$3 },
|
|
171
171
|
attributes: pageAttributes({
|
|
172
172
|
pageId,
|
|
173
173
|
url,
|
|
@@ -262,6 +262,125 @@ async function propagateRouteTraceHeaders({ route, request, traceId, spanId }) {
|
|
|
262
262
|
} });
|
|
263
263
|
}
|
|
264
264
|
//#endregion
|
|
265
|
+
//#region src/fixture/api-request-capture.ts
|
|
266
|
+
const SPAN_KIND_CLIENT$2 = 3;
|
|
267
|
+
const SPAN_STATUS_CODE_UNSET$2 = 0;
|
|
268
|
+
const SPAN_STATUS_CODE_ERROR$2 = 2;
|
|
269
|
+
const CAPTURED_METHODS = new Set([
|
|
270
|
+
"delete",
|
|
271
|
+
"fetch",
|
|
272
|
+
"get",
|
|
273
|
+
"head",
|
|
274
|
+
"patch",
|
|
275
|
+
"post",
|
|
276
|
+
"put"
|
|
277
|
+
]);
|
|
278
|
+
function createCapturedApiRequestContext(request, traceContext) {
|
|
279
|
+
return new Proxy(request, { get(target, property, receiver) {
|
|
280
|
+
const value = Reflect.get(target, property, receiver);
|
|
281
|
+
if (typeof property !== "string" || !CAPTURED_METHODS.has(property)) return value;
|
|
282
|
+
if (typeof value !== "function") return value;
|
|
283
|
+
return async (...args) => {
|
|
284
|
+
const startTime = /* @__PURE__ */ new Date();
|
|
285
|
+
try {
|
|
286
|
+
const response = await value.apply(target, args);
|
|
287
|
+
traceContext.addSpan(createApiRequestSpan({
|
|
288
|
+
methodName: property,
|
|
289
|
+
args,
|
|
290
|
+
traceContext,
|
|
291
|
+
startTime,
|
|
292
|
+
endTime: /* @__PURE__ */ new Date(),
|
|
293
|
+
statusCode: response.status()
|
|
294
|
+
}));
|
|
295
|
+
return response;
|
|
296
|
+
} catch (error) {
|
|
297
|
+
traceContext.addSpan(createApiRequestSpan({
|
|
298
|
+
methodName: property,
|
|
299
|
+
args,
|
|
300
|
+
traceContext,
|
|
301
|
+
startTime,
|
|
302
|
+
endTime: /* @__PURE__ */ new Date(),
|
|
303
|
+
error
|
|
304
|
+
}));
|
|
305
|
+
throw error;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
} });
|
|
309
|
+
}
|
|
310
|
+
function createApiRequestSpan({ methodName, args, traceContext, startTime, endTime, statusCode, error }) {
|
|
311
|
+
const method = getRequestMethod(methodName, args);
|
|
312
|
+
const attributes = createHttpAttributes$1({
|
|
313
|
+
method,
|
|
314
|
+
url: getRequestUrl(args[0]),
|
|
315
|
+
statusCode,
|
|
316
|
+
error
|
|
317
|
+
});
|
|
318
|
+
const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
|
|
319
|
+
return {
|
|
320
|
+
traceId: traceContext.traceId,
|
|
321
|
+
spanId: generateSpanId(),
|
|
322
|
+
parentSpanId: traceContext.rootSpanId,
|
|
323
|
+
name: `HTTP ${method}`,
|
|
324
|
+
kind: SPAN_KIND_CLIENT$2,
|
|
325
|
+
startTime,
|
|
326
|
+
endTime,
|
|
327
|
+
status: failed ? {
|
|
328
|
+
code: SPAN_STATUS_CODE_ERROR$2,
|
|
329
|
+
message: errorMessage$1(error)
|
|
330
|
+
} : { code: SPAN_STATUS_CODE_UNSET$2 },
|
|
331
|
+
attributes,
|
|
332
|
+
events: []
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function createHttpAttributes$1({ method, url, statusCode, error }) {
|
|
336
|
+
const attributes = {
|
|
337
|
+
"http.request.method": method,
|
|
338
|
+
"http.resource.type": "fetch",
|
|
339
|
+
"playwright.request.api": true,
|
|
340
|
+
"url.full": url
|
|
341
|
+
};
|
|
342
|
+
try {
|
|
343
|
+
const parsedUrl = new URL(url);
|
|
344
|
+
attributes["url.path"] = parsedUrl.pathname;
|
|
345
|
+
attributes["server.address"] = parsedUrl.hostname;
|
|
346
|
+
attributes["server.port"] = serverPort$1(parsedUrl);
|
|
347
|
+
if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
|
|
348
|
+
} catch {}
|
|
349
|
+
if (statusCode !== void 0) {
|
|
350
|
+
attributes["http.response.status_code"] = statusCode;
|
|
351
|
+
if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
|
|
352
|
+
} else if (error !== void 0) attributes["error.type"] = errorType$1(error);
|
|
353
|
+
return attributes;
|
|
354
|
+
}
|
|
355
|
+
function getRequestMethod(methodName, args) {
|
|
356
|
+
const options = getOptions(args[1]);
|
|
357
|
+
if (methodName === "fetch") {
|
|
358
|
+
const input = args[0];
|
|
359
|
+
return (options.method ?? (input instanceof Request ? input.method : void 0) ?? "GET").toUpperCase();
|
|
360
|
+
}
|
|
361
|
+
return methodName.toUpperCase();
|
|
362
|
+
}
|
|
363
|
+
function getRequestUrl(input) {
|
|
364
|
+
if (input instanceof Request) return input.url;
|
|
365
|
+
return String(input);
|
|
366
|
+
}
|
|
367
|
+
function getOptions(value) {
|
|
368
|
+
if (typeof value !== "object" || value === null || !("method" in value)) return {};
|
|
369
|
+
const method = value.method;
|
|
370
|
+
return typeof method === "string" ? { method } : {};
|
|
371
|
+
}
|
|
372
|
+
function serverPort$1(url) {
|
|
373
|
+
if (url.port) return Number.parseInt(url.port, 10);
|
|
374
|
+
return url.protocol === "https:" ? 443 : 80;
|
|
375
|
+
}
|
|
376
|
+
function errorType$1(error) {
|
|
377
|
+
if (error instanceof Error && error.name) return error.name;
|
|
378
|
+
return "Error";
|
|
379
|
+
}
|
|
380
|
+
function errorMessage$1(error) {
|
|
381
|
+
return error instanceof Error && error.message ? error.message : void 0;
|
|
382
|
+
}
|
|
383
|
+
//#endregion
|
|
265
384
|
//#region src/fixture/reporter-config.ts
|
|
266
385
|
const PLAYWRIGHT_OPENTELEMETRY_REPORTER_NAMES = new Set(["playwright-opentelemetry", "playwright-opentelemetry/reporter"]);
|
|
267
386
|
const PLAYWRIGHT_OPENTELEMETRY_REPORTER_PATHS = ["dist/reporter.mjs", "dist/reporter.cjs"];
|
|
@@ -529,9 +648,13 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
529
648
|
testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
|
|
530
649
|
const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
531
650
|
const traceContext = await createTestTraceContext(testInfo);
|
|
651
|
+
await registerExpectedTrace(traceContext, config, {
|
|
652
|
+
trace,
|
|
653
|
+
testInfo
|
|
654
|
+
});
|
|
532
655
|
await runWithTestFetchCapture(traceContext, () => use(traceContext));
|
|
533
656
|
await flushFixtureSpans(traceContext, config, {
|
|
534
|
-
trace
|
|
657
|
+
trace,
|
|
535
658
|
testInfo
|
|
536
659
|
});
|
|
537
660
|
}, { auto: true }],
|
|
@@ -540,6 +663,9 @@ function createPlaywrightOtelTest(testBase) {
|
|
|
540
663
|
await use(tracker);
|
|
541
664
|
tracker.finishAll();
|
|
542
665
|
}, { auto: true }],
|
|
666
|
+
request: async ({ request, testTraceContext }, use) => {
|
|
667
|
+
await use(createCapturedApiRequestContext(request, testTraceContext));
|
|
668
|
+
},
|
|
543
669
|
context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker }, use) => {
|
|
544
670
|
const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
|
|
545
671
|
context.route("**", async (route, request) => {
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
1
|
+
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-D-3pnapc.cjs";
|
|
2
2
|
import { t as PlaywrightOpentelemetryReporter } from "./reporter-DaCojFom.cjs";
|
|
3
3
|
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryDestination, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, PlaywrightOpentelemetryReporter as default };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-
|
|
1
|
+
import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-D-3pnapc.mjs";
|
|
2
2
|
import { t as PlaywrightOpentelemetryReporter } from "./reporter-DaCojFom.mjs";
|
|
3
3
|
export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryDestination, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, PlaywrightOpentelemetryReporter as default };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_config = require("./config-
|
|
1
|
+
const require_config = require("./config-CE5ph46B.cjs");
|
|
2
2
|
let node_path = require("node:path");
|
|
3
3
|
node_path = require_config.__toESM(node_path, 1);
|
|
4
4
|
let node_fs_promises = require("node:fs/promises");
|
|
@@ -195,15 +195,24 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
195
195
|
onTestEnd(test, result) {
|
|
196
196
|
const config = getTestConfig(test);
|
|
197
197
|
const traceAttachment = result.attachments.find((attachment) => attachment.name === "trace" && attachment.contentType === "application/zip" && attachment.path);
|
|
198
|
-
|
|
198
|
+
const traceRetentionTestInfo = {
|
|
199
199
|
expectedStatus: test.expectedStatus,
|
|
200
200
|
retry: result.retry,
|
|
201
201
|
status: result.status
|
|
202
|
-
}
|
|
202
|
+
};
|
|
203
|
+
const shouldRetainTrace = (trace) => trace === null ? Boolean(traceAttachment) : require_config.shouldRetainPlaywrightTrace(trace, traceRetentionTestInfo);
|
|
204
|
+
const shouldStoreTraceZip = config.storeTraceZip && shouldRetainTrace(config.trace);
|
|
205
|
+
const retainedConfig = {
|
|
206
|
+
...config,
|
|
207
|
+
otlpDestinations: require_config.filterRetainedDestinations(config.otlpDestinations, config.trace, shouldRetainTrace),
|
|
208
|
+
playwrightTraceApiDestinations: require_config.filterRetainedDestinations(config.playwrightTraceApiDestinations, config.trace, shouldRetainTrace),
|
|
209
|
+
storeTraceZip: shouldStoreTraceZip
|
|
210
|
+
};
|
|
211
|
+
if (!hasPlaywrightOpentelemetryDestination(retainedConfig)) return;
|
|
203
212
|
const testId = test.id;
|
|
204
213
|
const outputDir = getTestOutputDir(test);
|
|
205
214
|
const { traceId, rootSpanId: testSpanId } = readTraceContextAttachment(result, testId);
|
|
206
|
-
const fixtureSpans =
|
|
215
|
+
const fixtureSpans = retainedConfig.storeTraceZip ? readFixtureSpansAttachment(result, testId) : [];
|
|
207
216
|
result.annotations.push({
|
|
208
217
|
type: "playwrightOpentelemetryTraceId",
|
|
209
218
|
description: traceId
|
|
@@ -243,16 +252,16 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
243
252
|
const testSpans = [span, ...stepSpans];
|
|
244
253
|
this.spanBatches.push({
|
|
245
254
|
spans: testSpans,
|
|
246
|
-
config
|
|
255
|
+
config: retainedConfig
|
|
247
256
|
});
|
|
248
|
-
if (
|
|
257
|
+
if (retainedConfig.storeTraceZip || hasTraceApiDestination(retainedConfig)) {
|
|
249
258
|
const prepared = this.prepareTraceArtifact({
|
|
250
259
|
test,
|
|
251
260
|
spans: testSpans,
|
|
252
261
|
fixtureSpans,
|
|
253
262
|
traceAttachmentPath: traceAttachment?.path,
|
|
254
263
|
traceId,
|
|
255
|
-
config,
|
|
264
|
+
config: retainedConfig,
|
|
256
265
|
playwrightVersion: this.playwrightVersion || "unknown"
|
|
257
266
|
}).catch((error) => ({ error }));
|
|
258
267
|
this.pendingTraceArtifacts.push({
|
|
@@ -283,7 +292,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
283
292
|
if (!destination.url) continue;
|
|
284
293
|
addDestinationSpans(destinations, batch.spans, {
|
|
285
294
|
tracesEndpoint: `${destination.url}/v1/traces`,
|
|
286
|
-
headers: destination.headers,
|
|
295
|
+
headers: require_config.withPlaywrightTraceApiHeaders(destination.headers),
|
|
287
296
|
playwrightVersion: this.playwrightVersion || "unknown",
|
|
288
297
|
debug: batch.config.debug
|
|
289
298
|
});
|
|
@@ -310,7 +319,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
310
319
|
}
|
|
311
320
|
processTestStep(test, step, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds) {
|
|
312
321
|
const stepId = getStepId(test, step);
|
|
313
|
-
if (isInternalFixtureStep(step)) {
|
|
322
|
+
if (isInternalFixtureStep(step) || isInternalApiRequestStep(step)) {
|
|
314
323
|
skippedStepIds.add(stepId);
|
|
315
324
|
processedSteps.delete(stepId);
|
|
316
325
|
if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds);
|
|
@@ -373,7 +382,8 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
373
382
|
headers: {
|
|
374
383
|
"content-type": "application/zip",
|
|
375
384
|
"x-trace-id": traceId,
|
|
376
|
-
...destination.headers
|
|
385
|
+
...destination.headers,
|
|
386
|
+
[require_config.PLAYWRIGHT_TRACE_API_SOURCE_HEADER]: require_config.PLAYWRIGHT_TRACE_API_SOURCE_REPORTER
|
|
377
387
|
},
|
|
378
388
|
body: screenshotsZip
|
|
379
389
|
});
|
|
@@ -409,6 +419,9 @@ function addDestinationSpans(destinations, spans, options) {
|
|
|
409
419
|
function hasTraceApiDestination(config) {
|
|
410
420
|
return config.playwrightTraceApiDestinations.some((destination) => destination.url);
|
|
411
421
|
}
|
|
422
|
+
function hasPlaywrightOpentelemetryDestination(config) {
|
|
423
|
+
return Boolean(config.storeTraceZip || config.otlpDestinations.some((destination) => destination.url) || config.playwrightTraceApiDestinations.some((destination) => destination.url));
|
|
424
|
+
}
|
|
412
425
|
function readTraceContextAttachment(result, testId) {
|
|
413
426
|
const attachment = result.attachments.find((attachment) => attachment.name === require_config.TRACE_CONTEXT_ATTACHMENT_NAME);
|
|
414
427
|
if (!attachment?.body) return {
|
|
@@ -485,15 +498,28 @@ function cleanErrorMessage(message) {
|
|
|
485
498
|
}
|
|
486
499
|
function isInternalFixtureStep(step) {
|
|
487
500
|
if (step.category !== "fixture" || !step.location?.file) return false;
|
|
488
|
-
|
|
501
|
+
return isInternalFixtureFile(step.location.file);
|
|
502
|
+
}
|
|
503
|
+
function isInternalApiRequestStep(step) {
|
|
504
|
+
if (step.category !== "pw:api" || !step.location?.file) return false;
|
|
505
|
+
return isApiRequestStepTitle(step.title) && isInternalFixtureFile(step.location.file);
|
|
506
|
+
}
|
|
507
|
+
function isApiRequestStepTitle(title) {
|
|
508
|
+
return /^(?:DELETE|FETCH|GET|HEAD|PATCH|POST|PUT)\s+"/.test(title);
|
|
509
|
+
}
|
|
510
|
+
function isInternalFixtureFile(filePath) {
|
|
511
|
+
const file = filePath.replace(/\\/g, "/");
|
|
489
512
|
return INTERNAL_FIXTURE_FILE_PATTERNS.some((pattern) => pattern.test(file));
|
|
490
513
|
}
|
|
491
514
|
const INTERNAL_FIXTURE_FILE_PATTERNS = [
|
|
492
515
|
/(?:^|\/)dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
|
|
516
|
+
/(?:^|\/)dist\/fixture\.(?:mjs|cjs|js)$/,
|
|
493
517
|
/(?:^|\/)playwright-opentelemetry\/dist\/fixture\.(?:mjs|cjs|js)$/,
|
|
518
|
+
/(?:^|\/)playwright-opentelemetry\/reporter\/dist\/fixture\.(?:mjs|cjs|js)$/,
|
|
494
519
|
/(?:^|\/)playwright-opentelemetry\/dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
|
|
495
520
|
/(?:^|\/)playwright-opentelemetry\/dist\/fixture\/index\.(?:mjs|cjs|js)$/,
|
|
496
|
-
/(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/playwright-opentelemetry-fixture\.ts
|
|
521
|
+
/(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/playwright-opentelemetry-fixture\.ts$/,
|
|
522
|
+
/(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/api-request-capture\.ts$/
|
|
497
523
|
];
|
|
498
524
|
function isSpanAttributes(value) {
|
|
499
525
|
if (!isRecord(value)) return false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as
|
|
1
|
+
import { c as shouldRetainPlaywrightTrace, d as PLAYWRIGHT_TRACE_API_SOURCE_REPORTER, f as buildOtlpRequest, g as withPlaywrightTraceApiHeaders, h as sendSpans, i as TRACE_CONTEXT_ATTACHMENT_NAME, l as filterRetainedDestinations, m as generateTraceId, p as generateSpanId, r as FIXTURE_SPANS_ATTACHMENT_NAME, t as resolvePlaywrightOpentelemetryConfig, u as PLAYWRIGHT_TRACE_API_SOURCE_HEADER } from "./config-CoP8kphA.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import { BlobReader, BlobWriter, TextWriter, ZipReader, ZipWriter } from "@zip.js/zip.js";
|
|
@@ -193,15 +193,24 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
193
193
|
onTestEnd(test, result) {
|
|
194
194
|
const config = getTestConfig(test);
|
|
195
195
|
const traceAttachment = result.attachments.find((attachment) => attachment.name === "trace" && attachment.contentType === "application/zip" && attachment.path);
|
|
196
|
-
|
|
196
|
+
const traceRetentionTestInfo = {
|
|
197
197
|
expectedStatus: test.expectedStatus,
|
|
198
198
|
retry: result.retry,
|
|
199
199
|
status: result.status
|
|
200
|
-
}
|
|
200
|
+
};
|
|
201
|
+
const shouldRetainTrace = (trace) => trace === null ? Boolean(traceAttachment) : shouldRetainPlaywrightTrace(trace, traceRetentionTestInfo);
|
|
202
|
+
const shouldStoreTraceZip = config.storeTraceZip && shouldRetainTrace(config.trace);
|
|
203
|
+
const retainedConfig = {
|
|
204
|
+
...config,
|
|
205
|
+
otlpDestinations: filterRetainedDestinations(config.otlpDestinations, config.trace, shouldRetainTrace),
|
|
206
|
+
playwrightTraceApiDestinations: filterRetainedDestinations(config.playwrightTraceApiDestinations, config.trace, shouldRetainTrace),
|
|
207
|
+
storeTraceZip: shouldStoreTraceZip
|
|
208
|
+
};
|
|
209
|
+
if (!hasPlaywrightOpentelemetryDestination(retainedConfig)) return;
|
|
201
210
|
const testId = test.id;
|
|
202
211
|
const outputDir = getTestOutputDir(test);
|
|
203
212
|
const { traceId, rootSpanId: testSpanId } = readTraceContextAttachment(result, testId);
|
|
204
|
-
const fixtureSpans =
|
|
213
|
+
const fixtureSpans = retainedConfig.storeTraceZip ? readFixtureSpansAttachment(result, testId) : [];
|
|
205
214
|
result.annotations.push({
|
|
206
215
|
type: "playwrightOpentelemetryTraceId",
|
|
207
216
|
description: traceId
|
|
@@ -241,16 +250,16 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
241
250
|
const testSpans = [span, ...stepSpans];
|
|
242
251
|
this.spanBatches.push({
|
|
243
252
|
spans: testSpans,
|
|
244
|
-
config
|
|
253
|
+
config: retainedConfig
|
|
245
254
|
});
|
|
246
|
-
if (
|
|
255
|
+
if (retainedConfig.storeTraceZip || hasTraceApiDestination(retainedConfig)) {
|
|
247
256
|
const prepared = this.prepareTraceArtifact({
|
|
248
257
|
test,
|
|
249
258
|
spans: testSpans,
|
|
250
259
|
fixtureSpans,
|
|
251
260
|
traceAttachmentPath: traceAttachment?.path,
|
|
252
261
|
traceId,
|
|
253
|
-
config,
|
|
262
|
+
config: retainedConfig,
|
|
254
263
|
playwrightVersion: this.playwrightVersion || "unknown"
|
|
255
264
|
}).catch((error) => ({ error }));
|
|
256
265
|
this.pendingTraceArtifacts.push({
|
|
@@ -281,7 +290,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
281
290
|
if (!destination.url) continue;
|
|
282
291
|
addDestinationSpans(destinations, batch.spans, {
|
|
283
292
|
tracesEndpoint: `${destination.url}/v1/traces`,
|
|
284
|
-
headers: destination.headers,
|
|
293
|
+
headers: withPlaywrightTraceApiHeaders(destination.headers),
|
|
285
294
|
playwrightVersion: this.playwrightVersion || "unknown",
|
|
286
295
|
debug: batch.config.debug
|
|
287
296
|
});
|
|
@@ -308,7 +317,7 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
308
317
|
}
|
|
309
318
|
processTestStep(test, step, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds) {
|
|
310
319
|
const stepId = getStepId(test, step);
|
|
311
|
-
if (isInternalFixtureStep(step)) {
|
|
320
|
+
if (isInternalFixtureStep(step) || isInternalApiRequestStep(step)) {
|
|
312
321
|
skippedStepIds.add(stepId);
|
|
313
322
|
processedSteps.delete(stepId);
|
|
314
323
|
if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds);
|
|
@@ -371,7 +380,8 @@ var PlaywrightOpentelemetryReporter = class {
|
|
|
371
380
|
headers: {
|
|
372
381
|
"content-type": "application/zip",
|
|
373
382
|
"x-trace-id": traceId,
|
|
374
|
-
...destination.headers
|
|
383
|
+
...destination.headers,
|
|
384
|
+
[PLAYWRIGHT_TRACE_API_SOURCE_HEADER]: PLAYWRIGHT_TRACE_API_SOURCE_REPORTER
|
|
375
385
|
},
|
|
376
386
|
body: screenshotsZip
|
|
377
387
|
});
|
|
@@ -407,6 +417,9 @@ function addDestinationSpans(destinations, spans, options) {
|
|
|
407
417
|
function hasTraceApiDestination(config) {
|
|
408
418
|
return config.playwrightTraceApiDestinations.some((destination) => destination.url);
|
|
409
419
|
}
|
|
420
|
+
function hasPlaywrightOpentelemetryDestination(config) {
|
|
421
|
+
return Boolean(config.storeTraceZip || config.otlpDestinations.some((destination) => destination.url) || config.playwrightTraceApiDestinations.some((destination) => destination.url));
|
|
422
|
+
}
|
|
410
423
|
function readTraceContextAttachment(result, testId) {
|
|
411
424
|
const attachment = result.attachments.find((attachment) => attachment.name === TRACE_CONTEXT_ATTACHMENT_NAME);
|
|
412
425
|
if (!attachment?.body) return {
|
|
@@ -483,15 +496,28 @@ function cleanErrorMessage(message) {
|
|
|
483
496
|
}
|
|
484
497
|
function isInternalFixtureStep(step) {
|
|
485
498
|
if (step.category !== "fixture" || !step.location?.file) return false;
|
|
486
|
-
|
|
499
|
+
return isInternalFixtureFile(step.location.file);
|
|
500
|
+
}
|
|
501
|
+
function isInternalApiRequestStep(step) {
|
|
502
|
+
if (step.category !== "pw:api" || !step.location?.file) return false;
|
|
503
|
+
return isApiRequestStepTitle(step.title) && isInternalFixtureFile(step.location.file);
|
|
504
|
+
}
|
|
505
|
+
function isApiRequestStepTitle(title) {
|
|
506
|
+
return /^(?:DELETE|FETCH|GET|HEAD|PATCH|POST|PUT)\s+"/.test(title);
|
|
507
|
+
}
|
|
508
|
+
function isInternalFixtureFile(filePath) {
|
|
509
|
+
const file = filePath.replace(/\\/g, "/");
|
|
487
510
|
return INTERNAL_FIXTURE_FILE_PATTERNS.some((pattern) => pattern.test(file));
|
|
488
511
|
}
|
|
489
512
|
const INTERNAL_FIXTURE_FILE_PATTERNS = [
|
|
490
513
|
/(?:^|\/)dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
|
|
514
|
+
/(?:^|\/)dist\/fixture\.(?:mjs|cjs|js)$/,
|
|
491
515
|
/(?:^|\/)playwright-opentelemetry\/dist\/fixture\.(?:mjs|cjs|js)$/,
|
|
516
|
+
/(?:^|\/)playwright-opentelemetry\/reporter\/dist\/fixture\.(?:mjs|cjs|js)$/,
|
|
492
517
|
/(?:^|\/)playwright-opentelemetry\/dist\/playwright-opentelemetry-fixture-[^/]+\.(?:mjs|cjs|js)$/,
|
|
493
518
|
/(?:^|\/)playwright-opentelemetry\/dist\/fixture\/index\.(?:mjs|cjs|js)$/,
|
|
494
|
-
/(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/playwright-opentelemetry-fixture\.ts
|
|
519
|
+
/(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/playwright-opentelemetry-fixture\.ts$/,
|
|
520
|
+
/(?:^|\/)playwright-opentelemetry\/(?:reporter\/)?src\/fixture\/api-request-capture\.ts$/
|
|
495
521
|
];
|
|
496
522
|
function isSpanAttributes(value) {
|
|
497
523
|
if (!isRecord(value)) return false;
|
package/dist/reporter.cjs
CHANGED
package/dist/reporter.mjs
CHANGED