Documentation ¶
Overview ¶
package reporter provides a context.Context aware abstraction for shuttling errors and panics to third partys.
Index ¶
- Variables
- func AddContext(ctx context.Context, key string, value interface{})
- func AddRequest(ctx context.Context, req *http.Request)
- func Monitor(ctx context.Context)
- func Report(ctx context.Context, err error) error
- func WithReporter(ctx context.Context, r Reporter) context.Context
- type BacktraceLine
- type Error
- type FallbackReporter
- type LogReporter
- type MultiError
- type MultiReporter
- type Reporter
- type ReporterFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultMax = 1024
DefaultMax is the default maximum number of lines to show from the backtrace.
Functions ¶
func AddContext ¶
AddContext adds contextual information to the Request object.
func AddRequest ¶
AddRequest adds information from an http.Request to the Request object.
func Monitor ¶
Monitors and reports panics. Useful in goroutines. Example:
ctx := reporter.WithReporter(context.Background(), hb2.NewReporter(hb2.Config{})) ... go func(ctx context.Context) { defer reporter.Monitor(ctx) ... panic("oh noes") // will report, then crash. }(ctx)
Types ¶
type BacktraceLine ¶
A line from the backtrace.
type Error ¶
type Error struct { // The error that was generated. Err error // The backtrace. Backtrace []*BacktraceLine // Any freeform contextual information about that error. Context map[string]interface{} // If provided, an http request that generated the error. Request *http.Request }
Error wraps an error with additional information, like a backtrace, contextual information, and an http request if provided.
func NewError ¶
NewError wraps err as an Error and generates a backtrace pointing at the caller of this function.
func NewErrorWithContext ¶
NewErrorWithContext returns a new Error with contextual information added.
type FallbackReporter ¶
type LogReporter ¶
type LogReporter struct{}
LogReporter is a Handler that logs the error to a log.Logger.
func NewLogReporter ¶
func NewLogReporter() *LogReporter
type MultiError ¶
type MultiError struct {
Errors []error
}
MutliError is an error implementation that wraps multiple errors.
func (*MultiError) Error ¶
func (e *MultiError) Error() string
Error implements the error interface. It simply joins all of the individual error messages with a comma.
type MultiReporter ¶
type MultiReporter []Reporter
MultiReporter is an implementation of the Reporter interface that reports the error to multiple Reporters. If any of the individual error reporters returns an error, a MutliError will be returned.
type Reporter ¶
type Reporter interface { // Report reports the error to an external system. The provided error // could be an Error instance, which will contain additional information // about the error, including a backtrace and any contextual // information. Implementers should type assert the error to an *Error // if they want to report the backtrace. Report(context.Context, error) error }
Reporter represents an error handler.