playwright-opentelemetry 0.13.5 → 0.14.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,6 +1,6 @@
1
- import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-DhuwcBzL.mjs";
1
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-DFY22ysa.mjs";
2
2
  import { n as SpanEvent, t as Span } from "./otel-D0ztpic2.mjs";
3
- import { ConsoleMessage, Page, Request } from "@playwright/test";
3
+ import { BrowserContext, ConsoleMessage, Page, Request } from "@playwright/test";
4
4
  export * from "@playwright/test";
5
5
 
6
6
  //#region src/fixture/trace-context.d.ts
@@ -31,6 +31,8 @@ declare class BrowserPageTracker {
31
31
  private pages;
32
32
  constructor(traceContext: TestTraceContext);
33
33
  registerPage(page: Page): void;
34
+ /** The `browser.page.id` used for this page's spans and screenshots. */
35
+ pageIdFor(page: Page): string;
34
36
  unregisterPage(page: Page, endTime?: Date): void;
35
37
  finishAll(endTime?: Date): void;
36
38
  startDocumentNavigation(request: Request): void;
@@ -50,6 +52,51 @@ declare class BrowserPageTracker {
50
52
  private createBrowserSpan;
51
53
  }
52
54
  //#endregion
55
+ //#region src/fixture/screencast-capture.d.ts
56
+ interface CapturedFrame {
57
+ pageId: string;
58
+ timestamp: number;
59
+ file: string;
60
+ path: string;
61
+ viewportWidth?: number;
62
+ viewportHeight?: number;
63
+ }
64
+ /**
65
+ * Captures screencast frames from every page opened during a test and writes
66
+ * the kept frames to a temporary directory.
67
+ */
68
+ declare class ScreencastCapture {
69
+ readonly dir: string;
70
+ private readonly pageIdFor;
71
+ private readonly pages;
72
+ private readonly contexts;
73
+ private readonly frames;
74
+ private readonly writes;
75
+ private readonly files;
76
+ private readonly apiCalls;
77
+ private stopped;
78
+ private constructor();
79
+ /**
80
+ * Contexts are added by the caller with `addContext`.
81
+ *
82
+ * @param playwright The `playwright` fixture. Its private connection shows
83
+ * which page each API call acts on; without it, activity is detected from
84
+ * the frames.
85
+ */
86
+ static start(options: {
87
+ playwright: unknown;
88
+ pageIdFor: (page: Page) => string;
89
+ }): Promise<ScreencastCapture>;
90
+ addContext(context: BrowserContext): void;
91
+ addPage(page: Page): void;
92
+ /** Stops capturing and returns the kept frames, oldest first. */
93
+ stop(): Promise<CapturedFrame[]>;
94
+ dispose(): Promise<void>;
95
+ private unthrottle;
96
+ private keepFrame;
97
+ private uniqueFileName;
98
+ }
99
+ //#endregion
53
100
  //#region src/fixture/index.d.ts
54
101
  declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & PlaywrightOpentelemetryUseOptions & {
55
102
  testTraceInfo: {
@@ -58,8 +105,10 @@ declare const test: import("@playwright/test").TestType<import("@playwright/test
58
105
  };
59
106
  testTraceContext: TestTraceContext;
60
107
  browserPageTracker: BrowserPageTracker;
108
+ screencastCapture: ScreencastCapture | undefined;
61
109
  }, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions & {
62
110
  _playwrightOpentelemetryReporterCheck: void;
111
+ _playwrightOpentelemetryNewContexts: Set<(context: import("@playwright/test").BrowserContext) => void>;
63
112
  }>;
64
113
  //#endregion
65
114
  export { type PlaywrightOpentelemetryConfig, type PlaywrightOpentelemetryDestination, type PlaywrightOpentelemetryUseOptions, type PlaywrightTraceOption, test };
package/dist/fixture.mjs CHANGED
@@ -1,6 +1,8 @@
1
- import { a as createTestTraceContext, n as BROWSER_SERVICE_NAME, o as flushFixtureSpans, p as generateSpanId, s as registerExpectedTrace, t as resolvePlaywrightOpentelemetryConfig } from "./config-CiYAieDt.mjs";
1
+ import { a as supportsScreencastScreenshots, d as flushFixtureSpans, f as registerExpectedTrace, h as filterRetainedDestinations, m as shouldRetainPlaywrightTrace, o as resolvePlaywrightOpentelemetryConfig, p as couldRetainPlaywrightTrace, r as createScreenshotsZip, s as BROWSER_SERVICE_NAME, t as SCREENSHOTS_ATTACHMENT_NAME, u as createTestTraceContext, y as generateSpanId } from "./screenshots-zip-DXk2R8_S.mjs";
2
+ import fs from "node:fs/promises";
2
3
  import path from "node:path";
3
4
  import { test as test$1 } from "@playwright/test";
5
+ import os from "node:os";
4
6
  export * from "@playwright/test";
5
7
  //#region src/fixture/browser-page-tracker.ts
6
8
  const BROWSER_PAGE_SPAN_NAME = "browser.page";
@@ -18,6 +20,10 @@ var BrowserPageTracker = class {
18
20
  this.stateFor(page);
19
21
  this.pages.add(page);
20
22
  }
23
+ /** The `browser.page.id` used for this page's spans and screenshots. */
24
+ pageIdFor(page) {
25
+ return this.stateFor(page).pageId;
26
+ }
21
27
  unregisterPage(page, endTime = /* @__PURE__ */ new Date()) {
22
28
  this.finishPageSpans(page, endTime);
23
29
  this.pages.delete(page);
@@ -533,6 +539,372 @@ async function getResponseHeaders(response) {
533
539
  return null;
534
540
  }
535
541
  }
542
+ const PAGE_CHANNEL_TYPES = new Set([
543
+ "Page",
544
+ "Frame",
545
+ "ElementHandle",
546
+ "JSHandle"
547
+ ]);
548
+ const UNKNOWN_PAGE = Symbol("unknown page");
549
+ /**
550
+ * Decides which screencast frames to keep, mirroring Playwright's trace
551
+ * recorder. Normally it keeps one frame and holds back its acknowledgement for
552
+ * SCREENCAST_THROTTLE_MS, so the browser slows down and frames that still
553
+ * arrive in between are dropped. For SCREENCAST_UNTHROTTLE_MS after
554
+ * `unthrottle()`, it keeps and acknowledges every frame.
555
+ */
556
+ var ScreencastFrameThrottle = class {
557
+ keep;
558
+ now;
559
+ unthrottledUntil = Number.NEGATIVE_INFINITY;
560
+ pendingAck;
561
+ constructor(keep, now = () => performance.now()) {
562
+ this.keep = keep;
563
+ this.now = now;
564
+ }
565
+ onFrame(frame) {
566
+ if (this.now() < this.unthrottledUntil) {
567
+ this.keep(frame);
568
+ return;
569
+ }
570
+ if (this.pendingAck) return;
571
+ this.keep(frame);
572
+ return new Promise((resolve) => {
573
+ this.pendingAck = {
574
+ resolve,
575
+ timer: setTimeout(() => this.clearPendingAck(), 200)
576
+ };
577
+ });
578
+ }
579
+ unthrottle() {
580
+ this.unthrottledUntil = this.now() + 500;
581
+ this.clearPendingAck();
582
+ }
583
+ dispose() {
584
+ this.unthrottledUntil = Number.NEGATIVE_INFINITY;
585
+ this.clearPendingAck();
586
+ }
587
+ clearPendingAck() {
588
+ if (!this.pendingAck) return;
589
+ clearTimeout(this.pendingAck.timer);
590
+ this.pendingAck.resolve();
591
+ this.pendingAck = void 0;
592
+ }
593
+ };
594
+ /**
595
+ * Captures screencast frames from every page opened during a test and writes
596
+ * the kept frames to a temporary directory.
597
+ */
598
+ var ScreencastCapture = class ScreencastCapture {
599
+ dir;
600
+ pageIdFor;
601
+ pages = /* @__PURE__ */ new Map();
602
+ contexts = /* @__PURE__ */ new Map();
603
+ frames = [];
604
+ writes = /* @__PURE__ */ new Set();
605
+ files = /* @__PURE__ */ new Set();
606
+ apiCalls;
607
+ stopped = false;
608
+ constructor(dir, pageIdFor, playwright) {
609
+ this.dir = dir;
610
+ this.pageIdFor = pageIdFor;
611
+ this.apiCalls = PageApiCallHook.install(playwright, (page) => this.unthrottle(page));
612
+ if (!this.apiCalls) warnOnce("api-calls", "playwright-opentelemetry: this Playwright version doesn't expose the API call hook screenshots use. Screenshots are still captured, but actions are detected from page activity, so fewer frames are kept around them.");
613
+ }
614
+ /**
615
+ * Contexts are added by the caller with `addContext`.
616
+ *
617
+ * @param playwright The `playwright` fixture. Its private connection shows
618
+ * which page each API call acts on; without it, activity is detected from
619
+ * the frames.
620
+ */
621
+ static async start(options) {
622
+ return new ScreencastCapture(await fs.mkdtemp(path.join(os.tmpdir(), "playwright-opentelemetry-screencast-")), options.pageIdFor, options.playwright);
623
+ }
624
+ addContext(context) {
625
+ if (this.stopped || this.contexts.has(context)) return;
626
+ const onPage = (page) => this.addPage(page);
627
+ this.contexts.set(context, onPage);
628
+ context.on("page", onPage);
629
+ for (const page of context.pages()) this.addPage(page);
630
+ }
631
+ addPage(page) {
632
+ if (this.stopped || this.pages.has(page)) return;
633
+ let screencast;
634
+ try {
635
+ const pageId = this.pageIdFor(page);
636
+ screencast = new PageScreencast(page, (frame) => this.keepFrame(pageId, frame), { detectActivityFromFrames: !this.apiCalls });
637
+ } catch (error) {
638
+ console.warn(`Failed to capture screenshots of a page: ${error}`);
639
+ return;
640
+ }
641
+ this.pages.set(page, screencast);
642
+ screencast.start();
643
+ }
644
+ /** Stops capturing and returns the kept frames, oldest first. */
645
+ async stop() {
646
+ if (!this.stopped) {
647
+ this.stopped = true;
648
+ this.apiCalls?.uninstall();
649
+ for (const [context, onPage] of this.contexts) context.off("page", onPage);
650
+ await Promise.all(Array.from(this.pages.values(), (screencast) => screencast.stop()));
651
+ }
652
+ await Promise.all(this.writes);
653
+ return [...this.frames].sort((a, b) => a.timestamp - b.timestamp);
654
+ }
655
+ async dispose() {
656
+ await this.stop();
657
+ await fs.rm(this.dir, {
658
+ recursive: true,
659
+ force: true
660
+ });
661
+ }
662
+ unthrottle(page) {
663
+ if (page !== UNKNOWN_PAGE) {
664
+ this.pages.get(page)?.unthrottle();
665
+ return;
666
+ }
667
+ for (const screencast of this.pages.values()) screencast.unthrottle();
668
+ }
669
+ keepFrame(pageId, frame) {
670
+ if (this.stopped) return;
671
+ const timestamp = Math.round(Number.isFinite(frame.timestamp) ? frame.timestamp : Date.now());
672
+ const file = this.uniqueFileName(pageId, timestamp);
673
+ const framePath = path.join(this.dir, file);
674
+ const write = fs.writeFile(framePath, frame.data).then(() => {
675
+ this.frames.push({
676
+ pageId,
677
+ timestamp,
678
+ file,
679
+ path: framePath,
680
+ ...viewportOf(frame)
681
+ });
682
+ }, () => {});
683
+ this.writes.add(write);
684
+ write.then(() => this.writes.delete(write));
685
+ }
686
+ uniqueFileName(pageId, timestamp) {
687
+ let file = `${pageId}-${timestamp}.jpeg`;
688
+ for (let index = 1; this.files.has(file); index++) file = `${pageId}-${timestamp}-${index}.jpeg`;
689
+ this.files.add(file);
690
+ return file;
691
+ }
692
+ };
693
+ /**
694
+ * Owns the screencast of one page. Playwright allows one `page.screencast`
695
+ * per page, so the test's own `start()`/`stop()` calls are routed through here:
696
+ * while the test runs its screencast, frames are taken from it instead.
697
+ */
698
+ var PageScreencast = class {
699
+ page;
700
+ options;
701
+ throttle;
702
+ originalStart;
703
+ originalStop;
704
+ ownStarted = false;
705
+ userStarted = false;
706
+ stopped = false;
707
+ lastFrameAt;
708
+ queue = Promise.resolve();
709
+ constructor(page, keep, options) {
710
+ this.page = page;
711
+ this.options = options;
712
+ this.throttle = new ScreencastFrameThrottle(keep);
713
+ const screencast = page.screencast;
714
+ this.originalStart = screencast.start.bind(screencast);
715
+ this.originalStop = screencast.stop.bind(screencast);
716
+ screencast.start = (startOptions) => this.startForTest(startOptions);
717
+ screencast.stop = () => this.stopForTest();
718
+ }
719
+ start() {
720
+ return this.enqueue(() => this.startOwn());
721
+ }
722
+ async stop() {
723
+ this.stopped = true;
724
+ this.throttle.dispose();
725
+ await this.enqueue(() => this.stopOwn());
726
+ const screencast = this.page.screencast;
727
+ delete screencast.start;
728
+ delete screencast.stop;
729
+ }
730
+ unthrottle() {
731
+ this.throttle.unthrottle();
732
+ }
733
+ handleFrame(frame) {
734
+ if (this.options.detectActivityFromFrames) {
735
+ const now = performance.now();
736
+ if (this.lastFrameAt === void 0 || now - this.lastFrameAt > 1e3) this.throttle.unthrottle();
737
+ this.lastFrameAt = now;
738
+ }
739
+ return this.throttle.onFrame(frame);
740
+ }
741
+ async startOwn() {
742
+ if (this.stopped || this.ownStarted || this.userStarted || this.page.isClosed()) return;
743
+ try {
744
+ await runInternalApiCall(this.page, () => this.originalStart({ onFrame: (frame) => this.handleFrame(frame) }));
745
+ this.ownStarted = true;
746
+ } catch {}
747
+ }
748
+ async stopOwn() {
749
+ if (!this.ownStarted) return;
750
+ this.ownStarted = false;
751
+ await runInternalApiCall(this.page, () => this.originalStop()).catch(() => {});
752
+ }
753
+ async startForTest(options = {}) {
754
+ await this.enqueue(() => this.stopOwn());
755
+ this.userStarted = true;
756
+ const onFrame = options.onFrame;
757
+ try {
758
+ return await this.originalStart({
759
+ ...options,
760
+ onFrame: (frame) => {
761
+ this.handleFrame(frame);
762
+ return onFrame?.(frame);
763
+ }
764
+ });
765
+ } catch (error) {
766
+ this.userStarted = false;
767
+ await this.start();
768
+ throw error;
769
+ }
770
+ }
771
+ async stopForTest() {
772
+ if (!this.userStarted) return;
773
+ try {
774
+ await this.originalStop();
775
+ } finally {
776
+ this.userStarted = false;
777
+ await this.start();
778
+ }
779
+ }
780
+ enqueue(task) {
781
+ const next = this.queue.then(task);
782
+ this.queue = next.catch(() => {});
783
+ return next;
784
+ }
785
+ };
786
+ /**
787
+ * Sees which page each Playwright API call acts on, so only that page's
788
+ * throttling stops around it, like Playwright's trace recorder does on the
789
+ * server. The client instrumentation reports API calls without their object,
790
+ * so this wraps the private connection method every call goes through instead.
791
+ * Only the first message of a test-facing API call is sent as non-internal:
792
+ * the same call @playwright/test reports as a step.
793
+ */
794
+ var PageApiCallHook = class PageApiCallHook {
795
+ connection;
796
+ wrapper;
797
+ original;
798
+ hadOwnMethod;
799
+ constructor(connection, wrapper, original, hadOwnMethod) {
800
+ this.connection = connection;
801
+ this.wrapper = wrapper;
802
+ this.original = original;
803
+ this.hadOwnMethod = hadOwnMethod;
804
+ }
805
+ static install(playwright, onPageApiCall) {
806
+ const connection = playwright?._connection;
807
+ const original = connection?.sendMessageToServer;
808
+ if (!connection || typeof original !== "function") return;
809
+ const wrapper = function(object, method, params, options) {
810
+ const result = original.call(this, object, method, params, options);
811
+ const page = options?.internal ? void 0 : pageOfApiCall(object);
812
+ if (page) {
813
+ onPageApiCall(page);
814
+ const onEnd = () => onPageApiCall(page);
815
+ result.then(onEnd, onEnd);
816
+ }
817
+ return result;
818
+ };
819
+ const hadOwnMethod = Object.hasOwn(connection, "sendMessageToServer");
820
+ connection.sendMessageToServer = wrapper;
821
+ return new PageApiCallHook(connection, wrapper, original, hadOwnMethod);
822
+ }
823
+ uninstall() {
824
+ if (this.connection.sendMessageToServer !== this.wrapper) return;
825
+ if (this.hadOwnMethod) this.connection.sendMessageToServer = this.original;
826
+ else delete this.connection.sendMessageToServer;
827
+ }
828
+ };
829
+ /**
830
+ * The page a call on a Playwright client object acts on: the page itself, a
831
+ * frame's page, or the page of the frame that owns a handle.
832
+ */
833
+ function pageOfApiCall(object) {
834
+ const channelOwner = object;
835
+ const type = channelOwner?._type ?? "";
836
+ if (!PAGE_CHANNEL_TYPES.has(type)) return;
837
+ if (type === "Page") return channelOwner;
838
+ const frame = type === "Frame" ? channelOwner : channelOwner?._parent;
839
+ return frame?._type === "Frame" && frame._page || UNKNOWN_PAGE;
840
+ }
841
+ /**
842
+ * Runs Playwright calls as internal ones, so they aren't reported as test
843
+ * steps or seen by the API call hooks.
844
+ */
845
+ function runInternalApiCall(page, call) {
846
+ const wrapApiCall = page._wrapApiCall;
847
+ if (typeof wrapApiCall === "function") return wrapApiCall.call(page, call, { internal: true });
848
+ warnOnce("internal-calls", "playwright-opentelemetry: this Playwright version can't hide the screencast calls screenshots use, so they may show up as test steps.");
849
+ return call();
850
+ }
851
+ function viewportOf(frame) {
852
+ const { viewportWidth, viewportHeight } = frame;
853
+ return Number.isFinite(viewportWidth) && Number.isFinite(viewportHeight) ? {
854
+ viewportWidth,
855
+ viewportHeight
856
+ } : {};
857
+ }
858
+ const warnings = /* @__PURE__ */ new Set();
859
+ /** Warns once per worker: the same fallback applies to every test. */
860
+ function warnOnce(key, message) {
861
+ if (warnings.has(key)) return;
862
+ warnings.add(key);
863
+ console.warn(message);
864
+ }
865
+ //#endregion
866
+ //#region src/fixture/screenshots.ts
867
+ /**
868
+ * Screenshots only go to Trace API destinations and the local trace ZIP, so
869
+ * there is no point capturing them when neither could keep this test.
870
+ */
871
+ function shouldCaptureScreenshots(config, options) {
872
+ return config.screenshots && storesScreenshots(config, (trace) => couldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo));
873
+ }
874
+ /**
875
+ * Stops the capture and, if the test is retained, attaches its frames as a
876
+ * screenshots ZIP for the reporter to upload. Never rejects: a test must not
877
+ * fail because its screenshots couldn't be stored.
878
+ */
879
+ async function attachScreenshots(capture, config, options) {
880
+ try {
881
+ const frames = await capture.stop();
882
+ const retained = storesScreenshots(config, (trace) => shouldRetainPlaywrightTrace(trace ?? options.trace, options.testInfo));
883
+ if (frames.length === 0 || !retained) return;
884
+ const zip = await createScreenshotsZip(await Promise.all(frames.map(async (frame) => ({
885
+ timestamp: frame.timestamp,
886
+ file: frame.file,
887
+ contentType: "image/jpeg",
888
+ pageId: frame.pageId,
889
+ viewportWidth: frame.viewportWidth,
890
+ viewportHeight: frame.viewportHeight,
891
+ blob: new Blob([await fs.readFile(frame.path)])
892
+ }))));
893
+ const zipPath = path.join(capture.dir, "screenshots.zip");
894
+ await fs.writeFile(zipPath, Buffer.from(await zip.arrayBuffer()));
895
+ await options.testInfo.attach(SCREENSHOTS_ATTACHMENT_NAME, {
896
+ path: zipPath,
897
+ contentType: "application/zip"
898
+ });
899
+ } catch (error) {
900
+ console.warn(`Failed to store screenshots: ${error instanceof Error ? error.message : String(error)}`);
901
+ } finally {
902
+ await capture.dispose().catch(() => {});
903
+ }
904
+ }
905
+ function storesScreenshots(config, retainsTrace) {
906
+ return config.storeTraceZip && retainsTrace(config.trace) || filterRetainedDestinations(config.playwrightTraceApiDestinations, config.trace, retainsTrace).length > 0;
907
+ }
536
908
  //#endregion
537
909
  //#region src/fixture/test-fetch-capture.ts
538
910
  const SPAN_KIND_CLIENT = 3;
@@ -665,6 +1037,17 @@ function createPlaywrightOtelTest(testBase) {
665
1037
  scope: "worker",
666
1038
  auto: true
667
1039
  }],
