SDK · Go
Go
Official Bugwatch SDK for Go 1.21+. Zero external dependencies — standard library only. Events are queued on an internal channel and sent by a background worker, so a slow or down Bugwatch server never stalls your application.
Install
Shell
go get github.com/roomylabs/bugwatch-go
Quickstart
Go
package main
import (
"errors"
"log"
"time"
bugwatch "github.com/roomylabs/bugwatch-go"
)
func main() {
// DSN format: https://<public_key>@<host>/<path>
if err := bugwatch.Init("https://bw-YOUR_KEY@bugwatch-api.loadmindx.com/api/1"); err != nil {
log.Fatalf("bugwatch init: %v", err)
}
defer bugwatch.Flush(5 * time.Second)
err := doSomething()
if err != nil {
event := bugwatch.CaptureException(err)
if event != nil {
log.Printf("reported event %s", event.ID)
}
}
}Context & sensitive data
Go
bugwatch.AddBreadcrumb("db", "query users")
bugwatch.SetUser("42", "alice@example.com")
bugwatch.SetTag("region", "eu-west")
// Redact anything tagged sensitive before it leaves the process:
bugwatch.SetTag("user.email", "sensitive") // email is sent as "[redacted]"
bugwatch.CaptureMessage("payment retry scheduled", "warning")Both id and email are checked against the tag map; anything tagged sensitive never leaves the process in clear text.
API
| API | Description |
|---|---|
| Init(dsn string) error | Parse the DSN, validate HTTPS (unless BUGWATCH_ALLOW_HTTP=1), start the delivery worker. |
| CaptureException(err error) *Event | Capture an error with a stacktrace of the calling goroutine. Never blocks. |
| CaptureMessage(msg string, level string) *Event | Capture a message: debug, info, warning, error or fatal. |
| AddBreadcrumb(category, message string) | Append a breadcrumb to the client-wide trail. |
| SetUser(id, email string) | Set user context. |
| SetTag(k, v string) | Set a tag on subsequent events. |
| Flush(timeout time.Duration) bool | Wait up to timeout for queued events to be delivered. Call it in a defer. |
Environment variables
| API | Description |
|---|---|
| BUGWATCH_ALLOW_HTTP | Set to 1 to allow plain HTTP DSNs (tests only). |
