Skip to content

Commit 3bd413c

Browse files
authored
Merge pull request #7 from networkteam/feat-capture-session
Add new session capabilities with global and session mode and refined UI
2 parents 4c545b1 + 49ea341 commit 3bd413c

70 files changed

Lines changed: 7072 additions & 1692 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
on:
2+
push:
3+
tags:
4+
- v*
5+
branches:
6+
- main
7+
pull_request:
8+
9+
name: run tests
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Install Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version: '1.23'
20+
- name: Run tests
21+
run: go test -v ./...
22+
23+
acceptance:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v3
27+
- name: Install Go
28+
uses: actions/setup-go@v4
29+
with:
30+
go-version: '1.23'
31+
- name: Restore Playwright browsers cache
32+
id: playwright-cache
33+
uses: actions/cache/restore@v4
34+
with:
35+
path: ~/.cache/ms-playwright
36+
key: playwright-${{ runner.os }}-${{ hashFiles('acceptance/go.sum') }}
37+
restore-keys: |
38+
playwright-${{ runner.os }}-
39+
- name: Run acceptance tests
40+
run: go test -v -timeout 5m ./acceptance/...
41+
- name: Save Playwright browsers cache
42+
if: always() && steps.playwright-cache.outputs.cache-hit != 'true'
43+
uses: actions/cache/save@v4
44+
with:
45+
path: ~/.cache/ms-playwright
46+
key: playwright-${{ runner.os }}-${{ hashFiles('acceptance/go.sum') }}

README.md

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ A lightweight, embeddable development dashboard for Go applications. Monitor log
99
- **Logs**: Capture and browse structured logs with filtering and detail view
1010
- **HTTP Client**: Monitor outgoing HTTP requests with timing, headers, and response info
1111
- **HTTP Server**: Track incoming HTTP requests to your application
12-
- **Low Overhead**: Designed to be lightweight to run in development and testing setups
12+
- **SQL Queries**: Monitor database queries with timing and arguments
13+
- **On-Demand Capture**: Start/stop capturing through the dashboard UI with session or global modes
14+
- **Multi-User Isolation**: Each user gets their own event storage with independent clearing
15+
- **Low Overhead**: Designed to be lightweight; no events captured until you start a session
1316
- **Easy to Integrate**: Embeds into your application with minimal configuration
14-
- **Realtime**: See events as they occur
17+
- **Realtime**: See events as they occur via Server-Sent Events
1518
- **Clean UI**: Modern, minimalist interface with responsive design
1619

1720
## Note
@@ -86,6 +89,21 @@ See [example](example/main.go) for a more complete example showing all features.
8689

8790
## Usage
8891

92+
### Capture Sessions
93+
94+
By default, no events are collected until a user starts a capture session through the dashboard UI. This on-demand approach:
95+
96+
- Reduces overhead when not actively debugging
97+
- Provides isolation between users (each gets their own event storage)
98+
- Allows clearing events without affecting other users
99+
100+
**Capture Modes:**
101+
102+
- **Session Mode** (default): Only captures events from HTTP requests that include your session cookie. Useful for isolating your own requests in a shared environment.
103+
- **Global Mode**: Captures all events from all requests. Useful when you need to see everything happening in the application.
104+
105+
Toggle between modes using the buttons in the dashboard header.
106+
89107
### Capturing Logs
90108

91109
devlog integrates with Go's `slog` package:
@@ -250,28 +268,71 @@ The collected queries will be visible in the devlog dashboard, showing:
250268

251269
### Configuring the Dashboard
252270

253-
Use options to customize the dashboard:
271+
Use functional options to customize the dashboard handler:
254272

255273
```go
256-
dashboard := devlog.NewWithOptions(devlog.Options{
257-
LogCapacity: 1000, // Maximum number of log entries to keep
258-
HTTPClientCapacity: 100, // Maximum number of HTTP client requests to keep
259-
HTTPServerCapacity: 100, // Maximum number of HTTP server requests to keep
260-
SQLCapacity: 100, // Maximum number of SQL queries to keep
274+
mux.Handle("/_devlog/", http.StripPrefix("/_devlog", dlog.DashboardHandler("/_devlog",
275+
dashboard.WithStorageCapacity(5000), // Events per user (default: 1000)
276+
dashboard.WithSessionIdleTimeout(time.Minute), // Cleanup timeout (default: 30s)
277+
dashboard.WithTruncateAfter(100), // Limit displayed events
278+
)))
279+
```
280+
281+
### Configuring Collectors
282+
283+
Use options to customize collector behavior:
284+
285+
```go
286+
dlog := devlog.NewWithOptions(devlog.Options{
287+
HTTPServerOptions: &collector.HTTPServerOptions{
288+
CaptureRequestBody: true,
289+
CaptureResponseBody: true,
290+
MaxBodySize: 1024 * 1024, // 1MB max body capture
291+
SkipPaths: []string{"/_devlog"}, // Skip dashboard routes
292+
},
293+
HTTPClientOptions: &collector.HTTPClientOptions{
294+
CaptureRequestBody: true,
295+
CaptureResponseBody: true,
296+
MaxBodySize: 1024 * 1024,
297+
},
261298
})
262299
```
263300

301+
## Development
302+
303+
### Running Acceptance Tests
304+
305+
The project includes Playwright-based acceptance tests that verify the dashboard UI works correctly with the backend.
306+
307+
**Prerequisites:**
308+
309+
Playwright browsers will be automatically installed on first run.
310+
311+
**Run all acceptance tests:**
312+
313+
```bash
314+
go test -v -timeout 5m ./acceptance/...
315+
```
316+
317+
**Debug mode (visible browser):**
318+
319+
```bash
320+
HEADLESS=false go test -v -parallel=1 ./acceptance/...
321+
```
322+
323+
The acceptance tests cover:
324+
- Dashboard access and session management
325+
- Global and session capture modes
326+
- Event capturing and display (HTTP server/client, logs, DB queries)
327+
- SSE real-time updates
328+
- Mode switching and event clearing
329+
264330
## TODOs
265331

266-
- [ ] Add support for generic events/groups that can be used in user-code
267-
- [ ] Implement on-demand activation of devlog (record / stop)
268-
- [ ] Implement reset of collected events
332+
- [ ] Add support for generic events/groups that can be used in user-code
269333
- [ ] Add pretty printing of JSON
270334
- [ ] Implement ad-hoc change of log level via slog.Leveler via UI
271335
- [ ] Implement filtering of events
272-
- [ ] Support plugins (e.g. for GraphQL) to add attributes to HTTP requests (operation name)
273-
- [x] Change display of time or implement timers via JS
274-
- [x] Implement SQL query logging with adapters
275336

276337
## License
277338

acceptance/acceptance_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package acceptance
2+
3+
import (
4+
"log"
5+
"os"
6+
"testing"
7+
8+
"github.com/playwright-community/playwright-go"
9+
)
10+
11+
// TestMain installs Playwright browsers before running tests.
12+
func TestMain(m *testing.M) {
13+
if err := playwright.Install(); err != nil {
14+
log.Fatalf("could not install playwright: %v", err)
15+
}
16+
os.Exit(m.Run())
17+
}

0 commit comments

Comments
 (0)