Raven-Go provides a Sentry client implementation for the Go programming language.


Raven-Go can be installed like any other Go library through go get:

$ go get github.com/getsentry/raven-go

Configuring the Client

To use raven-go, you’ll need to import the raven package, then initilize your DSN globally. If you specify the SENTRY_DSN environment variable, this will be done automatically for you. The release and environment can also be specified in the environment variables SENTRY_RELEASE and SENTRY_ENVIRONMENT respectively.

package main

import "github.com/getsentry/raven-go"

func init() {

Reporting Errors

In Go, there are both errors and panics, and Raven can handle both. To learn more about the differences, please read Error handling and Go.

To handle normal error responses, we have two options: CaptureErrorAndWait and CaptureError. The former is a blocking call, for a case where you’d like to exit the application after reporting, and the latter is non-blocking.

f, err := os.Open("filename.ext")
if err != nil {
    raven.CaptureErrorAndWait(err, nil)

Reporting Panics

Capturing a panic is pretty simple as well. We just need to wrap our code in CapturePanic. CapturePanic will execute the func and if a panic happened, we will record it, and gracefully continue.

raven.CapturePanic(func() {
    // do all of the scary things here
}, nil)

Additional Context

All of the Capture* functions accept an additional argument for passing a map of tags as the second argument. For example:

raven.CaptureError(err, map[string]string{"browser": "Firefox"})

Tags in Sentry help to categories and give you more information about the errors that happened.

Event Sampling

To setup client side sampling you can use SetSampleRate Client function. Error sampling is disabled by default (sampleRate=1).

package main

import "github.com/getsentry/raven-go"

func init() {

Deep Dive

For more detailed information about how to get the most out of raven-go there is additional documentation available that covers all the rest: