Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
push:
tags:
- v*
branches:
- main
pull_request:

name: run tests

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Run tests
run: go test -v ./...

acceptance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Restore Playwright browsers cache
id: playwright-cache
uses: actions/cache/restore@v4
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ hashFiles('acceptance/go.sum') }}
restore-keys: |
playwright-${{ runner.os }}-
- name: Run acceptance tests
run: go test -v -timeout 5m ./acceptance/...
- name: Save Playwright browsers cache
if: always() && steps.playwright-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ hashFiles('acceptance/go.sum') }}
89 changes: 75 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ A lightweight, embeddable development dashboard for Go applications. Monitor log
- **Logs**: Capture and browse structured logs with filtering and detail view
- **HTTP Client**: Monitor outgoing HTTP requests with timing, headers, and response info
- **HTTP Server**: Track incoming HTTP requests to your application
- **Low Overhead**: Designed to be lightweight to run in development and testing setups
- **SQL Queries**: Monitor database queries with timing and arguments
- **On-Demand Capture**: Start/stop capturing through the dashboard UI with session or global modes
- **Multi-User Isolation**: Each user gets their own event storage with independent clearing
- **Low Overhead**: Designed to be lightweight; no events captured until you start a session
- **Easy to Integrate**: Embeds into your application with minimal configuration
- **Realtime**: See events as they occur
- **Realtime**: See events as they occur via Server-Sent Events
- **Clean UI**: Modern, minimalist interface with responsive design

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

## Usage

### Capture Sessions

By default, no events are collected until a user starts a capture session through the dashboard UI. This on-demand approach:

- Reduces overhead when not actively debugging
- Provides isolation between users (each gets their own event storage)
- Allows clearing events without affecting other users

**Capture Modes:**

- **Session Mode** (default): Only captures events from HTTP requests that include your session cookie. Useful for isolating your own requests in a shared environment.
- **Global Mode**: Captures all events from all requests. Useful when you need to see everything happening in the application.

Toggle between modes using the buttons in the dashboard header.

### Capturing Logs

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

### Configuring the Dashboard

Use options to customize the dashboard:
Use functional options to customize the dashboard handler:

```go
dashboard := devlog.NewWithOptions(devlog.Options{
LogCapacity: 1000, // Maximum number of log entries to keep
HTTPClientCapacity: 100, // Maximum number of HTTP client requests to keep
HTTPServerCapacity: 100, // Maximum number of HTTP server requests to keep
SQLCapacity: 100, // Maximum number of SQL queries to keep
mux.Handle("/_devlog/", http.StripPrefix("/_devlog", dlog.DashboardHandler("/_devlog",
dashboard.WithStorageCapacity(5000), // Events per user (default: 1000)
dashboard.WithSessionIdleTimeout(time.Minute), // Cleanup timeout (default: 30s)
dashboard.WithTruncateAfter(100), // Limit displayed events
)))
```

### Configuring Collectors

Use options to customize collector behavior:

```go
dlog := devlog.NewWithOptions(devlog.Options{
HTTPServerOptions: &collector.HTTPServerOptions{
CaptureRequestBody: true,
CaptureResponseBody: true,
MaxBodySize: 1024 * 1024, // 1MB max body capture
SkipPaths: []string{"/_devlog"}, // Skip dashboard routes
},
HTTPClientOptions: &collector.HTTPClientOptions{
CaptureRequestBody: true,
CaptureResponseBody: true,
MaxBodySize: 1024 * 1024,
},
})
```

## Development

### Running Acceptance Tests

The project includes Playwright-based acceptance tests that verify the dashboard UI works correctly with the backend.

**Prerequisites:**

Playwright browsers will be automatically installed on first run.

**Run all acceptance tests:**

```bash
go test -v -timeout 5m ./acceptance/...
```

**Debug mode (visible browser):**

```bash
HEADLESS=false go test -v -parallel=1 ./acceptance/...
```

The acceptance tests cover:
- Dashboard access and session management
- Global and session capture modes
- Event capturing and display (HTTP server/client, logs, DB queries)
- SSE real-time updates
- Mode switching and event clearing

## TODOs

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

## License

Expand Down
17 changes: 17 additions & 0 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package acceptance

import (
"log"
"os"
"testing"

"github.com/playwright-community/playwright-go"
)

// TestMain installs Playwright browsers before running tests.
func TestMain(m *testing.M) {
if err := playwright.Install(); err != nil {
log.Fatalf("could not install playwright: %v", err)
}
os.Exit(m.Run())
}
Loading