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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 WithLogger ¶
WithLogger adds Logger to Client. Client would be logging messages passed to it as well as delivery/overflow errors to this Logger.
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 ¶
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 ¶
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.