Documentation ¶
Overview ¶
Package errornotifier is a notifier "provider" that provides a way to report runtime error. It uses gobrake notifier by default.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NotifyOnPanic ¶
NotifyOnPanic will notify Airbrake if function f panics, and will return the error that caused the panic (if any)
This is for wrapping Goroutines to prevent panics from bringing down the whole application.
Example ¶
package main import ( "fmt" "github.com/theplant/appkit/errornotifier" au "github.com/theplant/appkit/errornotifier/utils" ) func main() { bufferNotifier := &au.BufferNotifier{} // return nil => Do nothing err := errornotifier.NotifyOnPanic(bufferNotifier, nil, func() { fmt.Println("do nothing") }) fmt.Printf("%v %d\n", err, len(bufferNotifier.Notices)) // panic in func => return panic error err = errornotifier.NotifyOnPanic(bufferNotifier, nil, func() { panicErr := "panic" fmt.Println(panicErr) panic(panicErr) }) fmt.Printf("%v %d\n", err, len(bufferNotifier.Notices)) }
Output: do nothing <nil> 0 panic panic 1
Types ¶
type AirbrakeConfig ¶
type AirbrakeConfig struct { ProjectID int64 Token string Environment string `default:"dev"` KeysBlocklist []interface{} Filters []interface{} }
AirbrakeConfig is struct to embed into application config to allow configuration of Airbrake notifier from environment or other external source
type Notifier ¶
type Notifier interface {
Notify(err interface{}, r *http.Request, context map[string]interface{})
}
Notifier defines an interface for reporting error
func ForceContext ¶
ForceContext extracts a notifier from the request context, falling back to a LogNotifier using the context's logger.
func NewAirbrakeNotifier ¶
func NewAirbrakeNotifier(c AirbrakeConfig) (Notifier, io.Closer, error)
NewAirbrakeNotifier constructs Airbrake notifier from given config
Returns error if no Airbrake configuration or airbrake configuration is invalid
Notify is async, call close to wait send data to Airbrake.
func NewLogNotifier ¶
NewLogNotifier constructs notifier that logs error notification messages to given logger