Documentation ¶
Overview ¶
Package raven implements a client for the Sentry error logging service.
Example ¶
// ... 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 config := &ClientConfig{nil, nil} client, err := NewClient(sentryDSN, config) 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)
Output:
Index ¶
- Constants
- Variables
- type Client
- 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) CaptureMessage(message string, tags map[string]string, interfaces ...Interface) string
- func (client *Client) CapturePanic(f func(), tags map[string]string, interfaces ...Interface)
- func (client *Client) Close()
- func (client *Client) ProjectID() string
- func (client *Client) Scrub(packet *Packet) *Packet
- func (client *Client) SetDSN(dsn string) error
- func (client *Client) URL() string
- type ClientConfig
- type Culpriter
- type Exception
- type HTTPTransport
- type Http
- type Interface
- type Message
- type Packet
- type Processor
- type Query
- type Severity
- type Stacktrace
- type StacktraceFrame
- type Tag
- type Tags
- type Template
- type Timestamp
- type Transport
- type User
- type Writer
Examples ¶
Constants ¶
const ( DEBUG Severity = "debug" INFO = "info" WARNING = "warning" ERROR = "error" FATAL = "fatal" )
http://docs.python.org/2/howto/logging.html#logging-levels
const Mask = "********"
Variables ¶
var ErrPacketDropped = errors.New("raven: packet dropped")
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.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Config *ClientConfig 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 NewClient ¶
func NewClient(dsn string, config *ClientConfig) (*Client, error)
NewClient constructs a Sentry client and spawns a background goroutine to handle packets sent by Client.Report.
func (*Client) Capture ¶
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 ¶
func (client *Client) CaptureError(err error, tags map[string]string, interfaces ...Interface) string
CaptureErrors formats and delivers an errorto the Sentry server. Adds a stacktrace to the packet, excluding the call to this method.
func (*Client) CaptureMessage ¶
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) CapturePanic ¶
CapturePanic calls f and then recovers and reports a panic to the Sentry server if it occurs.
type ClientConfig ¶
type Exception ¶
type Exception struct { // Required Value string `json:"value"` // Optional Type string `json:"type,omitempty"` Module string `json:"module,omitempty"` Stacktrace *Stacktrace `json:"stacktrace,omitempty"` }
http://sentry.readthedocs.org/en/latest/developer/interfaces/index.html#sentry.interfaces.Exception
func NewException ¶
func NewException(err error, stacktrace *Stacktrace) *Exception
type HTTPTransport ¶
HTTPTransport is the default transport, delivering packets to Sentry via the HTTP API.
type Http ¶
type Http struct { // Required URL string `json:"url"` Method string `json:"method"` Query string `json:"query_string,omitempty"` // Optional 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"` }
http://sentry.readthedocs.org/en/latest/developer/interfaces/index.html#sentry.interfaces.Http
type Interface ¶
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 ¶
type Message struct { // Required Message string `json:"message"` // Optional Params []interface{} `json:"params,omitempty"` }
http://sentry.readthedocs.org/en/latest/developer/interfaces/index.html#sentry.interfaces.Message
type Packet ¶
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"` Tags Tags `json:"tags,omitempty"` ServerName string `json:"server_name,omitempty"` Modules []map[string]string `json:"modules,omitempty"` Extra map[string]interface{} `json:"extra,omitempty"` Interfaces []Interface `json:"-"` }
http://sentry.readthedocs.org/en/latest/developer/client/index.html#building-the-json-packet
type Query ¶
type Query struct { // Required Query string `json:"query"` // Optional Engine string `json:"engine,omitempty"` }
http://sentry.readthedocs.org/en/latest/developer/interfaces/index.html#sentry.interfaces.Query
type Stacktrace ¶
type Stacktrace struct { // Required Frames []*StacktraceFrame `json:"frames"` }
http://sentry.readthedocs.org/en/latest/developer/interfaces/index.html#sentry.interfaces.Stacktrace
func 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".
func (*Stacktrace) Class ¶
func (s *Stacktrace) Class() string
func (*Stacktrace) Culprit ¶
func (s *Stacktrace) Culprit() string
type StacktraceFrame ¶
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,omitempty"` }
func NewStacktraceFrame ¶
func NewStacktraceFrame(pc uintptr, 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 Template ¶
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"` }
http://sentry.readthedocs.org/en/latest/developer/interfaces/index.html#sentry.interfaces.Template
type User ¶
type User struct { ID string `json:"id"` Username string `json:"username,omitempty"` Email string `json:"email,omitempty"` }
http://sentry.readthedocs.org/en/latest/developer/interfaces/index.html#sentry.interfaces.User