SDKs JavaScript SDK Python SDK Go SDK Ruby SDK Docs Pricing Blog Error Guides Book a Demo
Log In Start Free Trial

Install bugstack for Go

HTTP middleware for net/http, Gin, and Echo. Panic recovery and full config reference.

Compatibility

Go 1.18+

Install

go get github.com/MasonBachmann7/bugstack-go

Initialize

Call bugstack.Init() in your main() function and defer bugstack.Flush():

package main

import (
    "os"
    "github.com/MasonBachmann7/bugstack-go/bugstack"
)

func main() {
    bugstack.Init(bugstack.Config{
        APIKey: os.Getenv("BUGSTACK_API_KEY"),
    })
    defer bugstack.Flush()

    // Manually capture an error
    err := riskyOperation()
    if err != nil {
        bugstack.CaptureError(err)
    }
}

Panic Recovery

Recover from panics and report them automatically:

func handler() {
    defer bugstack.Recover()

    // If this panics, bugstack captures it
    riskyOperation()
}

net/http

Wrap your HTTP handler with the bugstack middleware:

package main

import (
    "net/http"
    "github.com/MasonBachmann7/bugstack-go/bugstack"
    "github.com/MasonBachmann7/bugstack-go/middleware"
)

func main() {
    bugstack.Init(bugstack.Config{
        APIKey: os.Getenv("BUGSTACK_API_KEY"),
    })
    defer bugstack.Flush()

    mux := http.NewServeMux()
    mux.HandleFunc("/", indexHandler)

    // Wrap the mux with bugstack middleware
    http.ListenAndServe(":8080", middleware.NetHTTP(mux))
}

Gin

package main

import (
    "github.com/gin-gonic/gin"
    "github.com/MasonBachmann7/bugstack-go/bugstack"
    "github.com/MasonBachmann7/bugstack-go/middleware"
)

func main() {
    bugstack.Init(bugstack.Config{
        APIKey: os.Getenv("BUGSTACK_API_KEY"),
    })
    defer bugstack.Flush()

    r := gin.Default()
    r.Use(middleware.GinRecovery())

    r.GET("/", func(c *gin.Context) {
        c.JSON(200, gin.H{"message": "hello"})
    })

    r.Run(":8080")
}

Echo

package main

import (
    "github.com/labstack/echo/v4"
    "github.com/MasonBachmann7/bugstack-go/bugstack"
    "github.com/MasonBachmann7/bugstack-go/middleware"
)

func main() {
    bugstack.Init(bugstack.Config{
        APIKey: os.Getenv("BUGSTACK_API_KEY"),
    })
    defer bugstack.Flush()

    e := echo.New()
    e.Use(middleware.EchoRecover())

    e.GET("/", func(c echo.Context) error {
        return c.JSON(200, map[string]string{"message": "hello"})
    })

    e.Start(":8080")
}

Configuration Reference

Option Type Default Description
APIKey string Required. Your bugstack API key.
Environment string "production" Environment name (production, staging, etc.).
AutoFix bool true Enable automatic fix generation via GitHub PRs.
Debug bool false Log internal SDK activity to stderr.
DryRun bool false Process errors locally without sending to the API.
Enabled bool true Master kill switch for error capture.
DeduplicationWindow time.Duration 60s Window to deduplicate identical errors.
Timeout time.Duration 5s HTTP timeout for sending reports.
MaxRetries int 3 Number of retries on failed HTTP requests.
IgnoredErrors []error nil Error values to ignore.
BeforeSend func(*Payload) *Payload nil Hook to transform or drop payloads before sending.

Data Control

BeforeSend hook example

Drop health-check errors from being reported:

bugstack.Init(bugstack.Config{
    APIKey: os.Getenv("BUGSTACK_API_KEY"),
    BeforeSend: func(p *bugstack.Payload) *bugstack.Payload {
        if p.RequestPath == "/health" {
            return nil // drop this event
        }
        return p
    },
})

DryRun mode

Test your integration without sending data to the API:

bugstack.Init(bugstack.Config{
    APIKey:  os.Getenv("BUGSTACK_API_KEY"),
    DryRun:  true,
    Debug:   true, // logs payloads to stderr
})

Next Steps

Start capturing Go errors now

bugstack catches runtime panics in production, writes the fix, runs your CI, and opens a tested pull request — in under 2 minutes.