Go

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

Getting Started

Getting started with Sentry is a three step process:

  1. Sign up for an account
  2. Install your SDK
  3. Configure it

Installation

sentry-go can be installed like any other Go library through go get, and if using Go Modules, it will pick up the latest tagged version:

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

Configuration

To use sentry-go, you’ll need to import the sentry-go package and initialize it with the client options that will include your DSN. If you specify the SENTRY_DSN environment variable, you can omit this value from options and it will be picked up automatically for you. The release and environment can also be specified in the environment variables SENTRY_RELEASE and SENTRY_ENVIRONMENT respectively.

More on this in Configuration section.

Usage

package main

import (
	"fmt"
	"os"
	"time"

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

func main() {
	err := sentry.Init(sentry.ClientOptions{
		Dsn: "___PUBLIC_DSN___",
	})

	if err != nil {
		fmt.Printf("Sentry initialization failed: %v\n", err)
	}
	
	f, err := os.Open("filename.ext")
	if err != nil {
		sentry.CaptureException(err)
		sentry.Flush(time.Second * 5)
	}
}

Next Steps

For more detailed information about how to get the most out of sentry-go there is additional documentation available:

Resources: