playwright-opentelemetry 0.9.0 → 0.11.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,7 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.9.0";
3
- //#endregion
4
- //#region src/shared/otel.ts
2
+ var version = "0.11.0";
5
3
  /** Generate a random 32-character hex trace ID. */
6
4
  function generateTraceId() {
7
5
  return Array.from({ length: 32 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
@@ -89,10 +87,10 @@ function buildResourceSpan(spans, serviceName, playwrightVersion) {
89
87
  }]
90
88
  };
91
89
  }
92
- function buildOtlpRequest(spans, serviceName, playwrightVersion) {
90
+ function buildOtlpRequest(spans, playwrightVersion) {
93
91
  const spansByService = /* @__PURE__ */ new Map();
94
92
  for (const span of spans) {
95
- const spanServiceName = span.serviceName ?? serviceName;
93
+ const spanServiceName = span.serviceName ?? "playwright-tests";
96
94
  const serviceSpans = spansByService.get(spanServiceName);
97
95
  if (serviceSpans) serviceSpans.push(span);
98
96
  else spansByService.set(spanServiceName, [span]);
@@ -103,7 +101,7 @@ function buildOtlpRequest(spans, serviceName, playwrightVersion) {
103
101
  }
104
102
  async function sendSpans(spans, options) {
105
103
  if (spans.length === 0) return;
106
- const body = JSON.stringify(buildOtlpRequest(spans, options.serviceName, options.playwrightVersion));
104
+ const body = JSON.stringify(buildOtlpRequest(spans, options.playwrightVersion));
107
105
  if (options.debug) console.log("Sending spans to", options.tracesEndpoint);
108
106
  const response = await fetch(options.tracesEndpoint, {
109
107
  method: "POST",
@@ -142,6 +140,7 @@ function normalizeTraceMode(trace) {
142
140
  //#region src/fixture/trace-context.ts
143
141
  const TRACE_CONTEXT_ATTACHMENT_NAME = "playwright-opentelemetry-trace-context";
144
142
  const FIXTURE_SPANS_ATTACHMENT_NAME = "playwright-opentelemetry-fixture-spans";
143
+ const BROWSER_SERVICE_NAME = "playwright-browser";
145
144
  async function createTestTraceContext(testInfo) {
146
145
  const traceContext = {
147
146
  traceId: generateTraceId(),
@@ -173,7 +172,6 @@ async function flushFixtureSpans(traceContext, config, options) {
173
172
  await Promise.all(destinations.map((destination) => sendSpans(traceContext.spans, {
174
173
  tracesEndpoint: destination.tracesEndpoint,
175
174
  headers: destination.headers,
176
- serviceName: "playwright-browser",
177
175
  playwrightVersion: "unknown",
178
176
  debug: config.debug
179
177
  })));
@@ -191,47 +189,75 @@ function serializeSpanForAttachment(span) {
191
189
  }
192
190
  function fixtureSpanDestinations(config) {
193
191
  const destinations = [];
194
- if (config.playwrightTraceApiEndpoint) destinations.push({
195
- tracesEndpoint: `${config.playwrightTraceApiEndpoint}/v1/traces`,
196
- headers: config.playwrightTraceApiHeaders
197
- });
198
- if (config.otlpEndpoint) destinations.push({
199
- tracesEndpoint: config.otlpEndpoint,
200
- headers: config.otlpHeaders
201
- });
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
+ }
202
206
  return destinations;
203
207
  }
204
208
  //#endregion
205
209
  //#region src/shared/config.ts
206
210
  function resolvePlaywrightOpentelemetryConfig(config, options = {}) {
207
- const envOtlpHeaders = parseOtlpHeaders(process.env.OTEL_EXPORTER_OTLP_HEADERS);
208
- const envTraceApiHeaders = parseOtlpHeaders(process.env.PLAYWRIGHT_TRACE_API_HEADERS);
209
211
  const debugEnv = process.env.PLAYWRIGHT_OPENTELEMETRY_DEBUG;
210
212
  const resolvedConfig = {
211
- otlpEndpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || config?.otlpEndpoint || "",
212
- otlpHeaders: {
213
- ...config?.otlpHeaders,
214
- ...envOtlpHeaders
215
- },
216
- playwrightTraceApiEndpoint: process.env.PLAYWRIGHT_TRACE_API_ENDPOINT || config?.playwrightTraceApiEndpoint || "",
217
- playwrightTraceApiHeaders: {
218
- ...config?.playwrightTraceApiHeaders,
219
- ...envTraceApiHeaders
220
- },
213
+ otlpDestinations: resolveDestinationKind({
214
+ envEndpointName: "OTEL_EXPORTER_OTLP_ENDPOINT",
215
+ envHeadersName: "OTEL_EXPORTER_OTLP_HEADERS",
216
+ singular: resolveLegacyDestinationConfig(config?.otlpEndpoint, config?.otlpHeaders),
217
+ plural: config?.otlpEndpoints
218
+ }),
219
+ playwrightTraceApiDestinations: resolveDestinationKind({
220
+ envEndpointName: "PLAYWRIGHT_TRACE_API_ENDPOINT",
221
+ envHeadersName: "PLAYWRIGHT_TRACE_API_HEADERS",
222
+ singular: resolveLegacyDestinationConfig(config?.playwrightTraceApiEndpoint, config?.playwrightTraceApiHeaders),
223
+ plural: config?.playwrightTraceApiEndpoints
224
+ }),
221
225
  storeTraceZip: config?.storeTraceZip === true,
222
226
  trace: config?.trace ?? null,
223
227
  propagateTraceHeaders: config?.propagateTraceHeaders ?? true,
224
- serviceName: process.env.OTEL_SERVICE_NAME || config?.serviceName || "playwright-tests",
225
228
  debug: debugEnv === void 0 ? config?.debug ?? false : debugEnv === "1" || debugEnv === "true"
226
229
  };
227
230
  if (options.requireDestination === true && !hasPlaywrightOpentelemetryDestination(resolvedConfig)) throw new Error(getConfigurationErrorMessage());
228
231
  return resolvedConfig;
229
232
  }
230
233
  function hasPlaywrightOpentelemetryDestination(config) {
231
- return Boolean(config.otlpEndpoint || config.playwrightTraceApiEndpoint || config.storeTraceZip);
234
+ return Boolean(config.otlpDestinations.some((destination) => destination.url) || config.playwrightTraceApiDestinations.some((destination) => destination.url) || config.storeTraceZip);
235
+ }
236
+ function resolveDestinationKind(options) {
237
+ const envEndpoint = process.env[options.envEndpointName];
238
+ const envHeaders = process.env[options.envHeadersName];
239
+ if (envHeaders && !envEndpoint) throw new Error(`${options.envHeadersName} is set but ${options.envEndpointName} is not set.`);
240
+ if (envEndpoint) return [{
241
+ url: envEndpoint,
242
+ headers: parseOtlpHeaders(envHeaders)
243
+ }];
244
+ if (options.singular) return [{
245
+ url: options.singular.url,
246
+ headers: { ...options.singular.headers }
247
+ }];
248
+ return (options.plural ?? []).map((destination) => ({
249
+ url: destination.url,
250
+ headers: { ...destination.headers }
251
+ }));
252
+ }
253
+ function resolveLegacyDestinationConfig(destination, headers) {
254
+ return typeof destination === "string" ? {
255
+ url: destination,
256
+ headers
257
+ } : destination;
232
258
  }
233
259
  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";
260
+ 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";
235
261
  }
236
262
  //#endregion
237
- export { flushFixtureSpans as a, generateSpanId as c, createTestTraceContext as i, generateTraceId as l, FIXTURE_SPANS_ATTACHMENT_NAME as n, shouldRetainPlaywrightTrace as o, TRACE_CONTEXT_ATTACHMENT_NAME as r, buildOtlpRequest as s, resolvePlaywrightOpentelemetryConfig as t, sendSpans as u };
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 };
@@ -9,19 +9,22 @@ type PlaywrightTraceOption = PlaywrightTraceMode | "retry-with-trace" | {
9
9
  };
10
10
  //#endregion
11
11
  //#region src/shared/config.d.ts
12
+ type PlaywrightOpentelemetryDestination = {
13
+ url: string;
14
+ headers?: Record<string, string>;
15
+ };
12
16
  interface PlaywrightOpentelemetryConfig {
13
- otlpEndpoint?: string;
14
- otlpHeaders?: Record<string, string>;
15
- playwrightTraceApiEndpoint?: string;
16
- playwrightTraceApiHeaders?: Record<string, string>;
17
+ otlpEndpoint?: PlaywrightOpentelemetryDestination;
18
+ otlpEndpoints?: PlaywrightOpentelemetryDestination[];
19
+ playwrightTraceApiEndpoint?: PlaywrightOpentelemetryDestination;
20
+ playwrightTraceApiEndpoints?: PlaywrightOpentelemetryDestination[];
17
21
  storeTraceZip?: boolean;
18
22
  trace?: PlaywrightTraceOption;
19
23
  propagateTraceHeaders?: boolean;
20
- serviceName?: string;
21
24
  debug?: boolean;
22
25
  }
23
26
  interface PlaywrightOpentelemetryUseOptions {
24
27
  playwrightOpentelemetry?: PlaywrightOpentelemetryConfig;
25
28
  }
26
29
  //#endregion
27
- export { PlaywrightOpentelemetryUseOptions as n, PlaywrightTraceOption as r, PlaywrightOpentelemetryConfig as t };
30
+ export { PlaywrightTraceOption as i, PlaywrightOpentelemetryDestination as n, PlaywrightOpentelemetryUseOptions as r, PlaywrightOpentelemetryConfig as t };
@@ -9,19 +9,22 @@ type PlaywrightTraceOption = PlaywrightTraceMode | "retry-with-trace" | {
9
9
  };
10
10
  //#endregion
11
11
  //#region src/shared/config.d.ts
12
+ type PlaywrightOpentelemetryDestination = {
13
+ url: string;
14
+ headers?: Record<string, string>;
15
+ };
12
16
  interface PlaywrightOpentelemetryConfig {
13
- otlpEndpoint?: string;
14
- otlpHeaders?: Record<string, string>;
15
- playwrightTraceApiEndpoint?: string;
16
- playwrightTraceApiHeaders?: Record<string, string>;
17
+ otlpEndpoint?: PlaywrightOpentelemetryDestination;
18
+ otlpEndpoints?: PlaywrightOpentelemetryDestination[];
19
+ playwrightTraceApiEndpoint?: PlaywrightOpentelemetryDestination;
20
+ playwrightTraceApiEndpoints?: PlaywrightOpentelemetryDestination[];
17
21
  storeTraceZip?: boolean;
18
22
  trace?: PlaywrightTraceOption;
19
23
  propagateTraceHeaders?: boolean;
20
- serviceName?: string;
21
24
  debug?: boolean;
22
25
  }
23
26
  interface PlaywrightOpentelemetryUseOptions {
24
27
  playwrightOpentelemetry?: PlaywrightOpentelemetryConfig;
25
28
  }
26
29
  //#endregion
27
- export { PlaywrightOpentelemetryUseOptions as n, PlaywrightTraceOption as r, PlaywrightOpentelemetryConfig as t };
30
+ export { PlaywrightTraceOption as i, PlaywrightOpentelemetryDestination as n, PlaywrightOpentelemetryUseOptions as r, PlaywrightOpentelemetryConfig as t };
@@ -21,9 +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.9.0";
25
- //#endregion
26
- //#region src/shared/otel.ts
24
+ var version = "0.11.0";
27
25
  /** Generate a random 32-character hex trace ID. */
28
26
  function generateTraceId() {
29
27
  return Array.from({ length: 32 }, () => Math.floor(Math.random() * 16).toString(16)).join("");
@@ -111,10 +109,10 @@ function buildResourceSpan(spans, serviceName, playwrightVersion) {
111
109
  }]
112
110
  };
113
111
  }
114
- function buildOtlpRequest(spans, serviceName, playwrightVersion) {
112
+ function buildOtlpRequest(spans, playwrightVersion) {
115
113
  const spansByService = /* @__PURE__ */ new Map();
116
114
  for (const span of spans) {
117
- const spanServiceName = span.serviceName ?? serviceName;
115
+ const spanServiceName = span.serviceName ?? "playwright-tests";
118
116
  const serviceSpans = spansByService.get(spanServiceName);
119
117
  if (serviceSpans) serviceSpans.push(span);
120
118
  else spansByService.set(spanServiceName, [span]);
@@ -125,7 +123,7 @@ function buildOtlpRequest(spans, serviceName, playwrightVersion) {
125
123
  }
126
124
  async function sendSpans(spans, options) {
127
125
  if (spans.length === 0) return;
128
- const body = JSON.stringify(buildOtlpRequest(spans, options.serviceName, options.playwrightVersion));
126
+ const body = JSON.stringify(buildOtlpRequest(spans, options.playwrightVersion));
129
127
  if (options.debug) console.log("Sending spans to", options.tracesEndpoint);
130
128
  const response = await fetch(options.tracesEndpoint, {
131
129
  method: "POST",
@@ -164,6 +162,7 @@ function normalizeTraceMode(trace) {
164
162
  //#region src/fixture/trace-context.ts
165
163
  const TRACE_CONTEXT_ATTACHMENT_NAME = "playwright-opentelemetry-trace-context";
166
164
  const FIXTURE_SPANS_ATTACHMENT_NAME = "playwright-opentelemetry-fixture-spans";
165
+ const BROWSER_SERVICE_NAME = "playwright-browser";
167
166
  async function createTestTraceContext(testInfo) {
168
167
  const traceContext = {
169
168
  traceId: generateTraceId(),
@@ -195,7 +194,6 @@ async function flushFixtureSpans(traceContext, config, options) {
195
194
  await Promise.all(destinations.map((destination) => sendSpans(traceContext.spans, {
196
195
  tracesEndpoint: destination.tracesEndpoint,
197
196
  headers: destination.headers,
198
- serviceName: "playwright-browser",
199
197
  playwrightVersion: "unknown",
200
198
  debug: config.debug
201
199
  })));
@@ -213,49 +211,83 @@ function serializeSpanForAttachment(span) {
213
211
  }
214
212
  function fixtureSpanDestinations(config) {
215
213
  const destinations = [];
216
- if (config.playwrightTraceApiEndpoint) destinations.push({
217
- tracesEndpoint: `${config.playwrightTraceApiEndpoint}/v1/traces`,
218
- headers: config.playwrightTraceApiHeaders
219
- });
220
- if (config.otlpEndpoint) destinations.push({
221
- tracesEndpoint: config.otlpEndpoint,
222
- headers: config.otlpHeaders
223
- });
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
+ }
224
228
  return destinations;
225
229
  }
226
230
  //#endregion
227
231
  //#region src/shared/config.ts
228
232
  function resolvePlaywrightOpentelemetryConfig(config, options = {}) {
229
- const envOtlpHeaders = parseOtlpHeaders(process.env.OTEL_EXPORTER_OTLP_HEADERS);
230
- const envTraceApiHeaders = parseOtlpHeaders(process.env.PLAYWRIGHT_TRACE_API_HEADERS);
231
233
  const debugEnv = process.env.PLAYWRIGHT_OPENTELEMETRY_DEBUG;
232
234
  const resolvedConfig = {
233
- otlpEndpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT || config?.otlpEndpoint || "",
234
- otlpHeaders: {
235
- ...config?.otlpHeaders,
236
- ...envOtlpHeaders
237
- },
238
- playwrightTraceApiEndpoint: process.env.PLAYWRIGHT_TRACE_API_ENDPOINT || config?.playwrightTraceApiEndpoint || "",
239
- playwrightTraceApiHeaders: {
240
- ...config?.playwrightTraceApiHeaders,
241
- ...envTraceApiHeaders
242
- },
235
+ otlpDestinations: resolveDestinationKind({
236
+ envEndpointName: "OTEL_EXPORTER_OTLP_ENDPOINT",
237
+ envHeadersName: "OTEL_EXPORTER_OTLP_HEADERS",
238
+ singular: resolveLegacyDestinationConfig(config?.otlpEndpoint, config?.otlpHeaders),
239
+ plural: config?.otlpEndpoints
240
+ }),
241
+ playwrightTraceApiDestinations: resolveDestinationKind({
242
+ envEndpointName: "PLAYWRIGHT_TRACE_API_ENDPOINT",
243
+ envHeadersName: "PLAYWRIGHT_TRACE_API_HEADERS",
244
+ singular: resolveLegacyDestinationConfig(config?.playwrightTraceApiEndpoint, config?.playwrightTraceApiHeaders),
245
+ plural: config?.playwrightTraceApiEndpoints
246
+ }),
243
247
  storeTraceZip: config?.storeTraceZip === true,
244
248
  trace: config?.trace ?? null,
245
249
  propagateTraceHeaders: config?.propagateTraceHeaders ?? true,
246
- serviceName: process.env.OTEL_SERVICE_NAME || config?.serviceName || "playwright-tests",
247
250
  debug: debugEnv === void 0 ? config?.debug ?? false : debugEnv === "1" || debugEnv === "true"
248
251
  };
249
252
  if (options.requireDestination === true && !hasPlaywrightOpentelemetryDestination(resolvedConfig)) throw new Error(getConfigurationErrorMessage());
250
253
  return resolvedConfig;
251
254
  }
252
255
  function hasPlaywrightOpentelemetryDestination(config) {
253
- return Boolean(config.otlpEndpoint || config.playwrightTraceApiEndpoint || config.storeTraceZip);
256
+ return Boolean(config.otlpDestinations.some((destination) => destination.url) || config.playwrightTraceApiDestinations.some((destination) => destination.url) || config.storeTraceZip);
257
+ }
258
+ function resolveDestinationKind(options) {
259
+ const envEndpoint = process.env[options.envEndpointName];
260
+ const envHeaders = process.env[options.envHeadersName];
261
+ if (envHeaders && !envEndpoint) throw new Error(`${options.envHeadersName} is set but ${options.envEndpointName} is not set.`);
262
+ if (envEndpoint) return [{
263
+ url: envEndpoint,
264
+ headers: parseOtlpHeaders(envHeaders)
265
+ }];
266
+ if (options.singular) return [{
267
+ url: options.singular.url,
268
+ headers: { ...options.singular.headers }
269
+ }];
270
+ return (options.plural ?? []).map((destination) => ({
271
+ url: destination.url,
272
+ headers: { ...destination.headers }
273
+ }));
274
+ }
275
+ function resolveLegacyDestinationConfig(destination, headers) {
276
+ return typeof destination === "string" ? {
277
+ url: destination,
278
+ headers
279
+ } : destination;
254
280
  }
255
281
  function getConfigurationErrorMessage() {
256
- 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";
282
+ 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";
257
283
  }
258
284
  //#endregion
285
+ Object.defineProperty(exports, "BROWSER_SERVICE_NAME", {
286
+ enumerable: true,
287
+ get: function() {
288
+ return BROWSER_SERVICE_NAME;
289
+ }
290
+ });
259
291
  Object.defineProperty(exports, "FIXTURE_SPANS_ATTACHMENT_NAME", {
260
292
  enumerable: true,
261
293
  get: function() {
package/dist/fixture.cjs CHANGED
@@ -1,13 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_config = require("./config-DtWFdgrv.cjs");
2
+ const require_config = require("./config-Csi-apHL.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 BROWSER_SERVICE_NAME = "playwright-browser";
10
- const SPAN_STATUS_CODE_UNSET$1 = 0;
9
+ const SPAN_STATUS_CODE_UNSET$2 = 0;
11
10
  var BrowserPageTracker = class {
12
11
  traceContext;
13
12
  nextPageId = 1;
@@ -169,7 +168,7 @@ var BrowserPageTracker = class {
169
168
  name,
170
169
  startTime,
171
170
  endTime: startTime,
172
- status: { code: SPAN_STATUS_CODE_UNSET$1 },
171
+ status: { code: SPAN_STATUS_CODE_UNSET$2 },
173
172
  attributes: pageAttributes({
174
173
  pageId,
175
174
  url,
@@ -178,7 +177,7 @@ var BrowserPageTracker = class {
178
177
  documentUrl
179
178
  }),
180
179
  events: [],
181
- serviceName: BROWSER_SERVICE_NAME
180
+ serviceName: require_config.BROWSER_SERVICE_NAME
182
181
  };
183
182
  }
184
183
  };
@@ -333,13 +332,13 @@ function detectResourceTypeFromUrl(url) {
333
332
  * OpenTelemetry SpanKind values
334
333
  * @see https://opentelemetry.io/docs/specs/otel/trace/api/#spankind
335
334
  */
336
- const SPAN_KIND_CLIENT = 3;
335
+ const SPAN_KIND_CLIENT$1 = 3;
337
336
  /**
338
337
  * OpenTelemetry SpanStatusCode values
339
338
  * @see https://opentelemetry.io/docs/specs/otel/trace/api/#set-status
340
339
  */
341
- const SPAN_STATUS_CODE_UNSET = 0;
342
- const SPAN_STATUS_CODE_ERROR = 2;
340
+ const SPAN_STATUS_CODE_UNSET$1 = 0;
341
+ const SPAN_STATUS_CODE_ERROR$1 = 2;
343
342
  /**
344
343
  * Captures request/response data and stores the complete network span in the
345
344
  * current test trace context. Called after the request has completed.
@@ -358,8 +357,8 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
358
357
  const parsedUrl = new URL(url);
359
358
  const serverAddress = parsedUrl.hostname;
360
359
  const serverPort = parsedUrl.port !== "" ? Number.parseInt(parsedUrl.port, 10) : parsedUrl.protocol === "https:" ? 443 : 80;
361
- let statusCodeValue = SPAN_STATUS_CODE_UNSET;
362
- if (statusCode >= 400) statusCodeValue = SPAN_STATUS_CODE_ERROR;
360
+ let statusCodeValue = SPAN_STATUS_CODE_UNSET$1;
361
+ if (statusCode >= 400) statusCodeValue = SPAN_STATUS_CODE_ERROR$1;
363
362
  const resourceType = detectResourceType(await getResponseHeaderValue(response, "content-type"), url);
364
363
  const attributes = {
365
364
  "http.request.method": method,
@@ -372,19 +371,19 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
372
371
  "browser.request.route_association": requestTraceContext.routeAssociation
373
372
  };
374
373
  if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
375
- if (statusCodeValue === SPAN_STATUS_CODE_ERROR) attributes["error.type"] = statusCode.toString();
374
+ if (statusCodeValue === SPAN_STATUS_CODE_ERROR$1) attributes["error.type"] = statusCode.toString();
376
375
  const networkSpan = {
377
376
  traceId: requestTraceContext.traceId,
378
377
  spanId: requestTraceContext.spanId,
379
378
  parentSpanId: requestTraceContext.parentSpanId,
380
379
  name: `HTTP ${method}`,
381
- kind: SPAN_KIND_CLIENT,
380
+ kind: SPAN_KIND_CLIENT$1,
382
381
  startTime,
383
382
  endTime,
384
383
  status: { code: statusCodeValue },
385
384
  attributes,
386
385
  events: [],
387
- serviceName: "playwright-browser"
386
+ serviceName: require_config.BROWSER_SERVICE_NAME
388
387
  };
389
388
  traceContext.addSpan(networkSpan);
390
389
  }
@@ -396,6 +395,120 @@ async function getResponseHeaderValue(response, name) {
396
395
  }
397
396
  }
398
397
  //#endregion
398
+ //#region src/fixture/test-fetch-capture.ts
399
+ const SPAN_KIND_CLIENT = 3;
400
+ const SPAN_STATUS_CODE_UNSET = 0;
401
+ const SPAN_STATUS_CODE_ERROR = 2;
402
+ let originalFetch;
403
+ let activeTraceContext;
404
+ function runWithTestFetchCapture(traceContext, callback) {
405
+ ensureFetchPatched();
406
+ const previousTraceContext = activeTraceContext;
407
+ activeTraceContext = traceContext;
408
+ return (async () => {
409
+ try {
410
+ return await callback();
411
+ } finally {
412
+ activeTraceContext = previousTraceContext;
413
+ }
414
+ })();
415
+ }
416
+ function ensureFetchPatched() {
417
+ if (globalThis.fetch === patchedFetch) return;
418
+ originalFetch = globalThis.fetch.bind(globalThis);
419
+ globalThis.fetch = patchedFetch;
420
+ }
421
+ const patchedFetch = async (input, init) => {
422
+ const traceContext = activeTraceContext;
423
+ if (!traceContext) return originalFetch ? originalFetch(input, init) : globalThis.fetch(input, init);
424
+ if (!originalFetch) return globalThis.fetch(input, init);
425
+ const startTime = /* @__PURE__ */ new Date();
426
+ try {
427
+ const response = await originalFetch(input, init);
428
+ traceContext.addSpan(createFetchSpan({
429
+ input,
430
+ init,
431
+ traceContext,
432
+ startTime,
433
+ endTime: /* @__PURE__ */ new Date(),
434
+ statusCode: response.status
435
+ }));
436
+ return response;
437
+ } catch (error) {
438
+ traceContext.addSpan(createFetchSpan({
439
+ input,
440
+ init,
441
+ traceContext,
442
+ startTime,
443
+ endTime: /* @__PURE__ */ new Date(),
444
+ error
445
+ }));
446
+ throw error;
447
+ }
448
+ };
449
+ function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, error }) {
450
+ const method = getFetchMethod(input, init);
451
+ const attributes = createHttpAttributes({
452
+ method,
453
+ url: getFetchUrl(input),
454
+ statusCode,
455
+ error
456
+ });
457
+ const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
458
+ return {
459
+ traceId: traceContext.traceId,
460
+ spanId: require_config.generateSpanId(),
461
+ parentSpanId: traceContext.rootSpanId,
462
+ name: `HTTP ${method}`,
463
+ kind: SPAN_KIND_CLIENT,
464
+ startTime,
465
+ endTime,
466
+ status: failed ? {
467
+ code: SPAN_STATUS_CODE_ERROR,
468
+ message: errorMessage(error)
469
+ } : { code: SPAN_STATUS_CODE_UNSET },
470
+ attributes,
471
+ events: []
472
+ };
473
+ }
474
+ function createHttpAttributes({ method, url, statusCode, error }) {
475
+ const attributes = {
476
+ "http.request.method": method,
477
+ "http.resource.type": "fetch",
478
+ "url.full": url
479
+ };
480
+ try {
481
+ const parsedUrl = new URL(url);
482
+ attributes["url.path"] = parsedUrl.pathname;
483
+ attributes["server.address"] = parsedUrl.hostname;
484
+ attributes["server.port"] = serverPort(parsedUrl);
485
+ if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
486
+ } catch {}
487
+ if (statusCode !== void 0) {
488
+ attributes["http.response.status_code"] = statusCode;
489
+ if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
490
+ } else if (error !== void 0) attributes["error.type"] = errorType(error);
491
+ return attributes;
492
+ }
493
+ function getFetchMethod(input, init) {
494
+ return (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
495
+ }
496
+ function getFetchUrl(input) {
497
+ if (input instanceof Request) return input.url;
498
+ return input.toString();
499
+ }
500
+ function serverPort(url) {
501
+ if (url.port) return Number.parseInt(url.port, 10);
502
+ return url.protocol === "https:" ? 443 : 80;
503
+ }
504
+ function errorType(error) {
505
+ if (error instanceof Error && error.name) return error.name;
506
+ return "Error";
507
+ }
508
+ function errorMessage(error) {
509
+ return error instanceof Error && error.message ? error.message : void 0;
510
+ }
511
+ //#endregion
399
512
  //#region src/fixture/playwright-opentelemetry-fixture.ts
400
513
  function createPlaywrightOtelTest(testBase) {
401
514
  return testBase.extend({
@@ -417,7 +530,7 @@ function createPlaywrightOtelTest(testBase) {
417
530
  testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
418
531
  const config = require_config.resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
419
532
  const traceContext = await require_config.createTestTraceContext(testInfo);
420
- await use(traceContext);
533
+ await runWithTestFetchCapture(traceContext, () => use(traceContext));
421
534
  await require_config.flushFixtureSpans(traceContext, config, {
422
535
  trace: config.trace ?? trace,
423
536
  testInfo
@@ -1,4 +1,4 @@
1
- import { n as PlaywrightOpentelemetryUseOptions, r as PlaywrightTraceOption, t as PlaywrightOpentelemetryConfig } from "./config-Db932l_s.cjs";
1
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-C_APEwdC.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";
@@ -62,4 +62,4 @@ declare const test: import("@playwright/test").TestType<import("@playwright/test
62
62
  _playwrightOpentelemetryReporterCheck: void;
63
63
  }>;
64
64
  //#endregion
65
- export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, test };
65
+ export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryDestination, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, test };
@@ -1,4 +1,4 @@
1
- import { n as PlaywrightOpentelemetryUseOptions, r as PlaywrightTraceOption, t as PlaywrightOpentelemetryConfig } from "./config-Db932l_s.mjs";
1
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-C_APEwdC.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";
@@ -62,4 +62,4 @@ declare const test: import("@playwright/test").TestType<import("@playwright/test
62
62
  _playwrightOpentelemetryReporterCheck: void;
63
63
  }>;
64
64
  //#endregion
65
- export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, test };
65
+ export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryDestination, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, test };
package/dist/fixture.mjs CHANGED
@@ -1,12 +1,11 @@
1
- import { a as flushFixtureSpans, c as generateSpanId, i as createTestTraceContext, t as resolvePlaywrightOpentelemetryConfig } from "./config-Cec6zO6v.mjs";
1
+ import { a as createTestTraceContext, l as generateSpanId, n as BROWSER_SERVICE_NAME, o as flushFixtureSpans, t as resolvePlaywrightOpentelemetryConfig } from "./config-B0-IOZF-.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 BROWSER_SERVICE_NAME = "playwright-browser";
9
- const SPAN_STATUS_CODE_UNSET$1 = 0;
8
+ const SPAN_STATUS_CODE_UNSET$2 = 0;
10
9
  var BrowserPageTracker = class {
11
10
  traceContext;
12
11
  nextPageId = 1;
@@ -168,7 +167,7 @@ var BrowserPageTracker = class {
168
167
  name,
169
168
  startTime,
170
169
  endTime: startTime,
171
- status: { code: SPAN_STATUS_CODE_UNSET$1 },
170
+ status: { code: SPAN_STATUS_CODE_UNSET$2 },
172
171
  attributes: pageAttributes({
173
172
  pageId,
174
173
  url,
@@ -332,13 +331,13 @@ function detectResourceTypeFromUrl(url) {
332
331
  * OpenTelemetry SpanKind values
333
332
  * @see https://opentelemetry.io/docs/specs/otel/trace/api/#spankind
334
333
  */
335
- const SPAN_KIND_CLIENT = 3;
334
+ const SPAN_KIND_CLIENT$1 = 3;
336
335
  /**
337
336
  * OpenTelemetry SpanStatusCode values
338
337
  * @see https://opentelemetry.io/docs/specs/otel/trace/api/#set-status
339
338
  */
340
- const SPAN_STATUS_CODE_UNSET = 0;
341
- const SPAN_STATUS_CODE_ERROR = 2;
339
+ const SPAN_STATUS_CODE_UNSET$1 = 0;
340
+ const SPAN_STATUS_CODE_ERROR$1 = 2;
342
341
  /**
343
342
  * Captures request/response data and stores the complete network span in the
344
343
  * current test trace context. Called after the request has completed.
@@ -357,8 +356,8 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
357
356
  const parsedUrl = new URL(url);
358
357
  const serverAddress = parsedUrl.hostname;
359
358
  const serverPort = parsedUrl.port !== "" ? Number.parseInt(parsedUrl.port, 10) : parsedUrl.protocol === "https:" ? 443 : 80;
360
- let statusCodeValue = SPAN_STATUS_CODE_UNSET;
361
- if (statusCode >= 400) statusCodeValue = SPAN_STATUS_CODE_ERROR;
359
+ let statusCodeValue = SPAN_STATUS_CODE_UNSET$1;
360
+ if (statusCode >= 400) statusCodeValue = SPAN_STATUS_CODE_ERROR$1;
362
361
  const resourceType = detectResourceType(await getResponseHeaderValue(response, "content-type"), url);
363
362
  const attributes = {
364
363
  "http.request.method": method,
@@ -371,19 +370,19 @@ async function fixtureCaptureRequestResponse({ request, response, traceContext }
371
370
  "browser.request.route_association": requestTraceContext.routeAssociation
372
371
  };
373
372
  if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
374
- if (statusCodeValue === SPAN_STATUS_CODE_ERROR) attributes["error.type"] = statusCode.toString();
373
+ if (statusCodeValue === SPAN_STATUS_CODE_ERROR$1) attributes["error.type"] = statusCode.toString();
375
374
  const networkSpan = {
376
375
  traceId: requestTraceContext.traceId,
377
376
  spanId: requestTraceContext.spanId,
378
377
  parentSpanId: requestTraceContext.parentSpanId,
379
378
  name: `HTTP ${method}`,
380
- kind: SPAN_KIND_CLIENT,
379
+ kind: SPAN_KIND_CLIENT$1,
381
380
  startTime,
382
381
  endTime,
383
382
  status: { code: statusCodeValue },
384
383
  attributes,
385
384
  events: [],
386
- serviceName: "playwright-browser"
385
+ serviceName: BROWSER_SERVICE_NAME
387
386
  };
388
387
  traceContext.addSpan(networkSpan);
389
388
  }
@@ -395,6 +394,120 @@ async function getResponseHeaderValue(response, name) {
395
394
  }
396
395
  }
397
396
  //#endregion
397
+ //#region src/fixture/test-fetch-capture.ts
398
+ const SPAN_KIND_CLIENT = 3;
399
+ const SPAN_STATUS_CODE_UNSET = 0;
400
+ const SPAN_STATUS_CODE_ERROR = 2;
401
+ let originalFetch;
402
+ let activeTraceContext;
403
+ function runWithTestFetchCapture(traceContext, callback) {
404
+ ensureFetchPatched();
405
+ const previousTraceContext = activeTraceContext;
406
+ activeTraceContext = traceContext;
407
+ return (async () => {
408
+ try {
409
+ return await callback();
410
+ } finally {
411
+ activeTraceContext = previousTraceContext;
412
+ }
413
+ })();
414
+ }
415
+ function ensureFetchPatched() {
416
+ if (globalThis.fetch === patchedFetch) return;
417
+ originalFetch = globalThis.fetch.bind(globalThis);
418
+ globalThis.fetch = patchedFetch;
419
+ }
420
+ const patchedFetch = async (input, init) => {
421
+ const traceContext = activeTraceContext;
422
+ if (!traceContext) return originalFetch ? originalFetch(input, init) : globalThis.fetch(input, init);
423
+ if (!originalFetch) return globalThis.fetch(input, init);
424
+ const startTime = /* @__PURE__ */ new Date();
425
+ try {
426
+ const response = await originalFetch(input, init);
427
+ traceContext.addSpan(createFetchSpan({
428
+ input,
429
+ init,
430
+ traceContext,
431
+ startTime,
432
+ endTime: /* @__PURE__ */ new Date(),
433
+ statusCode: response.status
434
+ }));
435
+ return response;
436
+ } catch (error) {
437
+ traceContext.addSpan(createFetchSpan({
438
+ input,
439
+ init,
440
+ traceContext,
441
+ startTime,
442
+ endTime: /* @__PURE__ */ new Date(),
443
+ error
444
+ }));
445
+ throw error;
446
+ }
447
+ };
448
+ function createFetchSpan({ input, init, traceContext, startTime, endTime, statusCode, error }) {
449
+ const method = getFetchMethod(input, init);
450
+ const attributes = createHttpAttributes({
451
+ method,
452
+ url: getFetchUrl(input),
453
+ statusCode,
454
+ error
455
+ });
456
+ const failed = error !== void 0 || statusCode !== void 0 && statusCode >= 400;
457
+ return {
458
+ traceId: traceContext.traceId,
459
+ spanId: generateSpanId(),
460
+ parentSpanId: traceContext.rootSpanId,
461
+ name: `HTTP ${method}`,
462
+ kind: SPAN_KIND_CLIENT,
463
+ startTime,
464
+ endTime,
465
+ status: failed ? {
466
+ code: SPAN_STATUS_CODE_ERROR,
467
+ message: errorMessage(error)
468
+ } : { code: SPAN_STATUS_CODE_UNSET },
469
+ attributes,
470
+ events: []
471
+ };
472
+ }
473
+ function createHttpAttributes({ method, url, statusCode, error }) {
474
+ const attributes = {
475
+ "http.request.method": method,
476
+ "http.resource.type": "fetch",
477
+ "url.full": url
478
+ };
479
+ try {
480
+ const parsedUrl = new URL(url);
481
+ attributes["url.path"] = parsedUrl.pathname;
482
+ attributes["server.address"] = parsedUrl.hostname;
483
+ attributes["server.port"] = serverPort(parsedUrl);
484
+ if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
485
+ } catch {}
486
+ if (statusCode !== void 0) {
487
+ attributes["http.response.status_code"] = statusCode;
488
+ if (statusCode >= 400) attributes["error.type"] = statusCode.toString();
489
+ } else if (error !== void 0) attributes["error.type"] = errorType(error);
490
+ return attributes;
491
+ }
492
+ function getFetchMethod(input, init) {
493
+ return (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
494
+ }
495
+ function getFetchUrl(input) {
496
+ if (input instanceof Request) return input.url;
497
+ return input.toString();
498
+ }
499
+ function serverPort(url) {
500
+ if (url.port) return Number.parseInt(url.port, 10);
501
+ return url.protocol === "https:" ? 443 : 80;
502
+ }
503
+ function errorType(error) {
504
+ if (error instanceof Error && error.name) return error.name;
505
+ return "Error";
506
+ }
507
+ function errorMessage(error) {
508
+ return error instanceof Error && error.message ? error.message : void 0;
509
+ }
510
+ //#endregion
398
511
  //#region src/fixture/playwright-opentelemetry-fixture.ts
399
512
  function createPlaywrightOtelTest(testBase) {
400
513
  return testBase.extend({
@@ -416,7 +529,7 @@ function createPlaywrightOtelTest(testBase) {
416
529
  testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
417
530
  const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
418
531
  const traceContext = await createTestTraceContext(testInfo);
419
- await use(traceContext);
532
+ await runWithTestFetchCapture(traceContext, () => use(traceContext));
420
533
  await flushFixtureSpans(traceContext, config, {
421
534
  trace: config.trace ?? trace,
422
535
  testInfo
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/index.ts
2
- var src_default = require("./reporter-k3LuaBV8.cjs").PlaywrightOpentelemetryReporter;
2
+ var src_default = require("./reporter-DszuIYsI.cjs").PlaywrightOpentelemetryReporter;
3
3
  //#endregion
4
4
  module.exports = src_default;
package/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- import { n as PlaywrightOpentelemetryUseOptions, r as PlaywrightTraceOption, t as PlaywrightOpentelemetryConfig } from "./config-Db932l_s.cjs";
1
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-C_APEwdC.cjs";
2
2
  import { t as PlaywrightOpentelemetryReporter } from "./reporter-DaCojFom.cjs";
3
- export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, PlaywrightOpentelemetryReporter as default };
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 { n as PlaywrightOpentelemetryUseOptions, r as PlaywrightTraceOption, t as PlaywrightOpentelemetryConfig } from "./config-Db932l_s.mjs";
1
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-C_APEwdC.mjs";
2
2
  import { t as PlaywrightOpentelemetryReporter } from "./reporter-DaCojFom.mjs";
3
- export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, PlaywrightOpentelemetryReporter as default };
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-BAfvjrKo.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-BGMoVKC7.mjs";
2
2
  //#region src/index.ts
3
3
  var src_default = PlaywrightOpentelemetryReporter;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { c as generateSpanId, l as generateTraceId, n as FIXTURE_SPANS_ATTACHMENT_NAME, o as shouldRetainPlaywrightTrace, r as TRACE_CONTEXT_ATTACHMENT_NAME, s as buildOtlpRequest, t as resolvePlaywrightOpentelemetryConfig, u as sendSpans } from "./config-Cec6zO6v.mjs";
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";
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";
@@ -77,14 +77,14 @@ async function createScreenshotsZip(screenshots) {
77
77
  return zipWriter.close();
78
78
  }
79
79
  async function createTraceZipBlob(options) {
80
- const { spans, fixtureSpans, serviceName, playwrightVersion, screenshots } = options;
81
- const otlpRequest = buildOtlpRequest(spans, serviceName, playwrightVersion);
80
+ const { spans, fixtureSpans, playwrightVersion, screenshots } = options;
81
+ const otlpRequest = buildOtlpRequest(spans, playwrightVersion);
82
82
  const traceJson = JSON.stringify(otlpRequest, null, 2);
83
83
  const zipWriter = new ZipWriter(new BlobWriter("application/zip"));
84
84
  await zipWriter.add("traces/playwright-opentelemetry.json", new Blob([traceJson]).stream());
85
85
  if (fixtureSpans.length > 0) {
86
- const fixtureOtlpRequest = buildOtlpRequest(fixtureSpans, "playwright-browser", playwrightVersion);
87
- await zipWriter.add("traces/playwright-browser.json", new Blob([JSON.stringify(fixtureOtlpRequest, null, 2)]).stream());
86
+ const fixtureOtlpRequest = buildOtlpRequest(fixtureSpans, playwrightVersion);
87
+ await zipWriter.add("traces/playwright-fixture-spans.json", new Blob([JSON.stringify(fixtureOtlpRequest, null, 2)]).stream());
88
88
  }
89
89
  await addScreenshotsToZip(zipWriter, screenshots);
90
90
  return zipWriter.close();
@@ -243,7 +243,7 @@ var PlaywrightOpentelemetryReporter = class {
243
243
  spans: testSpans,
244
244
  config
245
245
  });
246
- if (config.storeTraceZip || config.playwrightTraceApiEndpoint) {
246
+ if (config.storeTraceZip || hasTraceApiDestination(config)) {
247
247
  const prepared = this.prepareTraceArtifact({
248
248
  test,
249
249
  spans: testSpans,
@@ -268,20 +268,24 @@ var PlaywrightOpentelemetryReporter = class {
268
268
  }
269
269
  const destinations = /* @__PURE__ */ new Map();
270
270
  for (const batch of this.spanBatches) {
271
- if (batch.config.otlpEndpoint) addDestinationSpans(destinations, batch.spans, {
272
- tracesEndpoint: batch.config.otlpEndpoint,
273
- headers: batch.config.otlpHeaders,
274
- serviceName: batch.config.serviceName,
275
- playwrightVersion: this.playwrightVersion || "unknown",
276
- debug: batch.config.debug
277
- });
278
- if (batch.config.playwrightTraceApiEndpoint) addDestinationSpans(destinations, batch.spans, {
279
- tracesEndpoint: `${batch.config.playwrightTraceApiEndpoint}/v1/traces`,
280
- headers: batch.config.playwrightTraceApiHeaders,
281
- serviceName: batch.config.serviceName,
282
- playwrightVersion: this.playwrightVersion || "unknown",
283
- debug: batch.config.debug
284
- });
271
+ for (const destination of batch.config.otlpDestinations) {
272
+ if (!destination.url) continue;
273
+ addDestinationSpans(destinations, batch.spans, {
274
+ tracesEndpoint: destination.url,
275
+ headers: destination.headers,
276
+ playwrightVersion: this.playwrightVersion || "unknown",
277
+ debug: batch.config.debug
278
+ });
279
+ }
280
+ for (const destination of batch.config.playwrightTraceApiDestinations) {
281
+ if (!destination.url) continue;
282
+ addDestinationSpans(destinations, batch.spans, {
283
+ tracesEndpoint: `${destination.url}/v1/traces`,
284
+ headers: destination.headers,
285
+ playwrightVersion: this.playwrightVersion || "unknown",
286
+ debug: batch.config.debug
287
+ });
288
+ }
285
289
  }
286
290
  for (const destination of destinations.values()) await sendSpans(destination.spans, destination.options);
287
291
  }
@@ -291,16 +295,15 @@ var PlaywrightOpentelemetryReporter = class {
291
295
  test: options.test,
292
296
  spans: options.spans,
293
297
  fixtureSpans: options.fixtureSpans,
294
- serviceName: options.config.serviceName,
295
298
  playwrightVersion: options.playwrightVersion,
296
299
  screenshots
297
300
  }) : void 0;
298
- const uploadPromise = options.config.playwrightTraceApiEndpoint ? this.sendScreenshotsZipToTraceApi({
301
+ const uploadPromises = options.config.playwrightTraceApiDestinations.filter((destination) => destination.url).map((destination) => this.sendScreenshotsZipToTraceApi({
299
302
  traceId: options.traceId,
300
303
  screenshots,
301
- config: options.config
302
- }) : void 0;
303
- const [traceZipBlob] = await Promise.all([traceZipBlobPromise, uploadPromise]);
304
+ destination
305
+ }));
306
+ const [traceZipBlob] = await Promise.all([traceZipBlobPromise, ...uploadPromises]);
304
307
  return { traceZipBlob };
305
308
  }
306
309
  processTestStep(test, step, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds) {
@@ -360,15 +363,15 @@ var PlaywrightOpentelemetryReporter = class {
360
363
  return this.debug;
361
364
  }
362
365
  async sendScreenshotsZipToTraceApi(params) {
363
- const { traceId, screenshots, config } = params;
366
+ const { traceId, screenshots, destination } = params;
364
367
  const screenshotsZip = await createScreenshotsZip(screenshots);
365
- const screenshotUrl = `${config.playwrightTraceApiEndpoint}/playwright-otel-reporter/v1/screenshots.zip`;
368
+ const screenshotUrl = `${destination.url}/playwright-otel-reporter/v1/screenshots.zip`;
366
369
  const response = await fetch(screenshotUrl, {
367
370
  method: "PUT",
368
371
  headers: {
369
372
  "content-type": "application/zip",
370
373
  "x-trace-id": traceId,
371
- ...config.playwrightTraceApiHeaders
374
+ ...destination.headers
372
375
  },
373
376
  body: screenshotsZip
374
377
  });
@@ -401,6 +404,9 @@ function addDestinationSpans(destinations, spans, options) {
401
404
  options
402
405
  });
403
406
  }
407
+ function hasTraceApiDestination(config) {
408
+ return config.playwrightTraceApiDestinations.some((destination) => destination.url);
409
+ }
404
410
  function readTraceContextAttachment(result, testId) {
405
411
  const attachment = result.attachments.find((attachment) => attachment.name === TRACE_CONTEXT_ATTACHMENT_NAME);
406
412
  if (!attachment?.body) return {
@@ -1,4 +1,4 @@
1
- const require_config = require("./config-DtWFdgrv.cjs");
1
+ const require_config = require("./config-Csi-apHL.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");
@@ -79,14 +79,14 @@ async function createScreenshotsZip(screenshots) {
79
79
  return zipWriter.close();
80
80
  }
81
81
  async function createTraceZipBlob(options) {
82
- const { spans, fixtureSpans, serviceName, playwrightVersion, screenshots } = options;
83
- const otlpRequest = require_config.buildOtlpRequest(spans, serviceName, playwrightVersion);
82
+ const { spans, fixtureSpans, playwrightVersion, screenshots } = options;
83
+ const otlpRequest = require_config.buildOtlpRequest(spans, playwrightVersion);
84
84
  const traceJson = JSON.stringify(otlpRequest, null, 2);
85
85
  const zipWriter = new _zip_js_zip_js.ZipWriter(new _zip_js_zip_js.BlobWriter("application/zip"));
86
86
  await zipWriter.add("traces/playwright-opentelemetry.json", new Blob([traceJson]).stream());
87
87
  if (fixtureSpans.length > 0) {
88
- const fixtureOtlpRequest = require_config.buildOtlpRequest(fixtureSpans, "playwright-browser", playwrightVersion);
89
- await zipWriter.add("traces/playwright-browser.json", new Blob([JSON.stringify(fixtureOtlpRequest, null, 2)]).stream());
88
+ const fixtureOtlpRequest = require_config.buildOtlpRequest(fixtureSpans, playwrightVersion);
89
+ await zipWriter.add("traces/playwright-fixture-spans.json", new Blob([JSON.stringify(fixtureOtlpRequest, null, 2)]).stream());
90
90
  }
91
91
  await addScreenshotsToZip(zipWriter, screenshots);
92
92
  return zipWriter.close();
@@ -245,7 +245,7 @@ var PlaywrightOpentelemetryReporter = class {
245
245
  spans: testSpans,
246
246
  config
247
247
  });
248
- if (config.storeTraceZip || config.playwrightTraceApiEndpoint) {
248
+ if (config.storeTraceZip || hasTraceApiDestination(config)) {
249
249
  const prepared = this.prepareTraceArtifact({
250
250
  test,
251
251
  spans: testSpans,
@@ -270,20 +270,24 @@ var PlaywrightOpentelemetryReporter = class {
270
270
  }
271
271
  const destinations = /* @__PURE__ */ new Map();
272
272
  for (const batch of this.spanBatches) {
273
- if (batch.config.otlpEndpoint) addDestinationSpans(destinations, batch.spans, {
274
- tracesEndpoint: batch.config.otlpEndpoint,
275
- headers: batch.config.otlpHeaders,
276
- serviceName: batch.config.serviceName,
277
- playwrightVersion: this.playwrightVersion || "unknown",
278
- debug: batch.config.debug
279
- });
280
- if (batch.config.playwrightTraceApiEndpoint) addDestinationSpans(destinations, batch.spans, {
281
- tracesEndpoint: `${batch.config.playwrightTraceApiEndpoint}/v1/traces`,
282
- headers: batch.config.playwrightTraceApiHeaders,
283
- serviceName: batch.config.serviceName,
284
- playwrightVersion: this.playwrightVersion || "unknown",
285
- debug: batch.config.debug
286
- });
273
+ for (const destination of batch.config.otlpDestinations) {
274
+ if (!destination.url) continue;
275
+ addDestinationSpans(destinations, batch.spans, {
276
+ tracesEndpoint: destination.url,
277
+ headers: destination.headers,
278
+ playwrightVersion: this.playwrightVersion || "unknown",
279
+ debug: batch.config.debug
280
+ });
281
+ }
282
+ for (const destination of batch.config.playwrightTraceApiDestinations) {
283
+ if (!destination.url) continue;
284
+ addDestinationSpans(destinations, batch.spans, {
285
+ tracesEndpoint: `${destination.url}/v1/traces`,
286
+ headers: destination.headers,
287
+ playwrightVersion: this.playwrightVersion || "unknown",
288
+ debug: batch.config.debug
289
+ });
290
+ }
287
291
  }
288
292
  for (const destination of destinations.values()) await require_config.sendSpans(destination.spans, destination.options);
289
293
  }
@@ -293,16 +297,15 @@ var PlaywrightOpentelemetryReporter = class {
293
297
  test: options.test,
294
298
  spans: options.spans,
295
299
  fixtureSpans: options.fixtureSpans,
296
- serviceName: options.config.serviceName,
297
300
  playwrightVersion: options.playwrightVersion,
298
301
  screenshots
299
302
  }) : void 0;
300
- const uploadPromise = options.config.playwrightTraceApiEndpoint ? this.sendScreenshotsZipToTraceApi({
303
+ const uploadPromises = options.config.playwrightTraceApiDestinations.filter((destination) => destination.url).map((destination) => this.sendScreenshotsZipToTraceApi({
301
304
  traceId: options.traceId,
302
305
  screenshots,
303
- config: options.config
304
- }) : void 0;
305
- const [traceZipBlob] = await Promise.all([traceZipBlobPromise, uploadPromise]);
306
+ destination
307
+ }));
308
+ const [traceZipBlob] = await Promise.all([traceZipBlobPromise, ...uploadPromises]);
306
309
  return { traceZipBlob };
307
310
  }
308
311
  processTestStep(test, step, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds) {
@@ -362,15 +365,15 @@ var PlaywrightOpentelemetryReporter = class {
362
365
  return this.debug;
363
366
  }
364
367
  async sendScreenshotsZipToTraceApi(params) {
365
- const { traceId, screenshots, config } = params;
368
+ const { traceId, screenshots, destination } = params;
366
369
  const screenshotsZip = await createScreenshotsZip(screenshots);
367
- const screenshotUrl = `${config.playwrightTraceApiEndpoint}/playwright-otel-reporter/v1/screenshots.zip`;
370
+ const screenshotUrl = `${destination.url}/playwright-otel-reporter/v1/screenshots.zip`;
368
371
  const response = await fetch(screenshotUrl, {
369
372
  method: "PUT",
370
373
  headers: {
371
374
  "content-type": "application/zip",
372
375
  "x-trace-id": traceId,
373
- ...config.playwrightTraceApiHeaders
376
+ ...destination.headers
374
377
  },
375
378
  body: screenshotsZip
376
379
  });
@@ -403,6 +406,9 @@ function addDestinationSpans(destinations, spans, options) {
403
406
  options
404
407
  });
405
408
  }
409
+ function hasTraceApiDestination(config) {
410
+ return config.playwrightTraceApiDestinations.some((destination) => destination.url);
411
+ }
406
412
  function readTraceContextAttachment(result, testId) {
407
413
  const attachment = result.attachments.find((attachment) => attachment.name === require_config.TRACE_CONTEXT_ATTACHMENT_NAME);
408
414
  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-k3LuaBV8.cjs").PlaywrightOpentelemetryReporter;
2
+ var reporter_default = require("./reporter-DszuIYsI.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-BAfvjrKo.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-BGMoVKC7.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.9.0",
3
+ "version": "0.11.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",