playwright-opentelemetry 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,13 @@
1
1
  //#region package.json
2
- var version = "0.11.0";
2
+ var version = "0.12.0";
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
- if (!shouldRetainPlaywrightTrace(options.trace, options.testInfo)) return;
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
- if (!destination.url) continue;
194
- destinations.push({
195
- tracesEndpoint: `${destination.url}/v1/traces`,
196
- headers: destination.headers
197
- });
198
- }
199
- for (const destination of config.otlpDestinations) {
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
@@ -237,18 +276,23 @@ function resolveDestinationKind(options) {
237
276
  const envEndpoint = process.env[options.envEndpointName];
238
277
  const envHeaders = process.env[options.envHeadersName];
239
278
  if (envHeaders && !envEndpoint) throw new Error(`${options.envHeadersName} is set but ${options.envEndpointName} is not set.`);
240
- if (envEndpoint) return [{
279
+ let primaryDestination;
280
+ if (envEndpoint) primaryDestination = {
241
281
  url: envEndpoint,
242
- headers: parseOtlpHeaders(envHeaders)
243
- }];
244
- if (options.singular) return [{
282
+ headers: parseOtlpHeaders(envHeaders),
283
+ trace: null
284
+ };
285
+ else if (options.singular) primaryDestination = {
245
286
  url: options.singular.url,
246
- headers: { ...options.singular.headers }
247
- }];
248
- return (options.plural ?? []).map((destination) => ({
287
+ headers: { ...options.singular.headers },
288
+ trace: options.singular.trace ?? null
289
+ };
290
+ const additionalDestinations = (options.plural ?? []).map((destination) => ({
249
291
  url: destination.url,
250
- headers: { ...destination.headers }
292
+ headers: { ...destination.headers },
293
+ trace: destination.trace ?? null
251
294
  }));
295
+ return primaryDestination ? [primaryDestination, ...additionalDestinations] : additionalDestinations;
252
296
  }
253
297
  function resolveLegacyDestinationConfig(destination, headers) {
254
298
  return typeof destination === "string" ? {
@@ -260,4 +304,4 @@ function getConfigurationErrorMessage() {
260
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";
261
305
  }
262
306
  //#endregion
263
- export { createTestTraceContext as a, buildOtlpRequest as c, sendSpans as d, TRACE_CONTEXT_ATTACHMENT_NAME as i, generateSpanId as l, BROWSER_SERVICE_NAME as n, flushFixtureSpans as o, FIXTURE_SPANS_ATTACHMENT_NAME as r, shouldRetainPlaywrightTrace as s, resolvePlaywrightOpentelemetryConfig as t, generateTraceId as u };
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 };
@@ -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.11.0";
24
+ var version = "0.12.0";
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
- if (!shouldRetainPlaywrightTrace(options.trace, options.testInfo)) return;
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
- if (!destination.url) continue;
216
- destinations.push({
217
- tracesEndpoint: `${destination.url}/v1/traces`,
218
- headers: destination.headers
219
- });
220
- }
221
- for (const destination of config.otlpDestinations) {
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
@@ -259,18 +298,23 @@ function resolveDestinationKind(options) {
259
298
  const envEndpoint = process.env[options.envEndpointName];
260
299
  const envHeaders = process.env[options.envHeadersName];
261
300
  if (envHeaders && !envEndpoint) throw new Error(`${options.envHeadersName} is set but ${options.envEndpointName} is not set.`);
262
- if (envEndpoint) return [{
301
+ let primaryDestination;
302
+ if (envEndpoint) primaryDestination = {
263
303
  url: envEndpoint,
264
- headers: parseOtlpHeaders(envHeaders)
265
- }];
266
- if (options.singular) return [{
304
+ headers: parseOtlpHeaders(envHeaders),
305
+ trace: null
306
+ };
307
+ else if (options.singular) primaryDestination = {
267
308
  url: options.singular.url,
268
- headers: { ...options.singular.headers }
269
- }];
270
- return (options.plural ?? []).map((destination) => ({
309
+ headers: { ...options.singular.headers },
310
+ trace: options.singular.trace ?? null
311
+ };
312
+ const additionalDestinations = (options.plural ?? []).map((destination) => ({
271
313
  url: destination.url,
272
- headers: { ...destination.headers }
314
+ headers: { ...destination.headers },
315
+ trace: destination.trace ?? null
273
316
  }));
317
+ return primaryDestination ? [primaryDestination, ...additionalDestinations] : additionalDestinations;
274
318
  }
275
319
  function resolveLegacyDestinationConfig(destination, headers) {
276
320
  return typeof destination === "string" ? {
@@ -294,6 +338,18 @@ Object.defineProperty(exports, "FIXTURE_SPANS_ATTACHMENT_NAME", {
294
338
  return FIXTURE_SPANS_ATTACHMENT_NAME;
295
339
  }
296
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
+ });
297
353
  Object.defineProperty(exports, "TRACE_CONTEXT_ATTACHMENT_NAME", {
298
354
  enumerable: true,
299
355
  get: function() {
@@ -318,6 +374,12 @@ Object.defineProperty(exports, "createTestTraceContext", {
318
374
  return createTestTraceContext;
319
375
  }
320
376
  });
377
+ Object.defineProperty(exports, "filterRetainedDestinations", {
378
+ enumerable: true,
379
+ get: function() {
380
+ return filterRetainedDestinations;
381
+ }
382
+ });
321
383
  Object.defineProperty(exports, "flushFixtureSpans", {
322
384
  enumerable: true,
323
385
  get: function() {
@@ -336,6 +398,12 @@ Object.defineProperty(exports, "generateTraceId", {
336
398
  return generateTraceId;
337
399
  }
338
400
  });
401
+ Object.defineProperty(exports, "registerExpectedTrace", {
402
+ enumerable: true,
403
+ get: function() {
404
+ return registerExpectedTrace;
405
+ }
406
+ });
339
407
  Object.defineProperty(exports, "resolvePlaywrightOpentelemetryConfig", {
340
408
  enumerable: true,
341
409
  get: function() {
@@ -354,3 +422,9 @@ Object.defineProperty(exports, "shouldRetainPlaywrightTrace", {
354
422
  return shouldRetainPlaywrightTrace;
355
423
  }
356
424
  });
425
+ Object.defineProperty(exports, "withPlaywrightTraceApiHeaders", {
426
+ enumerable: true,
427
+ get: function() {
428
+ return withPlaywrightTraceApiHeaders;
429
+ }
430
+ });
@@ -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,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_config = require("./config-Csi-apHL.cjs");
2
+ const require_config = require("./config-BzW6-Ty7.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");
@@ -530,9 +530,13 @@ function createPlaywrightOtelTest(testBase) {
530
530
  testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
531
531
  const config = require_config.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
532
532
  const traceContext = await require_config.createTestTraceContext(testInfo);
533
+ await require_config.registerExpectedTrace(traceContext, config, {
534
+ trace,
535
+ testInfo
536
+ });
533
537
  await runWithTestFetchCapture(traceContext, () => use(traceContext));
534
538
  await require_config.flushFixtureSpans(traceContext, config, {
535
- trace: config.trace ?? trace,
539
+ trace,
536
540
  testInfo
537
541
  });
538
542
  }, { auto: true }],
@@ -1,4 +1,4 @@
1
- import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-C_APEwdC.cjs";
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";
@@ -1,4 +1,4 @@
1
- import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-C_APEwdC.mjs";
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,4 +1,4 @@
1
- import { a as createTestTraceContext, l as generateSpanId, n as BROWSER_SERVICE_NAME, o as flushFixtureSpans, t as resolvePlaywrightOpentelemetryConfig } from "./config-B0-IOZF-.mjs";
1
+ import { a as createTestTraceContext, n as BROWSER_SERVICE_NAME, o as flushFixtureSpans, p as generateSpanId, s as registerExpectedTrace, t as resolvePlaywrightOpentelemetryConfig } from "./config-Bv4dsPRO.mjs";
2
2
  import path from "node:path";
3
3
  import { test as test$1 } from "@playwright/test";
4
4
  export * from "@playwright/test";
@@ -529,9 +529,13 @@ function createPlaywrightOtelTest(testBase) {
529
529
  testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
530
530
  const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
531
531
  const traceContext = await createTestTraceContext(testInfo);
532
+ await registerExpectedTrace(traceContext, config, {
533
+ trace,
534
+ testInfo
535
+ });
532
536
  await runWithTestFetchCapture(traceContext, () => use(traceContext));
533
537
  await flushFixtureSpans(traceContext, config, {
534
- trace: config.trace ?? trace,
538
+ trace,
535
539
  testInfo
536
540
  });
537
541
  }, { auto: true }],
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/index.ts
2
- var src_default = require("./reporter-DszuIYsI.cjs").PlaywrightOpentelemetryReporter;
2
+ var src_default = require("./reporter-BFqKJlKV.cjs").PlaywrightOpentelemetryReporter;
3
3
  //#endregion
4
4
  module.exports = src_default;
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-C_APEwdC.cjs";
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-C_APEwdC.mjs";
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
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-BGMoVKC7.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-DTduncL-.mjs";
2
2
  //#region src/index.ts
3
3
  var src_default = PlaywrightOpentelemetryReporter;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- const require_config = require("./config-Csi-apHL.cjs");
1
+ const require_config = require("./config-BzW6-Ty7.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
- if (!(config.trace === null ? Boolean(traceAttachment) : require_config.shouldRetainPlaywrightTrace(config.trace, {
198
+ const traceRetentionTestInfo = {
199
199
  expectedStatus: test.expectedStatus,
200
200
  retry: result.retry,
201
201
  status: result.status
202
- }))) return;
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 = config.storeTraceZip ? readFixtureSpansAttachment(result, testId) : [];
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 (config.storeTraceZip || hasTraceApiDestination(config)) {
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
  });
@@ -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 {
@@ -1,4 +1,4 @@
1
- import { c as buildOtlpRequest, d as sendSpans, i as TRACE_CONTEXT_ATTACHMENT_NAME, l as generateSpanId, r as FIXTURE_SPANS_ATTACHMENT_NAME, s as shouldRetainPlaywrightTrace, t as resolvePlaywrightOpentelemetryConfig, u as generateTraceId } from "./config-B0-IOZF-.mjs";
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-Bv4dsPRO.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
- if (!(config.trace === null ? Boolean(traceAttachment) : shouldRetainPlaywrightTrace(config.trace, {
196
+ const traceRetentionTestInfo = {
197
197
  expectedStatus: test.expectedStatus,
198
198
  retry: result.retry,
199
199
  status: result.status
200
- }))) return;
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 = config.storeTraceZip ? readFixtureSpansAttachment(result, testId) : [];
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 (config.storeTraceZip || hasTraceApiDestination(config)) {
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
  });
@@ -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 {
package/dist/reporter.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/reporter/index.ts
2
- var reporter_default = require("./reporter-DszuIYsI.cjs").PlaywrightOpentelemetryReporter;
2
+ var reporter_default = require("./reporter-BFqKJlKV.cjs").PlaywrightOpentelemetryReporter;
3
3
  //#endregion
4
4
  module.exports = reporter_default;
package/dist/reporter.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-BGMoVKC7.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-DTduncL-.mjs";
2
2
  //#region src/reporter/index.ts
3
3
  var reporter_default = PlaywrightOpentelemetryReporter;
4
4
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright-opentelemetry",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "A reporter for Playwright that can export traces and spans in opentelemetry format.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",