playwright-opentelemetry 0.13.1 → 0.13.3

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/README.md CHANGED
@@ -87,3 +87,16 @@ Full documentation, including trace retention options, screenshot capture, multi
87
87
  ## License
88
88
 
89
89
  [Apache-2.0](https://github.com/endformdev/playwright-opentelemetry/blob/main/LICENSE), built by [Endform](https://endform.dev).
90
+
91
+ ### Browser navigation indexes
92
+
93
+ Document load spans (`browser.page`) carry `browser.page.navigation.index`,
94
+ starting at 0 and increasing for each document span within the same Playwright
95
+ page (`browser.page.id`). Page IDs are generated by the reporter, starting at
96
+ `page-0` for each test tracker. Reloads also advance the document index.
97
+
98
+ SPA navigation spans (`browser.route`) carry only their local
99
+ `browser.route.navigation.index`; the document index stays on the parent span.
100
+ The route index starts at 0 and resets on each document load. Ignored URL updates,
101
+ such as hash-only changes, do not advance it. Each Playwright page has independent
102
+ counters.
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.13.1";
2
+ var version = "0.13.3";
3
3
  const PLAYWRIGHT_TRACE_API_SOURCE_HEADER = "x-playwright-otel-source";
4
4
  const PLAYWRIGHT_TRACE_API_SOURCE_REPORTER = "reporter";
5
5
  function withPlaywrightTraceApiHeaders(headers) {
@@ -21,7 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
  //#endregion
23
23
  //#region package.json
24
- var version = "0.13.1";
24
+ var version = "0.13.3";
25
25
  const PLAYWRIGHT_TRACE_API_SOURCE_HEADER = "x-playwright-otel-source";
26
26
  const PLAYWRIGHT_TRACE_API_SOURCE_REPORTER = "reporter";
27
27
  function withPlaywrightTraceApiHeaders(headers) {
package/dist/fixture.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_config = require("./config-CA6DXotG.cjs");
2
+ const require_config = require("./config-Dl2qORR5.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");
@@ -9,7 +9,7 @@ const BROWSER_ROUTE_SPAN_NAME = "browser.route";
9
9
  const SPAN_STATUS_CODE_UNSET$3 = 0;
10
10
  var BrowserPageTracker = class {
11
11
  traceContext;
12
- nextPageId = 1;
12
+ nextPageId = 0;
13
13
  pageStates = /* @__PURE__ */ new WeakMap();
14
14
  pages = /* @__PURE__ */ new Set();
15
15
  constructor(traceContext) {
@@ -96,8 +96,11 @@ var BrowserPageTracker = class {
96
96
  startDocumentPageSpan(page, url, startTime) {
97
97
  const state = this.stateFor(page);
98
98
  this.finishPageSpans(page, startTime);
99
+ state.documentIndex += 1;
100
+ state.routeIndex = -1;
99
101
  const span = this.createBrowserSpan({
100
102
  pageId: state.pageId,
103
+ documentIndex: state.documentIndex,
101
104
  name: BROWSER_PAGE_SPAN_NAME,
102
105
  url,
103
106
  navigationType: "document",
@@ -117,6 +120,7 @@ var BrowserPageTracker = class {
117
120
  this.finishRouteSpan(state, startTime);
118
121
  const span = this.createBrowserSpan({
119
122
  pageId: state.pageId,
123
+ routeIndex: ++state.routeIndex,
120
124
  name: BROWSER_ROUTE_SPAN_NAME,
121
125
  url,
122
126
  navigationType: "same-document",
@@ -155,12 +159,14 @@ var BrowserPageTracker = class {
155
159
  if (existing) return existing;
156
160
  const state = {
157
161
  pageId: `page-${this.nextPageId++}`,
158
- lastUrl: page.url()
162
+ lastUrl: page.url(),
163
+ documentIndex: -1,
164
+ routeIndex: -1
159
165
  };
160
166
  this.pageStates.set(page, state);
161
167
  return state;
162
168
  }
163
- createBrowserSpan({ pageId, name, url, navigationType, parentSpanId, startTime, previousUrl, documentUrl }) {
169
+ createBrowserSpan({ pageId, documentIndex, routeIndex, name, url, navigationType, parentSpanId, startTime, previousUrl, documentUrl }) {
164
170
  return {
165
171
  traceId: this.traceContext.traceId,
166
172
  spanId: require_config.generateSpanId(),
@@ -171,6 +177,8 @@ var BrowserPageTracker = class {
171
177
  status: { code: SPAN_STATUS_CODE_UNSET$3 },
172
178
  attributes: pageAttributes({
173
179
  pageId,
180
+ documentIndex,
181
+ routeIndex,
174
182
  url,
175
183
  navigationType,
176
184
  previousUrl,
@@ -194,7 +202,7 @@ function consoleSeverityText(type) {
194
202
  function consoleLocationLine(location) {
195
203
  return location.line ?? location.lineNumber;
196
204
  }
197
- function pageAttributes({ pageId, url, navigationType, previousUrl, documentUrl }) {
205
+ function pageAttributes({ pageId, documentIndex, routeIndex, url, navigationType, previousUrl, documentUrl }) {
198
206
  const attributes = {
199
207
  "browser.resource.type": navigationType === "document" ? "page" : "route",
200
208
  "browser.page.id": pageId,
@@ -206,6 +214,8 @@ function pageAttributes({ pageId, url, navigationType, previousUrl, documentUrl
206
214
  attributes["url.path"] = parsedUrl.pathname;
207
215
  if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
208
216
  } catch {}
217
+ if (documentIndex !== void 0) attributes["browser.page.navigation.index"] = documentIndex;
218
+ if (routeIndex !== void 0) attributes["browser.route.navigation.index"] = routeIndex;
209
219
  if (previousUrl) attributes["browser.route.previous_url"] = previousUrl;
210
220
  if (documentUrl) attributes["browser.document.url"] = documentUrl;
211
221
  return attributes;
package/dist/fixture.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as createTestTraceContext, n as BROWSER_SERVICE_NAME, o as flushFixtureSpans, p as generateSpanId, s as registerExpectedTrace, t as resolvePlaywrightOpentelemetryConfig } from "./config-DRADaT5x.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-DOwhIeqJ.mjs";
2
2
  import path from "node:path";
3
3
  import { test as test$1 } from "@playwright/test";
4
4
  export * from "@playwright/test";
@@ -8,7 +8,7 @@ const BROWSER_ROUTE_SPAN_NAME = "browser.route";
8
8
  const SPAN_STATUS_CODE_UNSET$3 = 0;
9
9
  var BrowserPageTracker = class {
10
10
  traceContext;
11
- nextPageId = 1;
11
+ nextPageId = 0;
12
12
  pageStates = /* @__PURE__ */ new WeakMap();
13
13
  pages = /* @__PURE__ */ new Set();
14
14
  constructor(traceContext) {
@@ -95,8 +95,11 @@ var BrowserPageTracker = class {
95
95
  startDocumentPageSpan(page, url, startTime) {
96
96
  const state = this.stateFor(page);
97
97
  this.finishPageSpans(page, startTime);
98
+ state.documentIndex += 1;
99
+ state.routeIndex = -1;
98
100
  const span = this.createBrowserSpan({
99
101
  pageId: state.pageId,
102
+ documentIndex: state.documentIndex,
100
103
  name: BROWSER_PAGE_SPAN_NAME,
101
104
  url,
102
105
  navigationType: "document",
@@ -116,6 +119,7 @@ var BrowserPageTracker = class {
116
119
  this.finishRouteSpan(state, startTime);
117
120
  const span = this.createBrowserSpan({
118
121
  pageId: state.pageId,
122
+ routeIndex: ++state.routeIndex,
119
123
  name: BROWSER_ROUTE_SPAN_NAME,
120
124
  url,
121
125
  navigationType: "same-document",
@@ -154,12 +158,14 @@ var BrowserPageTracker = class {
154
158
  if (existing) return existing;
155
159
  const state = {
156
160
  pageId: `page-${this.nextPageId++}`,
157
- lastUrl: page.url()
161
+ lastUrl: page.url(),
162
+ documentIndex: -1,
163
+ routeIndex: -1
158
164
  };
159
165
  this.pageStates.set(page, state);
160
166
  return state;
161
167
  }
162
- createBrowserSpan({ pageId, name, url, navigationType, parentSpanId, startTime, previousUrl, documentUrl }) {
168
+ createBrowserSpan({ pageId, documentIndex, routeIndex, name, url, navigationType, parentSpanId, startTime, previousUrl, documentUrl }) {
163
169
  return {
164
170
  traceId: this.traceContext.traceId,
165
171
  spanId: generateSpanId(),
@@ -170,6 +176,8 @@ var BrowserPageTracker = class {
170
176
  status: { code: SPAN_STATUS_CODE_UNSET$3 },
171
177
  attributes: pageAttributes({
172
178
  pageId,
179
+ documentIndex,
180
+ routeIndex,
173
181
  url,
174
182
  navigationType,
175
183
  previousUrl,
@@ -193,7 +201,7 @@ function consoleSeverityText(type) {
193
201
  function consoleLocationLine(location) {
194
202
  return location.line ?? location.lineNumber;
195
203
  }
196
- function pageAttributes({ pageId, url, navigationType, previousUrl, documentUrl }) {
204
+ function pageAttributes({ pageId, documentIndex, routeIndex, url, navigationType, previousUrl, documentUrl }) {
197
205
  const attributes = {
198
206
  "browser.resource.type": navigationType === "document" ? "page" : "route",
199
207
  "browser.page.id": pageId,
@@ -205,6 +213,8 @@ function pageAttributes({ pageId, url, navigationType, previousUrl, documentUrl
205
213
  attributes["url.path"] = parsedUrl.pathname;
206
214
  if (parsedUrl.search) attributes["url.query"] = parsedUrl.search.slice(1);
207
215
  } catch {}
216
+ if (documentIndex !== void 0) attributes["browser.page.navigation.index"] = documentIndex;
217
+ if (routeIndex !== void 0) attributes["browser.route.navigation.index"] = routeIndex;
208
218
  if (previousUrl) attributes["browser.route.previous_url"] = previousUrl;
209
219
  if (documentUrl) attributes["browser.document.url"] = documentUrl;
210
220
  return attributes;
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/index.ts
2
- var src_default = require("./reporter-DVhgDdJ7.cjs").PlaywrightOpentelemetryReporter;
2
+ var src_default = require("./reporter-Curmeux7.cjs").PlaywrightOpentelemetryReporter;
3
3
  //#endregion
4
4
  module.exports = src_default;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as PlaywrightOpentelemetryReporter } from "./reporter-D322isqC.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-DeNfLQ5b.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-CA6DXotG.cjs");
1
+ const require_config = require("./config-Dl2qORR5.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");
@@ -17,6 +17,7 @@ const TEST_STEP_SPAN_NAME = "playwright.test.step";
17
17
  const ATTR_TEST_STEP_NAME = "test.step.name";
18
18
  const ATTR_TEST_STEP_TITLE = "test.step.title";
19
19
  const ATTR_TEST_STEP_CATEGORY = "test.step.category";
20
+ const ATTR_TEST_PHASE = "playwright.test.phase";
20
21
  //#endregion
21
22
  //#region src/reporter/trace-zip-builder.ts
22
23
  /**
@@ -324,16 +325,21 @@ var PlaywrightOpentelemetryReporter = class {
324
325
  const [traceZipBlob] = await Promise.all([traceZipBlobPromise, ...uploadPromises]);
325
326
  return { traceZipBlob };
326
327
  }
327
- processTestStep(test, step, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds) {
328
+ processTestStep(test, step, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds, inheritedPhase) {
329
+ let phase = inheritedPhase;
330
+ if (step.category === "hook") {
331
+ if (step.title === "Before Hooks") phase = "before";
332
+ if (step.title === "After Hooks" || step.title === "Worker Cleanup") phase = "after";
333
+ }
328
334
  const stepId = getStepId(test, step);
329
335
  if (isInternalFixtureStep(step) || isInternalApiRequestStep(step)) {
330
336
  skippedStepIds.add(stepId);
331
337
  processedSteps.delete(stepId);
332
- if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds);
338
+ if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds, phase);
333
339
  return;
334
340
  }
335
341
  if (skippedStepIds.has(stepId)) {
336
- if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds);
342
+ if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds, phase);
337
343
  return;
338
344
  }
339
345
  const currentTitlePath = [...parentTitlePath, step.title];
@@ -346,13 +352,14 @@ var PlaywrightOpentelemetryReporter = class {
346
352
  existingSpan.attributes[ATTR_CODE_FILE_PATH] = relativePath;
347
353
  existingSpan.attributes[ATTR_CODE_LINE_NUMBER] = line;
348
354
  }
349
- if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, existingSpan.spanId, traceId, currentTitlePath, processedSteps, skippedStepIds);
355
+ if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, existingSpan.spanId, traceId, currentTitlePath, processedSteps, skippedStepIds, phase);
350
356
  return;
351
357
  }
352
358
  const attributes = {};
353
359
  attributes[ATTR_TEST_STEP_NAME] = currentTitlePath.join(" > ");
354
360
  attributes[ATTR_TEST_STEP_TITLE] = step.title;
355
361
  attributes[ATTR_TEST_STEP_CATEGORY] = step.category;
362
+ if (phase) attributes[ATTR_TEST_PHASE] = phase;
356
363
  if (step.location) {
357
364
  const { file, line } = step.location;
358
365
  attributes[ATTR_CODE_FILE_PATH] = this.rootDir ? node_path.default.relative(this.rootDir, file) : file;
@@ -369,7 +376,7 @@ var PlaywrightOpentelemetryReporter = class {
369
376
  };
370
377
  if (step.error) stepSpan.status = errorStatus(step.error.message);
371
378
  processedSteps.set(stepId, stepSpan);
372
- if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, stepSpan.spanId, traceId, currentTitlePath, processedSteps, skippedStepIds);
379
+ if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, stepSpan.spanId, traceId, currentTitlePath, processedSteps, skippedStepIds, phase);
373
380
  }
374
381
  onStdOut(chunk, _test, _result) {
375
382
  if (this.debug) console.log(chunk.toString().slice(0, -1));
@@ -1,4 +1,4 @@
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-DRADaT5x.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-DOwhIeqJ.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";
@@ -15,6 +15,7 @@ const TEST_STEP_SPAN_NAME = "playwright.test.step";
15
15
  const ATTR_TEST_STEP_NAME = "test.step.name";
16
16
  const ATTR_TEST_STEP_TITLE = "test.step.title";
17
17
  const ATTR_TEST_STEP_CATEGORY = "test.step.category";
18
+ const ATTR_TEST_PHASE = "playwright.test.phase";
18
19
  //#endregion
19
20
  //#region src/reporter/trace-zip-builder.ts
20
21
  /**
@@ -322,16 +323,21 @@ var PlaywrightOpentelemetryReporter = class {
322
323
  const [traceZipBlob] = await Promise.all([traceZipBlobPromise, ...uploadPromises]);
323
324
  return { traceZipBlob };
324
325
  }
325
- processTestStep(test, step, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds) {
326
+ processTestStep(test, step, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds, inheritedPhase) {
327
+ let phase = inheritedPhase;
328
+ if (step.category === "hook") {
329
+ if (step.title === "Before Hooks") phase = "before";
330
+ if (step.title === "After Hooks" || step.title === "Worker Cleanup") phase = "after";
331
+ }
326
332
  const stepId = getStepId(test, step);
327
333
  if (isInternalFixtureStep(step) || isInternalApiRequestStep(step)) {
328
334
  skippedStepIds.add(stepId);
329
335
  processedSteps.delete(stepId);
330
- if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds);
336
+ if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds, phase);
331
337
  return;
332
338
  }
333
339
  if (skippedStepIds.has(stepId)) {
334
- if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds);
340
+ if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, parentSpanId, traceId, parentTitlePath, processedSteps, skippedStepIds, phase);
335
341
  return;
336
342
  }
337
343
  const currentTitlePath = [...parentTitlePath, step.title];
@@ -344,13 +350,14 @@ var PlaywrightOpentelemetryReporter = class {
344
350
  existingSpan.attributes[ATTR_CODE_FILE_PATH] = relativePath;
345
351
  existingSpan.attributes[ATTR_CODE_LINE_NUMBER] = line;
346
352
  }
347
- if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, existingSpan.spanId, traceId, currentTitlePath, processedSteps, skippedStepIds);
353
+ if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, existingSpan.spanId, traceId, currentTitlePath, processedSteps, skippedStepIds, phase);
348
354
  return;
349
355
  }
350
356
  const attributes = {};
351
357
  attributes[ATTR_TEST_STEP_NAME] = currentTitlePath.join(" > ");
352
358
  attributes[ATTR_TEST_STEP_TITLE] = step.title;
353
359
  attributes[ATTR_TEST_STEP_CATEGORY] = step.category;
360
+ if (phase) attributes[ATTR_TEST_PHASE] = phase;
354
361
  if (step.location) {
355
362
  const { file, line } = step.location;
356
363
  attributes[ATTR_CODE_FILE_PATH] = this.rootDir ? path.relative(this.rootDir, file) : file;
@@ -367,7 +374,7 @@ var PlaywrightOpentelemetryReporter = class {
367
374
  };
368
375
  if (step.error) stepSpan.status = errorStatus(step.error.message);
369
376
  processedSteps.set(stepId, stepSpan);
370
- if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, stepSpan.spanId, traceId, currentTitlePath, processedSteps, skippedStepIds);
377
+ if (step.steps && step.steps.length > 0) for (const childStep of step.steps) this.processTestStep(test, childStep, stepSpan.spanId, traceId, currentTitlePath, processedSteps, skippedStepIds, phase);
371
378
  }
372
379
  onStdOut(chunk, _test, _result) {
373
380
  if (this.debug) console.log(chunk.toString().slice(0, -1));
package/dist/reporter.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/reporter/index.ts
2
- var reporter_default = require("./reporter-DVhgDdJ7.cjs").PlaywrightOpentelemetryReporter;
2
+ var reporter_default = require("./reporter-Curmeux7.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-D322isqC.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-DeNfLQ5b.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.13.1",
3
+ "version": "0.13.3",
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",