Help us shape the future of Go! Take the 2026 Go Developer Survey

raven

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package raven implements basic Sentry client compatible with standard logging facilities.

Consider your program takes *log.Logger and only uses its Print, Println, Printf methods. Then you can update your code signature to take Logger interface instead of exact *log.Logger type and use this package to provide drop-in replacement to usual logging like this:

logger, err := raven.New(WithDSN(os.Getenv("SENTRY_DSN")))
... // handle error

logger.Print("some informational message")

if err := myfunc() ; err != nil {
	logger.Printf("myfunc failed: %v", err)
}

Client automatically marks messages having non-nil error arguments as error events in Sentry; if error has stacktrace attached to it with github.com/pkg/errors package, this stacktrace is sent to Sentry as well.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a basic Sentry client implementing Logger interface. Consider using this interface in your code, as this would allow usage of stdlib log.Logger and Client interchangeably. Client also implements io.Writer interface specifically to be used as the underlying writer for log package Logger when it's impossible to use interface.

func New

func New(conf ...ConfFunc) (*Client, error)

New returns new Client initialized with provided configuration functions. Basic configuration can be done using only WithDSN function:

client, err := New(WithDSN("https://public:secret@sentry.example.com/1"))
...

func (*Client) Close

func (c *Client) Close() error

Close stops background goroutine processing message queue. Any messages pushed to closed Client would be discarded.

func (*Client) Print

func (c *Client) Print(v ...interface{})

Print creates new event and pushes it to outgoing queue. Arguments are handled in the manner of fmt.Print.

func (*Client) Printf

func (c *Client) Printf(format string, v ...interface{})

Printf creates new event and pushes it to outgoing queue. Arguments are handled in the manner of fmt.Printf.

func (*Client) Println

func (c *Client) Println(v ...interface{})

Println creates new event and pushes it to outgoing queue. Arguments are handled in the manner of fmt.Println.

func (*Client) Wait

func (c *Client) Wait()

Wait blocks until background goroutine processing message queue returns, which normally happens after Close() call. This method can be used to make sure ongoing message delivery completes during program shutdown.

func (*Client) Write

func (c *Client) Write(p []byte) (int, error)

Write implements io.Writer interface so that Client can be used as an underlying writer for log.Logger. It relies on log.Logger semantics that each logging operation makes a single call to the Writer's Write method. Write calls are non-blocking, they only put payload to send queue, so for cases where log output is followed by program termination (i.e. log.Fatal() call) queued but unsent output will be lost.

type ConfFunc

type ConfFunc func(*Client) (*Client, error)

ConfFunc is a function mutating Client that is used for configuration when creating new Client. These functions should only be used as an argument to New() function when creating new Client, attempt to apply such functions to alreaty started client panics.

func WithDSN

func WithDSN(dsn string) ConfFunc

WithDSN configures Client to use Sentry API endpoint specified by given DSN.

func WithLogger

func WithLogger(l Logger) ConfFunc

WithLogger adds Logger to Client. Client would be logging messages passed to it as well as delivery/overflow errors to this Logger.

func WithTags

func WithTags(tags map[string]string) ConfFunc

WithTags configures Client to assign given set of tags to every message it sends.

type Logger

type Logger interface {
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})
}

Logger describes set of methods used by Client for logging; standard lib *log.Logger implements this interface as well.

func AttachExtra

func AttachExtra(l Logger, extra interface{}) Logger

AttachExtra returns sublogger that sends an arbitrary mapping of additional metadata for every message it logs. This function calls json.Marshal on provided interface{} and does not retain pointers to it. If logger is not a *Client or data cannot be marshalled, original logger is returned.

func AttachRequestInfo

func AttachRequestInfo(l Logger, r *http.Request) Logger

AttachRequestInfo returns sublogger that sends given http.Request information with every message it logs. If Logger is not a *Client (i.e. it is *log.Logger), this function returns logger itself.

func AttachTags

func AttachTags(l Logger, tags map[string]string) Logger

AttachTags returns sublogger that sends additional tags for every message it logs. If logger is not *Client, original logger is returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL