Categorygithub.com/cockroachdb/sentry-go
modulepackage
0.6.1-cockroachdb.2
Repository: https://github.com/cockroachdb/sentry-go.git
Documentation: pkg.go.dev

# README


Official Sentry SDK for Go

Build Status Go Report Card Discord GoDoc go.dev

sentry-go provides a Sentry client implementation for the Go programming language. This is the next line of the Go SDK for Sentry, intended to replace the raven-go package.

Looking for the old raven-go SDK documentation? See the Legacy client section here. If you want to start using sentry-go instead, check out the migration guide.

Requirements

The only requirement is a Go compiler.

We verify this package against the 3 most recent releases of Go. Those are the supported versions. The exact versions are defined in .travis.yml.

In addition, we run tests against the current master branch of the Go toolchain, though support for this configuration is best-effort.

Installation

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

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

Or, if you are already using Go Modules, you may specify a version number as well:

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

Check out the list of released versions.

Configuration

To use sentry-go, you’ll need to import the sentry-go package and initialize it with your DSN and other options.

If not specified in the SDK initialization, the DSN, Release and Environment are read from the environment variables SENTRY_DSN, SENTRY_RELEASE and SENTRY_ENVIRONMENT, respectively.

More on this in the Configuration section of the official Sentry documentation.

Usage

The SDK must be initialized with a call to sentry.Init. The default transport is asynchronous and thus most programs should call sentry.Flush to wait until buffered events are sent to Sentry right before the program terminates.

Typically, sentry.Init is called in the beginning of func main and sentry.Flush is deferred right after.

Note that if the program terminates with a call to os.Exit, either directly or indirectly via another function like log.Fatal, deferred functions are not run.

In that case, and if it is important for you to report outstanding events before terminating the program, arrange for sentry.Flush to be called before the program terminates.

Example:

// This is an example program that makes an HTTP request and prints response
// headers. Whenever a request fails, the error is reported to Sentry.
//
// Try it by running:
//
// 	go run main.go
// 	go run main.go https://sentry.io
// 	go run main.go bad-url
//
// To actually report events to Sentry, set the DSN either by editing the
// appropriate line below or setting the environment variable SENTRY_DSN to
// match the DSN of your Sentry project.
package main

import (
	"fmt"
	"log"
	"net/http"
	"os"
	"time"

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

func main() {
	if len(os.Args) < 2 {
		log.Fatalf("usage: %s URL", os.Args[0])
	}

	err := sentry.Init(sentry.ClientOptions{
		// Either set your DSN here or set the SENTRY_DSN environment variable.
		Dsn: "",
		// Enable printing of SDK debug messages.
		// Useful when getting started or trying to figure something out.
		Debug: true,
	})
	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)

	resp, err := http.Get(os.Args[1])
	if err != nil {
		sentry.CaptureException(err)
		log.Printf("reported to Sentry: %s", err)
		return
	}
	defer resp.Body.Close()

	for header, values := range resp.Header {
		for _, value := range values {
			fmt.Printf("%s=%s\n", header, value)
		}
	}
}

For your convenience, this example is available at example/basic/main.go. There are also more examples in the example directory.

For more detailed information about how to get the most out of sentry-go, checkout the official documentation:

Resources

License

Licensed under The 2-Clause BSD License, see LICENSE.

Community

Join Sentry's #go channel on Discord to get involved and help us improve the SDK!

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

AddBreadcrumb records a new breadcrumb.
No description provided by the author
CaptureEvent captures an event on the currently active client if any.
CaptureException captures an error.
CaptureMessage captures an arbitrary message.
ConfigureScope invokes a function that can modify the current scope.
CurrentHub returns an instance of previously initialized `Hub` stored in the global namespace.
ExtractStacktrace creates a new `Stacktrace` based on the given `error` object.
Flush waits until the underlying Transport sends any buffered events to the Sentry server, blocking for at most the given timeout.
GetHubFromContext tries to retrieve `Hub` instance from the given `Context` struct or return `nil` if one is not found.
HasHubOnContext checks whether `Hub` instance is bound to a given `Context` struct.
Init initializes whole SDK by creating new `Client` and binding it to the current `Hub`.
LastEventID returns an ID of last captured event.
NewClient creates and returns an instance of `Client` configured using `ClientOptions`.
NewDsn creates an instance of `Dsn` by parsing provided url in a `string` format.
No description provided by the author
NewFrame assembles a stacktrace frame out of `runtime.Frame`.
NewHTTPSyncTransport returns a new pre-configured instance of HTTPSyncTransport.
NewHTTPTransport returns a new pre-configured instance of HTTPTransport.
NewHub returns an instance of a `Hub` with provided `Client` and `Scope` bound.
NewRequest returns a new Sentry Request from the given http.Request.
No description provided by the author
NewStacktrace creates a stacktrace using `runtime.Callers`.
PopScope pushes a new scope.
PushScope pushes a new scope.
Recover captures a panic.
Recover captures a panic and passes relevant context object.
SetHubOnContext stores given `Hub` instance on the `Context` struct and returns a new `Context`.
WithScope temporarily pushes a scope for a single call.

# Constants

HubContextKey is a context key used to store Hub on any context.Context type.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RequestContextKey is a context key used to store http.Request on the context passed to RecoverWithContext.
Version is the version of the sentry-go SDK.

# Variables

nolint: gochecknoglobals.

# Structs

https://docs.sentry.io/development/sdk-dev/event-payloads/breadcrumbs/.
Client is the underlying processor that's used by the main API and `Hub` instances.
ClientOptions that configures a SDK Client.
Dsn is used as the remote address source to client transport.
No description provided by the author
https://docs.sentry.io/development/sdk-dev/event-payloads/.
No description provided by the author
https://docs.sentry.io/development/sdk-dev/event-payloads/exception/.
https://docs.sentry.io/development/sdk-dev/event-payloads/stacktrace/.
HTTPSyncTransport is an implementation of `Transport` interface which blocks after each captured event.
HTTPTransport is a default implementation of `Transport` interface used by `Client`.
Hub is the central object that manages scopes and clients.
https://docs.sentry.io/development/sdk-dev/event-payloads/request/.
Scope holds contextual data for the current scope.
https://docs.sentry.io/development/sdk-dev/event-payloads/sdk/.
No description provided by the author
Stacktrace holds information about the frames of the stack.
No description provided by the author
https://docs.sentry.io/development/sdk-dev/event-payloads/user/.

# Interfaces

No description provided by the author
Integration allows for registering a functions that modify or discard captured events.
Transport is used by the `Client` to deliver events to remote server.

# Type aliases

TODO: This type could be more useful, as map of interface{} is too generic and requires a lot of type assertions in beforeBreadcrumb calls plus it could just be `map[string]interface{}` then.
No description provided by the author
No description provided by the author
Level marks the severity of the event.