1040
+ _playwrightOpentelemetryNewContexts: [async ({}, use) => {
1041
+ await use(/* @__PURE__ */ new Set());
1042
+ }, { scope: "worker" }],
1043
+ browser: [async ({ browser, _playwrightOpentelemetryNewContexts }, use) => {
1044
+ const onContext = (context) => {
1045
+ for (const listener of _playwrightOpentelemetryNewContexts) listener(context);
1046
+ };
1047
+ browser.on("context", onContext);
1048
+ await use(browser);
1049
+ browser.off("context", onContext);
1050
+ }, { scope: "worker" }],
668
1051
  testTraceInfo: [async ({ playwright }, use, testInfo) => {
669
1052
  const outputDir = path.dirname(testInfo.outputDir);
670
1053
  await use({
@@ -675,11 +1058,12 @@ function createPlaywrightOtelTest(testBase) {
675
1058
  testTraceContext: [async ({ playwrightOpentelemetry, trace }, use, testInfo) => {
676
1059
  const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
677
1060
  const traceContext = await createTestTraceContext(testInfo);
678
- await registerExpectedTrace(traceContext, config, {
1061
+ const registration = registerExpectedTrace(traceContext, config, {
679
1062
  trace,
680
1063
  testInfo
681
1064
  });
682
1065
  await runWithTestFetchCapture(traceContext, () => use(traceContext));
1066
+ await registration;
683
1067
  await flushFixtureSpans(traceContext, config, {
684
1068
  trace,
685
1069
  testInfo
@@ -690,11 +1074,44 @@ function createPlaywrightOtelTest(testBase) {
690
1074
  await use(tracker);
691
1075
  tracker.finishAll();
692
1076
  }, { auto: true }],
1077
+ screencastCapture: [async ({ playwright, playwrightOpentelemetry, trace, browserPageTracker, _playwrightOpentelemetryNewContexts: newContexts }, use, testInfo) => {
1078
+ const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
1079
+ if (!supportsScreencastScreenshots(testInfo.config.version) || !shouldCaptureScreenshots(config, {
1080
+ trace,
1081
+ testInfo
1082
+ })) {
1083
+ await use(void 0);
1084
+ return;
1085
+ }
1086
+ let capture;
1087
+ try {
1088
+ capture = await ScreencastCapture.start({
1089
+ playwright,
1090
+ pageIdFor: (page) => browserPageTracker.pageIdFor(page)
1091
+ });
1092
+ } catch (error) {
1093
+ console.warn(`Failed to start screenshot capture: ${error}`);
1094
+ await use(void 0);
1095
+ return;
1096
+ }
1097
+ const addContext = (context) => capture.addContext(context);
1098
+ newContexts.add(addContext);
1099
+ try {
1100
+ await use(capture);
1101
+ } finally {
1102
+ newContexts.delete(addContext);
1103
+ }
1104
+ await attachScreenshots(capture, config, {
1105
+ trace,
1106
+ testInfo
1107
+ });
1108
+ }, { auto: true }],
693
1109
  request: async ({ request, testTraceContext }, use) => {
694
1110
  await use(createCapturedApiRequestContext(request, testTraceContext));
695
1111
  },
696
- context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker }, use) => {
1112
+ context: async ({ context, playwrightOpentelemetry, testTraceContext, browserPageTracker, screencastCapture }, use) => {
697
1113
  const config = resolvePlaywrightOpentelemetryConfig(playwrightOpentelemetry);
1114
+ screencastCapture?.addContext(context);
698
1115
  const captureRequest = (request) => {
699
1116
  browserPageTracker.startDocumentNavigation(request);
700
1117
  const networkParent = browserPageTracker.getNetworkParent(request);
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/index.ts
2
- var src_default = require("./reporter-_hqajn5O.cjs").PlaywrightOpentelemetryReporter;
2
+ var src_default = require("./reporter-DMlPQnrW.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-DhuwcBzL.cjs";
1
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-DFY22ysa.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-DhuwcBzL.mjs";
1
+ import { i as PlaywrightTraceOption, n as PlaywrightOpentelemetryDestination, r as PlaywrightOpentelemetryUseOptions, t as PlaywrightOpentelemetryConfig } from "./config-DFY22ysa.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-DV6yWUMU.mjs";
1
+ import { t as PlaywrightOpentelemetryReporter } from "./reporter-CWAovnMj.mjs";
2
2
  //#region src/index.ts
3
3
  var src_default = PlaywrightOpentelemetryReporter;
4
4
  //#endregion