Connect Go to Bugsink

When a Go application fails, Bugsink gives you the error, stack trace, and context you need to investigate it.

This guide covers the initial setup, the different ways the Go SDK captures errors, and the useful context you can attach to them. You’ll start by connecting an existing application and sending a deliberate error to confirm that it reaches Bugsink.

To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.

Install the SDK

Add the open-source Sentry SDK to your Go module. Bugsink accepts the Sentry event protocol, so the SDK can send events directly to your Bugsink project:

go get github.com/getsentry/sentry-go

Configure your DSN

Initialize the SDK early in your application. Reading the DSN from the environment keeps it out of source control:

func configureErrorReporting() {
    if err := sentry.Init(sentry.ClientOptions{
        Dsn: os.Getenv("SENTRY_DSN"),
    }); err != nil {
        log.Fatal(err)
    }
}

Call configureErrorReporting() during startup. A short-lived command should also flush queued events before it exits:

configureErrorReporting()
    defer sentry.Flush(5 * time.Second)

Set SENTRY_DSN in the environment where the application runs:

export SENTRY_DSN=https://key@bugsink.example/1

Send a test error

Create an error on a code path you can run and pass it to CaptureException. Go errors are values rather than automatically unhandled exceptions, so this explicit call tells the SDK which failure to report:

func sendSetupCheck() {
    err := processOrder("go-setup-check", 0)
    sentry.CaptureException(err)
}

Run that code path once:

go run . setup-check

See the error in Bugsink

Open your Bugsink project. The new main.OrderQuantityError issue contains the Go stack and points to the call that captured it.

Bugsink preview

That’s it: your Go application is connected. Replace the setup error with capture calls at the failure boundaries you care about, or use a framework integration to capture request failures automatically.

Capture other kinds of errors

CaptureException is the normal path for errors returned by Go functions. The SDK can also report panics and exceptional conditions which do not have an error value.

Handled errors

Handled error capture reports a returned error without changing your recovery logic. Call CaptureException after deciding the application can continue but the failure is still worth investigating. The event includes a stack from the capture call and keeps the concrete Go error type:

if err := processOrder(orderID, quantity); err != nil {
            sentry.CaptureException(err)
        }

Bugsink preview

Panics

Panic recovery reports a panic with the stack where it occurred. Defer sentry.Recover in a function that must catch its own panic; the SDK consumes the panic after capturing it, so put the defer at the boundary where recovery is intended. HTTP framework middleware usually handles this for you:

func capturePanic() {
    defer sentry.Recover()
    panic(OrderQuantityError{OrderID: "go-panic"})
}

Bugsink preview: recovered panic
Bugsink preview

Messages without errors

A message creates a Bugsink event without requiring an error value. Use CaptureMessage for an exceptional condition such as an unresponsive queue; setting the scope level makes its severity explicit. Prefer CaptureException when a real error and its concrete type are available:

func captureQueueMessage() {
    sentry.WithScope(func(scope *sentry.Scope) {
        scope.SetLevel(sentry.LevelError)
        sentry.CaptureMessage("Order queue is not responding")
    })
}

Bugsink preview: captured message
Bugsink preview

The separate sentry-go/slog handler sends the newer Sentry Logs protocol, which Bugsink does not currently ingest. Use exception or message events for failures that need to appear as Bugsink issues.

Add useful context

An error tells you what failed; context helps explain why. WithScope keeps data for one capture together and removes it again when the callback returns.

Tags

Tags make events searchable by short key/value pairs. Use them for values such as component, region, plan, or feature flag when you will want to find related issues later. SetTag adds component:orders to the event captured within this scope:

scope.SetTag("component", "orders")

Bugsink preview: component tag
Bugsink preview

Structured context

Structured context adds a named group of details to an event. Use it for values you want to inspect but not search, such as the order or job being processed. SetContext("order", ...) creates an Order section with the identifier and quantity:

scope.SetContext("order", sentry.Context{
            "id":       orderID,
            "quantity": quantity,
        })

Bugsink preview: structured context
Bugsink preview

Breadcrumbs record what happened before an error. Add them for application steps the SDK cannot know about, such as beginning order processing or retrying an external call. This breadcrumb carries its category, message, order ID, and level into the next captured event:

sentry.AddBreadcrumb(&sentry.Breadcrumb{
            Category: "order",
            Message:  "Starting order processing",
            Data:     map[string]interface{}{"order_id": orderID},
            Level:    sentry.LevelInfo,
        })

Bugsink preview: breadcrumb
Bugsink preview

Go HTTP frameworks

HTTP integrations capture panics in the request lifecycle and add the request and application stack automatically.