Product How it works Features Security What is bugstack? SDKs JavaScript SDK Python SDK Go SDK Ruby SDK Docs Pricing Blog Book a Demo
Log In Get started

Install the bugstack SDK for Go

The SDK is the crash-capture part of bugstack: it captures uncaught server errors and starts a fix. HTTP middleware for net/http, Gin, and Echo, panic recovery, and the 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

Get started

Sign up with GitHub and start with $100 of free credit, or book a call and we set it up with you. Once the SDK is in, an uncaught server error starts a fix: specialist agents work out the cause and write a small change, it arrives as a pull request that runs through your CI, and what happens next depends on the autonomy level you set. Connecting the repository also starts repository scanning.