raven-go: github.com/getsentry/raven-go Index | Examples | Files | Directories

package raven

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

Package raven implements a client for the Sentry error logging service.

Code:

// ... 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)

Index

Examples

Package Files

client.go errors.go exception.go http.go interfaces.go stacktrace.go writer.go

Constants

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

Variables

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")
)
var DefaultClient = newClient(nil)

Initialize a default *Client instance

var MaxQueueBuffer = 100

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.

func Capture Uses

func Capture(packet *Packet, captureTags map[string]string) (eventID string, ch chan error)

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.

func CaptureError Uses

func CaptureError(err error, tags map[string]string, interfaces ...Interface) string

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 Uses

func CaptureErrorAndWait(err error, tags map[string]string, interfaces ...Interface) string

CaptureErrorAndWait is identical to CaptureError, except it blocks and assures that the event was sent

func CaptureMessage Uses

func CaptureMessage(message string, tags map[string]string, interfaces ...Interface) string

CaptureMessage formats and delivers a string message to the Sentry server with the default *Client

func CaptureMessageAndWait Uses

func CaptureMessageAndWait(message string, tags map[string]string, interfaces ...Interface) string

CaptureMessageAndWait is identical to CaptureMessage except it blocks and waits for the message to be sent.

func CapturePanic Uses

