Go | Sentry for Go (original) (raw)

On this page, we get you up and running with Sentry's SDK. If you are using our previous Go SDK, you can access the legacy SDK documentation, until further notice.

Install our Go SDK using go get:

Copied

go get github.com/getsentry/sentry-go

Consult the Go documentation for more information on how to manage your dependencies.

Configuration should happen as early as possible in your application's lifecycle.

Error MonitoringLogsTracing

Copied

err := sentry.Init(sentry.ClientOptions{
    Dsn: "___PUBLIC_DSN___",
    // Enable printing of SDK debug messages.
    // Useful when getting started or trying to figure something out.
    Debug: true,
    // Adds request headers and IP for users,
    // visit: https://docs.sentry.io/platforms/go/data-management/data-collected/ for more info
    SendDefaultPII: true,
    // ___PRODUCT_OPTION_START___ performance
    EnableTracing: true,
    // Set TracesSampleRate to 1.0 to capture 100%
    // of transactions for tracing.
    TracesSampleRate: 1.0,
    // ___PRODUCT_OPTION_END___ performance
    // ___PRODUCT_OPTION_START___ logs
    EnableLogs: true,
    // ___PRODUCT_OPTION_END___ logs
})
if err != nil {
    log.Fatalf("sentry.Init: %s", err)
}
// Flush buffered events before the program terminates.
// Set the timeout to the maximum duration the program can afford to wait.
defer sentry.Flush(2 * time.Second)

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.

Copied

package main

import (
    "log"
    "time"

    "github.com/getsentry/sentry-go"
)

func main() {
    err := sentry.Init(sentry.ClientOptions{
        Dsn: "___PUBLIC_DSN___",
        // Adds request headers and IP for users,
        // visit: https://docs.sentry.io/platforms/go/data-management/data-collected/ for more info
        SendDefaultPII: true,
    })
    if err != nil {
        log.Fatalf("sentry.Init: %s", err)
    }
    defer sentry.Flush(2 * time.Second)

    sentry.CaptureMessage("It works!")
}

To view and resolve the recorded error, log into sentry.io and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").