11import { defineConfig , devices } from "@playwright/test" ;
2+ import type { PlaywrightOpentelemetryUseOptions } from "playwright-opentelemetry/fixture" ;
23
34/**
45 * Read environment variables from file.
@@ -11,10 +12,15 @@ import { defineConfig, devices } from "@playwright/test";
1112export const baseURL =
1213 process . env . BASE_URL || "https://endform-playwright-tutorial.vercel.app" ;
1314
15+ const playwrightOtelEnabled = Boolean (
16+ process . env . PLAYWRIGHT_TRACE_API_ENDPOINT ||
17+ process . env . OTEL_EXPORTER_OTLP_ENDPOINT ,
18+ ) ;
19+
1420/**
1521 * See https://playwright.dev/docs/test-configuration.
1622 */
17- export default defineConfig ( {
23+ export default defineConfig < PlaywrightOpentelemetryUseOptions > ( {
1824 testDir : "./tests" ,
1925 globalSetup : "./global-setup.ts" ,
2026 globalTeardown : "./global-teardown.ts" ,
@@ -27,7 +33,12 @@ export default defineConfig({
2733 /* Opt out of parallel tests on CI. */
2834 workers : "50%" ,
2935 /* Reporter to use. See https://playwright.dev/docs/test-reporters */
30- reporter : [ [ "html" , { open : "never" } ] ] ,
36+ reporter : [
37+ [ "html" , { open : "never" } ] ,
38+ ...( playwrightOtelEnabled
39+ ? [ [ "playwright-opentelemetry/reporter" ] as const ]
40+ : [ ] ) ,
41+ ] ,
3142 /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
3243 use : {
3344 /* Base URL to use in actions like `await page.goto('/')`. */
@@ -36,7 +47,15 @@ export default defineConfig({
3647 // baseURL: "http://localhost:3000",
3748
3849 /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
39- trace : "retain-on-failure" ,
50+ trace : playwrightOtelEnabled ? "on" : "retain-on-failure" ,
51+ playwrightOpentelemetry : playwrightOtelEnabled
52+ ? {
53+ trace : "on" ,
54+ storeTraceZip : false ,
55+ propagateTraceHeaders : true ,
56+ serviceName : "playwright-tutorial-tests" ,
57+ }
58+ : undefined ,
4059 } ,
4160
4261 /* Run your local dev server before starting the tests */
0 commit comments