func CapturePanic(f func(), tags map[string]string, interfaces ...Interface) (interface{}, 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 CapturePanicAndWait Uses

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

func ClearContext Uses

func ClearContext()

func Close Uses

func Close()

func IncludePaths Uses

func IncludePaths() []string

func ProjectID Uses

func ProjectID() string

func Recoverer Uses

func Recoverer(handler http.Handler) http.Handler

Recovery handler to wrap the stdlib net/http Mux. Example:

 mux := http.NewServeMux
 ...
	http.Handle("/", raven.Recoverer(mux))

func RecoveryHandler Uses

func RecoveryHandler(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)

Recovery handler to wrap the stdlib net/http Mux. Example:

http.HandleFunc("/", raven.RecoveryHandler(func(w http.ResponseWriter, r *http.Request) {
	...
}))

func Release Uses

func Release() string

func SetDSN Uses

func SetDSN(dsn string) error

Sets the DSN for the default *Client instance

func SetDefaultLoggerName Uses

func SetDefaultLoggerName(name string)

SetDefaultLoggerName sets the "defaultLoggerName" on the default *Client

func SetEnvironment Uses

func SetEnvironment(environment string)

SetEnvironment sets the "environment" tag on the default *Client

func SetHttpContext Uses

func SetHttpContext(h *Http)

func SetIgnoreErrors Uses

func SetIgnoreErrors(errs ...string) error

func SetIncludePaths Uses

func SetIncludePaths(p []string)

func SetRelease Uses

func SetRelease(release string)

SetRelease sets the "release" tag on the default *Client

func SetSampleRate Uses

func SetSampleRate(rate float32) error

SetSampleRate sets the "sample rate" on the degault *Client

func SetSourceCodeLoader Uses

func SetSourceCodeLoader(loader SourceCodeLoader)

func SetTagsContext Uses

func SetTagsContext(t map[string]string)

func SetUserContext Uses

func SetUserContext(u *User)

func URL Uses

func URL() string

func Wait Uses

func Wait()

Wait blocks and waits for all events to finish being sent to Sentry server

func WrapWithExtra Uses

func WrapWithExtra(err error, extraInfo map[string]interface{}) error

Adds extra data to an error before reporting to Sentry

type Client Uses

type Client struct {
    Tags map[string]string

    Transport Transport

    // DropHandler is called when a packet is dropped because the buffer is full.
    DropHandler func(*Packet)
    // contains filtered or unexported fields
}

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.

func New Uses

func New(dsn string) (*Client, error)

New constructs a new Sentry client instance

func NewClient Uses

func NewClient(dsn string, tags map[string]string) (*Client, error)

NewClient constructs a Sentry client and spawns a background goroutine to handle packets sent by Client.Report.

Deprecated: use New and NewWithTags instead

func NewWithTags Uses

func NewWithTags(dsn string, tags map[string]string) (*Client, error)

NewWithTags constructs a new Sentry client instance with default tags.

func (*Client) Capture Uses

func (client *Client) Capture(packet *Packet, captureTags map[string]string) (eventID string, ch chan error)

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.

func (*Client) CaptureError Uses

func (client *Client) CaptureError(err error, tags map[string]string, interfaces ...Interface) string

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 Uses

func (client *Client) CaptureErrorAndWait(err error, tags map[string]string, interfaces ...Interface) string

CaptureErrorAndWait is identical to CaptureError, except it blocks and assures that the event was sent

func (*Client) CaptureMessage Uses

func (client *Client) CaptureMessage(message string, tags map[string]string, interfaces ...Interface) string

CaptureMessage formats and delivers a string message to the Sentry server.

func (*Client) CaptureMessageAndWait Uses

func (client *Client) CaptureMessageAndWait(message string, tags map[string]string, interfaces ...Interface) string

CaptureMessageAndWait is identical to CaptureMessage except it blocks and waits for the message to be sent.

func (*Client) CapturePanic Uses

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 Uses

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 (*Client) ClearContext Uses

func (c *Client) ClearContext()

func (*Client) Close Uses

func (client *Client) Close()

func (*Client) IncludePaths Uses

func (client *Client) IncludePaths() []string

func (*Client) ProjectID Uses

func (client *Client) ProjectID() string

func (*Client) Release Uses

func (client *Client) Release() string

func (*Client) SetDSN Uses

func (client *Client) SetDSN(dsn string) error

SetDSN updates a client with a new DSN. It safe to call after and concurrently with calls to Report and Send.

func (*Client) SetDefaultLoggerName Uses

func (client *Client) SetDefaultLoggerName(name string)

SetDefaultLoggerName sets the default logger name.

func (*Client) SetEnvironment Uses

func (client *Client) SetEnvironment(environment string)

SetEnvironment sets the "environment" tag.

func (*Client) SetHttpContext Uses

func (c *Client) SetHttpContext(h *Http)

func (*Client) SetIgnoreErrors Uses

func (c *Client) SetIgnoreErrors(errs []string) error

func (*Client) SetIncludePaths Uses

func (client *Client) SetIncludePaths(p []string)

func (*Client) SetRelease Uses

func (client *Client) SetRelease(release string)

SetRelease sets the "release" tag.

func (*Client) SetSampleRate Uses

func (client *Client) SetSampleRate(rate float32) error

SetSampleRate sets how much sampling we want on client side

func (*Client) SetTagsContext Uses

func (c *Client) SetTagsContext(t map[string]string)

func (*Client) SetUserContext Uses

func (c *Client) SetUserContext(u *User)

func (*Client) URL Uses

func (client *Client) URL() string

func (*Client) Wait Uses

func (client *Client) Wait()

Wait blocks and waits for all events to finish being sent to Sentry server

type Culpriter Uses

type Culpriter interface {
    Culprit() string
}

type ErrWithExtra Uses

type ErrWithExtra interface {
    Error() string
    Cause() error
    ExtraInfo() Extra
}

type Exception Uses

type Exception struct {
    // Required
    Value string `json:"value"`

    // Optional
    Type       string      `json:"type,omitempty"`
    Module     string      `json:"module,omitempty"`
    Stacktrace *Stacktrace `json:"stacktrace,omitempty"`
}

https://docs.getsentry.com/hosted/clientdev/interfaces/#failure-interfaces

func NewException Uses

func NewException(err error, stacktrace *Stacktrace) *Exception

func (*Exception) Class Uses

func (e *Exception) Class() string

func (*Exception) Culprit Uses

func (e *Exception) Culprit() string

type Exceptions Uses

type Exceptions struct {
    // Required
    Values []*Exception `json:"values"`
}

Exceptions allows for chained errors https://docs.sentry.io/clientdev/interfaces/exception/

func (Exceptions) Class Uses

func (es Exceptions) Class() string

type Extra Uses

type Extra map[string]interface{}

type HTTPTransport Uses

type HTTPTransport struct {
    *http.Client
}

HTTPTransport is the default transport, delivering packets to Sentry via the HTTP API.

func (*HTTPTransport) Send Uses

func (t *HTTPTransport) Send(url, authHeader string, packet *Packet) error

type Http Uses

type Http struct {
    // Required
    URL    string `json:"url"`
    Method string `json:"method"`
    Query  string `json:"query_string,omitempty"`

    // Optional
    Cookies string            `json:"cookies,omitempty"`
    Headers map[string]string `json:"headers,omitempty"`
    Env     map[string]string `json:"env,omitempty"`

    // Must be either a string or map[string]string
    Data interface{} `json:"data,omitempty"`
}

https://docs.getsentry.com/hosted/clientdev/interfaces/#context-interfaces

func NewHttp Uses

func NewHttp(req *http.Request) *Http

func (*Http) Class Uses

func (h *Http) Class() string

type Interface Uses

type Interface interface {
    // The Sentry class name. Example: sentry.interfaces.Stacktrace
    Class() string
}

An Interface is a Sentry interface that will be serialized as JSON. It must implement json.Marshaler or use json struct tags.

type Message Uses

type Message struct {
    // Required
    Message string `json:"message"`

    // Optional
    Params []interface{} `json:"params,omitempty"`
}

https://docs.getsentry.com/hosted/clientdev/interfaces/#message-interface

func (*Message) Class Uses

func (m *Message) Class() string

type Packet Uses

type Packet struct {
    // Required
    Message string `json:"message"`

    // Required, set automatically by Client.Send/Report via Packet.Init if blank
    EventID   string    `json:"event_id"`
    Project   string    `json:"project"`
    Timestamp Timestamp `json:"timestamp"`
    Level     Severity  `json:"level"`
    Logger    string    `json:"logger"`

    // Optional
    Platform    string            `json:"platform,omitempty"`
    Culprit     string            `json:"culprit,omitempty"`
    ServerName  string            `json:"server_name,omitempty"`
    Release     string            `json:"release,omitempty"`
    Environment string            `json:"environment,omitempty"`
    Tags        Tags              `json:"tags,omitempty"`
    Modules     map[string]string `json:"modules,omitempty"`
    Fingerprint []string          `json:"fingerprint,omitempty"`
    Extra       Extra             `json:"extra,omitempty"`

    Interfaces []Interface `json:"-"`
}

https://docs.getsentry.com/hosted/clientdev/#building-the-json-packet

func NewPacket Uses

func NewPacket(message string, interfaces ...Interface) *Packet

NewPacket constructs a packet with the specified message and interfaces.

func NewPacketWithExtra Uses

func NewPacketWithExtra(message string, extra Extra, interfaces ...Interface) *Packet

NewPacketWithExtra constructs a packet with the specified message, extra information, and interfaces.

func (*Packet) AddTags Uses

func (packet *Packet) AddTags(tags map[string]string)

func (*Packet) Init Uses

func (packet *Packet) Init(project string) error

Init initializes required fields in a packet. It is typically called by Client.Send/Report automatically.

func (*Packet) JSON Uses

func (packet *Packet) JSON() ([]byte, error)

type Query Uses

type Query struct {
    // Required
    Query string `json:"query"`

    // Optional
    Engine string `json:"engine,omitempty"`
}

https://docs.getsentry.com/hosted/clientdev/interfaces/#context-interfaces

func (*Query) Class Uses

func (q *Query) Class() string

type Severity Uses

type Severity string

type SourceCodeLoader Uses

type SourceCodeLoader interface {
    Load(filename string, line, context int) ([][]byte, int)
}

type Stacktrace Uses

type Stacktrace struct {
    // Required
    Frames []*StacktraceFrame `json:"frames"`
}

https://docs.getsentry.com/hosted/clientdev/interfaces/#failure-interfaces

func GetOrNewStacktrace Uses

func GetOrNewStacktrace(err error, skip int, context int, appPackagePrefixes []string) *Stacktrace

Try to get stacktrace from err as an interface of github.com/pkg/errors, or else NewStacktrace()

func NewStacktrace Uses

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".

func (*Stacktrace) Class Uses

func (s *Stacktrace) Class() string

func (*Stacktrace) Culprit Uses

func (s *Stacktrace) Culprit() string

type StacktraceFrame Uses

type StacktraceFrame struct {
    // At least one required
    Filename string `json:"filename,omitempty"`
    Function string `json:"function,omitempty"`
    Module   string `json:"module,omitempty"`

    // Optional
    Lineno       int      `json:"lineno,omitempty"`
    Colno        int      `json:"colno,omitempty"`
    AbsolutePath string   `json:"abs_path,omitempty"`
    ContextLine  string   `json:"context_line,omitempty"`
    PreContext   []string `json:"pre_context,omitempty"`
    PostContext  []string `json:"post_context,omitempty"`
    InApp        bool     `json:"in_app"`
}

func NewStacktraceFrame Uses

func NewStacktraceFrame(pc uintptr, fName, file string, line, context int, appPackagePrefixes []string) *StacktraceFrame

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".

type Tag Uses

type Tag struct {
    Key   string
    Value string
}

func (*Tag) MarshalJSON Uses

func (tag *Tag) MarshalJSON() ([]byte, error)

func (*Tag) UnmarshalJSON Uses

func (t *Tag) UnmarshalJSON(data []byte) error

type Tags Uses

type Tags []Tag

func (*Tags) UnmarshalJSON Uses

func (t *Tags) UnmarshalJSON(data []byte) error

type Template Uses

type Template struct {
    // Required
    Filename    string `json:"filename"`
    Lineno      int    `json:"lineno"`
    ContextLine string `json:"context_line"`

    // Optional
    PreContext   []string `json:"pre_context,omitempty"`
    PostContext  []string `json:"post_context,omitempty"`
    AbsolutePath string   `json:"abs_path,omitempty"`
}

https://docs.getsentry.com/hosted/clientdev/interfaces/#template-interface

func (*Template) Class Uses

func (t *Template) Class() string

type Timestamp Uses

type Timestamp time.Time

func (Timestamp) Format Uses

func (timestamp Timestamp) Format(format string) string

func (Timestamp) MarshalJSON Uses

func (t Timestamp) MarshalJSON() ([]byte, error)

func (*Timestamp) UnmarshalJSON Uses

func (timestamp *Timestamp) UnmarshalJSON(data []byte) error

type Transport Uses

type Transport interface {
    Send(url, authHeader string, packet *Packet) error
}

type User Uses

type User struct {
    // All fields are optional
    ID       string `json:"id,omitempty"`
    Username string `json:"username,omitempty"`
    Email    string `json:"email,omitempty"`
    IP       string `json:"ip_address,omitempty"`
}

https://docs.getsentry.com/hosted/clientdev/interfaces/#context-interfaces

func (*User) Class Uses

func (h *User) Class() string

type Writer Uses

type Writer struct {
    Client *Client
    Level  Severity
    Logger string // Logger name reported to Sentry
}

func (*Writer) Write Uses

func (w *Writer) Write(p []byte) (int, error)

Write formats the byte slice p into a string, and sends a message to Sentry at the severity level indicated by the Writer w.

Directories

PathSynopsis
example

Package raven imports 28 packages (graph) and is imported by 416 packages. Updated 2019-01-05. Refresh now. Tools for package owners.