raven package - github.com/getsentry/raven-go - Go Packages (original) (raw)
Package raven implements a client for the Sentry error logging service.
// ... i.e. raisedErr is incoming error var raisedErr error // sentry DSN generated by Sentry server var sentryDSN string // r is a request performed when error occured var r *http.Request client, err := New(sentryDSN) if err != nil { log.Fatal(err) } trace := NewStacktrace(0, 2, nil) packet := NewPacket(raisedErr.Error(), NewException(raisedErr, trace), NewHttp(r)) eventID, ch := client.Capture(packet, nil) if err = <-ch; err != nil { log.Fatal(err) } message := fmt.Sprintf("Captured error with id %s: %q", eventID, raisedErr) log.Println(message)
func Capture(packet *Packet, captureTags map[string]string) (eventID string, ch chan error)
func CaptureError(err error, tags map[string]string, interfaces ...Interface) string
func CaptureErrorAndWait(err error, tags map[string]string, interfaces ...Interface) string
func CaptureMessage(message string, tags map[string]string, interfaces ...Interface) string
func CaptureMessageAndWait(message string, tags map[string]string, interfaces ...Interface) string
func CapturePanic(f func(), tags map[string]string, interfaces ...Interface) (interface{}, string)
func WrapWithExtra(err error, extraInfo map[string]interface{}) error
- func (client *Client) Capture(packet *Packet, captureTags map[string]string) (eventID string, ch chan error)
- func (client *Client) CaptureError(err error, tags map[string]string, interfaces ...Interface) string
- func (client *Client) CaptureErrorAndWait(err error, tags map[string]string, interfaces ...Interface) string
- func (client *Client) CaptureMessage(message string, tags map[string]string, interfaces ...Interface) string
- func (client *Client) CaptureMessageAndWait(message string, tags map[string]string, interfaces ...Interface) string
- func (client *Client) CapturePanic(f func(), tags map[string]string, interfaces ...Interface) (err interface{}, errorID string)
- func (client *Client) CapturePanicAndWait(f func(), tags map[string]string, interfaces ...Interface) (err interface{}, errorID string)
- func (c *Client) ClearContext()
- func (client *Client) Close()
- func (client *Client) IncludePaths() []string
- func (client *Client) ProjectID() string
- func (client *Client) Release() string
- func (client *Client) SetDSN(dsn string) error
- func (client *Client) SetDefaultLoggerName(name string)
- func (client *Client) SetEnvironment(environment string)
- func (c *Client) SetHttpContext(h *Http)
- func (c *Client) SetIgnoreErrors(errs []string) error
- func (client *Client) SetIncludePaths(p []string)
- func (client *Client) SetRelease(release string)
- func (client *Client) SetSampleRate(rate float32) error
- func (c *Client) SetTagsContext(t map[string]string)
- func (c *Client) SetUserContext(u *User)
- func (client *Client) URL() string
- func (client *Client) Wait()
const ( DEBUG = Severity("debug") INFO = Severity("info") WARNING = Severity("warning") ERROR = Severity("error") FATAL = Severity("fatal") )
http://docs.python.org/2/howto/logging.html#logging-levels
var ( ErrPacketDropped = errors.New("raven: packet dropped") ErrUnableToUnmarshalJSON = errors.New("raven: unable to unmarshal JSON") ErrMissingUser = errors.New("raven: dsn missing public key and/or password") ErrMissingProjectID = errors.New("raven: dsn missing project id") ErrInvalidSampleRate = errors.New("raven: sample rate should be between 0 and 1") )
Initialize a default *Client instance
The maximum number of packets that will be buffered waiting to be delivered. Packets will be dropped if the buffer is full. Used by NewClient.
Capture asynchronously delivers a packet to the Sentry server with the default *Client. It is a no-op when client is nil. A channel is provided if it is important to check for a send's success.
CaptureErrors formats and delivers an error to the Sentry server using the default *Client. Adds a stacktrace to the packet, excluding the call to this method.
func CaptureErrorAndWait ¶
CaptureErrorAndWait is identical to CaptureError, except it blocks and assures that the event was sent
CaptureMessage formats and delivers a string message to the Sentry server with the default *Client
func CaptureMessageAndWait ¶
CaptureMessageAndWait is identical to CaptureMessage except it blocks and waits for the message to be sent.
CapturePanic calls f and then recovers and reports a panic to the Sentry server if it occurs. If an error is captured, both the error and the reported Sentry error ID are returned.
func CapturePanicAndWait ¶
func CapturePanicAndWait(f func(), tags map[string]string, interfaces ...Interface) (interface{}, string)
CapturePanicAndWait is identical to CaptureError, except it blocks and assures that the event was sent
Recovery handler to wrap the stdlib net/http Mux. Example:
mux := http.NewServeMux ... http.Handle("/", raven.Recoverer(mux))
func RecoveryHandler ¶
Recovery handler to wrap the stdlib net/http Mux. Example:
http.HandleFunc("/", raven.RecoveryHandler(func(w http.ResponseWriter, r *http.Request) { ... }))
Sets the DSN for the default *Client instance
func SetDefaultLoggerName(name string)
SetDefaultLoggerName sets the "defaultLoggerName" on the default *Client
func SetEnvironment(environment string)
SetEnvironment sets the "environment" tag on the default *Client
func SetHttpContext(h *Http)
func SetIncludePaths(p []string)
func SetRelease(release string)
SetRelease sets the "release" tag on the default *Client
SetSampleRate sets the "sample rate" on the degault *Client
func SetSourceCodeLoader(loader SourceCodeLoader)
func SetUserContext(u *User)
Wait blocks and waits for all events to finish being sent to Sentry server
Adds extra data to an error before reporting to Sentry
type Client struct { Tags map[string]string
Transport [Transport](#Transport)
DropHandler func(*[Packet](#Packet))}
Client encapsulates a connection to a Sentry server. It must be initialized by calling NewClient. Modification of fields concurrently with Send or after calling Report for the first time is not thread-safe.
New constructs a new Sentry client instance
NewClient constructs a Sentry client and spawns a background goroutine to handle packets sent by Client.Report.
Deprecated: use New and NewWithTags instead
NewWithTags constructs a new Sentry client instance with default tags.
Capture asynchronously delivers a packet to the Sentry server. It is a no-op when client is nil. A channel is provided if it is important to check for a send's success.
CaptureErrors formats and delivers an error to the Sentry server. Adds a stacktrace to the packet, excluding the call to this method.
func (*Client) CaptureErrorAndWait ¶
CaptureErrorAndWait is identical to CaptureError, except it blocks and assures that the event was sent
CaptureMessage formats and delivers a string message to the Sentry server.
func (*Client) CaptureMessageAndWait ¶
CaptureMessageAndWait is identical to CaptureMessage except it blocks and waits for the message to be sent.
func (client *Client) CapturePanic(f func(), tags map[string]string, interfaces ...Interface) (err interface{}, errorID string)
CapturePanic calls f and then recovers and reports a panic to the Sentry server if it occurs. If an error is captured, both the error and the reported Sentry error ID are returned.
func (*Client) CapturePanicAndWait ¶
func (client *Client) CapturePanicAndWait(f func(), tags map[string]string, interfaces ...Interface) (err interface{}, errorID string)
CapturePanicAndWait is identical to CaptureError, except it blocks and assures that the event was sent
func (c *Client) ClearContext()
func (client *Client) Close()
func (client *Client) IncludePaths() []string
func (client *Client) ProjectID() string
SetDSN updates a client with a new DSN. It safe to call after and concurrently with calls to Report and Send.
func (client *Client) SetDefaultLoggerName(name string)
SetDefaultLoggerName sets the default logger name.
func (client *Client) SetEnvironment(environment string)
SetEnvironment sets the "environment" tag.
func (c *Client) SetHttpContext(h *Http)
func (client *Client) SetIncludePaths(p []string)
func (client *Client) SetRelease(release string)
SetRelease sets the "release" tag.
SetSampleRate sets how much sampling we want on client side
func (c *Client) SetUserContext(u *User)
func (client *Client) Wait()
Wait blocks and waits for all events to finish being sent to Sentry server
type Culpriter interface { Culprit() string }
type ErrWithExtra interface { }
type Extra map[string]interface{}
HTTPTransport is the default transport, delivering packets to Sentry via the HTTP API.
type Interface interface {
Class() [string](/builtin#string)}
An Interface is a Sentry interface that will be serialized as JSON. It must implement json.Marshaler or use json struct tags.
type Packet struct {
Message [string](/builtin#string) `json:"message"`
EventID [string](/builtin#string) `json:"event_id"`
Project [string](/builtin#string) `json:"project"`
Timestamp [Timestamp](#Timestamp) `json:"timestamp"`
Level [Severity](#Severity) `json:"level"`
Logger [string](/builtin#string) `json:"logger"`
Platform [string](/builtin#string) `json:"platform,omitempty"`
Culprit [string](/builtin#string) `json:"culprit,omitempty"`
ServerName [string](/builtin#string) `json:"server_name,omitempty"`
Release [string](/builtin#string) `json:"release,omitempty"`
Environment [string](/builtin#string) `json:"environment,omitempty"`
Tags [Tags](#Tags) `json:"tags,omitempty"`
Modules map[[string](/builtin#string)][string](/builtin#string) `json:"modules,omitempty"`
Fingerprint [][string](/builtin#string) `json:"fingerprint,omitempty"`
Interfaces [][Interface](#Interface) `json:"-"`}
https://docs.getsentry.com/hosted/clientdev/#building-the-json-packet
func NewPacket(message string, interfaces ...Interface) *Packet
NewPacket constructs a packet with the specified message and interfaces.
func NewPacketWithExtra(message string, extra Extra, interfaces ...Interface) *Packet
NewPacketWithExtra constructs a packet with the specified message, extra information, and interfaces.
Init initializes required fields in a packet. It is typically called by Client.Send/Report automatically.
type SourceCodeLoader interface { Load(filename string, line, context int) ([][]byte, int) }
type Stacktrace struct {
Frames []*[StacktraceFrame](#StacktraceFrame) `json:"frames"`}
https://docs.getsentry.com/hosted/clientdev/interfaces/#failure-interfaces
Try to get stacktrace from err as an interface of github.com/pkg/errors, or else NewStacktrace()
func NewStacktrace(skip int, context int, appPackagePrefixes []string) *Stacktrace
Intialize and populate a new stacktrace, skipping skip frames.
context is the number of surrounding lines that should be included for context. Setting context to 3 would try to get seven lines. Setting context to -1 returns one line with no surrounding context, and 0 returns no context.
appPackagePrefixes is a list of prefixes used to check whether a package should be considered "in app".
type StacktraceFrame struct {
Filename [string](/builtin#string) `json:"filename,omitempty"`
Function [string](/builtin#string) `json:"function,omitempty"`
Module [string](/builtin#string) `json:"module,omitempty"`
Lineno [int](/builtin#int) `json:"lineno,omitempty"`
Colno [int](/builtin#int) `json:"colno,omitempty"`
AbsolutePath [string](/builtin#string) `json:"abs_path,omitempty"`
ContextLine [string](/builtin#string) `json:"context_line,omitempty"`
PreContext [][string](/builtin#string) `json:"pre_context,omitempty"`
PostContext [][string](/builtin#string) `json:"post_context,omitempty"`
InApp [bool](/builtin#bool) `json:"in_app"`}
Build a single frame using data returned from runtime.Caller.
context is the number of surrounding lines that should be included for context. Setting context to 3 would try to get seven lines. Setting context to -1 returns one line with no surrounding context, and 0 returns no context.
appPackagePrefixes is a list of prefixes used to check whether a package should be considered "in app".
func (timestamp *Timestamp) UnmarshalJSON(data []byte) error
type Transport interface { Send(url, authHeader string, packet *Packet) error }
type Writer struct { Client *Client Level Severity Logger string }
Write formats the byte slice p into a string, and sends a message to Sentry at the severity level indicated by the Writer w.