Go SDK
Capture production errors automatically in your Go applications. Fast, concurrent, and lightweight.
Installation
go get github.com/MasonBachmann7/Bugstack-Go
Quick Start
package main
import (
"log"
"net/http"
"os"
bugstack "github.com/MasonBachmann7/Bugstack-Go"
)
func main() {
// Initialize bugstack
bugstack.Init(bugstack.Config{
APIKey: os.Getenv("BUGSTACK_API_KEY"),
})
defer bugstack.Flush()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World"))
})
// bugstack automatically captures panics and errors
log.Fatal(http.ListenAndServe(":8080", nil))
}
What the SDK captures
The bugstack Go SDK wraps your HTTP handler stack and your goroutine-spawning helpers. After bugstack.Init() runs, the SDK's recovery middleware captures panics, returns a 500 to the client, and enqueues a report with the full goroutine stack, the request method and path, and any context values you've tagged for capture. Non-panic errors surfaced via bugstack.CaptureError(ctx, err) are reported with the same context propagation.
Reports flush on a dedicated goroutine using a buffered channel, so capture is O(1) and never blocks the request goroutine. If the bugstack endpoint is unreachable, the background goroutine retries with exponential backoff and drops events silently rather than accumulating unbounded memory.
Framework adapters
For Gin, register bugstack.GinMiddleware() before your route group — it installs a Recovery-compatible panic handler that also reports to bugstack. For Echo, use bugstack.EchoMiddleware() which wraps the handler chain with the same semantics. The vanilla net/http adapter bugstack.HTTPHandler(h) is suitable for Chi, gorilla/mux, and any standard library router.
For background work, the SDK exposes bugstack.Go(fn) — a drop-in replacement for go fn() that installs a recovery wrapper inside the new goroutine. This is critical in Go: a panic inside a bare go statement takes down the whole process, and the standard recovery patterns only catch panics on the goroutine where defer recover() is declared.
Configuration
- APIKey (required) — read from
os.Getenv("BUGSTACK_API_KEY"). - Environment (optional) — string tag surfaced in the dashboard.
- Release (optional) — build-time-injected git SHA. Use
-ldflags "-X main.version=...". - SampleRate (optional) — 0.0–1.0 float, default 1.0.
- BeforeSend (optional) —
func(*bugstack.Event) *bugstack.Event. Return nil to drop. - IgnoreErrors (optional) —
[]stringof regex patterns matched against error messages.
Common Go errors bugstack fixes
The most frequent production errors in Go web services, each linked to a step-by-step fix:
- nil pointer dereference in Gin handlers
- Unrecovered panics crashing goroutines
- Channel deadlock
- context canceled in HTTP handlers
- SQL connection pool exhaustion
- Data race on map access
- HTTP client timeout
- Goroutine leak
Troubleshooting
Panic not captured? Make sure the panic happens inside a request whose handler is wrapped by bugstack.HTTPHandler (or the Gin/Echo equivalent). Panics in goroutines spawned by go fn() are not recovered unless you use bugstack.Go() or a manual defer bugstack.Recover().
Seeing "context canceled" noise? Add "context canceled" to IgnoreErrors. This error fires when a client disconnects mid-request and is usually not actionable.
Release field empty? Confirm the -ldflags build flag is applied during your production build, not just local. In Docker, verify it's in the go build line of the build stage, not the runtime stage.
See the full Go installation guide for context-propagation patterns, build-info injection, and structured-logging integration.
Data and privacy
The SDK ships the error type, error message, full goroutine stack, request path, method, and status to bugstack. Request bodies, response bodies, and header values are never transmitted unless you opt in per-field via BeforeSend. The GitHub App reads only the Go files named in the stack — it does not scan vendored dependencies or unrelated packages. Transport uses TLS 1.3 and at-rest encryption uses AES-256. Project data is deletable from the dashboard. The data handling doc details retention windows.
Versioning and compatibility
The module follows semver. Go 1.21+ is supported. Gin 1.9+, Echo v4, and any net/http-compatible router (Chi, gorilla/mux, httprouter) work with the standard library adapter. The module has zero external dependencies — only the Go standard library. Install with go get github.com/MasonBachmann7/bugstack-go. For build reproducibility, pin to a specific tag in your go.mod.
Source Code
View the full source code, report issues, and contribute on GitHub.