@playwright-opentelemetry/trace-viewer 0.2.0 → 0.3.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
@@ -5,3 +5,41 @@ A SolidJS single-page application for viewing Playwright test execution traces i
5
5
  ## Overview
6
6
 
7
7
  This trace viewer provides a rich, interactive visualization of Playwright test runs that have been exported to OpenTelemetry format. It displays test steps, timing information, screenshots captured during execution, and additional trace data like HTTP requests.
8
+
9
+ ## Run the trace viewer
10
+
11
+ To boot the trace viewer on `localhost:9294`:
12
+
13
+ ```bash
14
+ npx @playwright-opentelemetry/trace-viewer
15
+ ```
16
+
17
+ ## Deploy Your Own
18
+
19
+ ### Cloudflare
20
+
21
+ You can deploy a copy of the trace viewer to Cloudflare:
22
+
23
+ ```bash
24
+ git clone https://github.com/endformdev/playwright-opentelemetry.git
25
+ cd playwright-opentelemetry/trace-viewer
26
+
27
+ pnpm install
28
+ pnpm build
29
+ pnpm deploy
30
+ ```
31
+
32
+ ### Custom Base Path (Optional)
33
+
34
+ If you want to build with absolute paths for a specific deployment location:
35
+
36
+ ```bash
37
+ TRACE_VIEWER_BASE=/trace-viewer/ pnpm build
38
+ ```
39
+
40
+ ## Local Development
41
+
42
+ ```bash
43
+ pnpm install
44
+ pnpm dev
45
+ ```
package/bin/serve.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import { access, readFile } from "node:fs/promises";
3
4
  import { createServer } from "node:http";
4
- import { readFile, access } from "node:fs/promises";
5
- import { join, extname } from "node:path";
5
+ import { extname, join } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
7
 
8
8
  const __dirname = fileURLToPath(new URL(".", import.meta.url));
@@ -32,7 +32,7 @@ function parseArgs() {
32
32
  for (let i = 0; i < args.length; i++) {
33
33
  if (args[i] === "--port" && args[i + 1]) {
34
34
  const parsed = parseInt(args[i + 1], 10);
35
- if (!isNaN(parsed) && parsed > 0 && parsed < 65536) {
35
+ if (!Number.isNaN(parsed) && parsed > 0 && parsed < 65536) {
36
36
  port = parsed;
37
37
  } else {
38
38
  console.error(`Invalid port: ${args[i + 1]}`);
@@ -84,6 +84,7 @@ async function serveFile(filePath, res) {
84
84
  res.writeHead(200, headers);
85
85
  res.end(content);
86
86
  } catch (err) {
87
+ console.error("Error serving file:", err);
87
88
  res.writeHead(500, { "Content-Type": "text/plain" });
88
89
  res.end("Internal Server Error");
89
90
  }
@@ -91,7 +92,7 @@ async function serveFile(filePath, res) {
91
92
 
92
93
  async function handleRequest(req, res) {
93
94
  const url = new URL(req.url, `http://${req.headers.host}`);
94
- let pathname = url.pathname;
95
+ const pathname = url.pathname;
95
96
 
96
97
  // Security: prevent directory traversal
97
98
  if (pathname.includes("..")) {
@@ -157,15 +158,19 @@ async function openBrowser(url) {
157
158
  async function main() {
158
159
  const { port } = parseArgs();
159
160
 
160
- // Check if dist directory exists
161
- if (!(await fileExists(DIST_DIR))) {
162
- console.error("Error: dist/ directory not found. Run 'pnpm build' first.");
163
- process.exit(1);
164
- }
165
-
166
161
  const server = createServer(handleRequest);
167
162
 
168
- server.listen(port, () => {
163
+ server.on("error", (err) => {
164
+ if (err.code === "EADDRINUSE") {
165
+ console.error(`\n ❌ Error: Port ${port} is already in use\n`);
166
+ console.error(` Try using a different port: --port <number>\n`);
167
+ } else {
168
+ console.error("Server error:", err.message);
169
+ }
170
+ process.exit(1);
171
+ });
172
+
173
+ server.listen(port, "localhost", () => {
169
174
  const url = `http://localhost:${port}`;
170
175
  console.log(`
171
176
  Playwright OpenTelemetry Trace Viewer
@@ -176,16 +181,6 @@ async function main() {
176
181
  `);
177
182
  openBrowser(url);
178
183
  });
179
-
180
- server.on("error", (err) => {
181
- if (err.code === "EADDRINUSE") {
182
- console.error(`Error: Port ${port} is already in use.`);
183
- console.error(`Try using a different port: --port <number>`);
184
- } else {
185
- console.error("Server error:", err.message);
186
- }
187
- process.exit(1);
188
- });
189
184
  }
190
185
 
191
186
  main();