reporter

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2016 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

package reporter provides a context.Context aware abstraction for shuttling errors and panics to third partys.

Index

Constants

This section is empty.

Variables

View Source
var DefaultMax = 1024

DefaultMax is the default maximum number of lines to show from the backtrace.

Functions

func AddContext

func AddContext(ctx context.Context, key string, value interface{})

AddContext adds contextual information to the Request object.

func AddRequest

func AddRequest(ctx context.Context, req *http.Request)

AddRequest adds information from an http.Request to the Request object.

func Monitor

func Monitor(ctx context.Context)

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)

func Report

func Report(ctx context.Context, err error) error

Report wraps the err as an Error and reports it the the Reporter embedded within the context.Context.

func WithReporter

func WithReporter(ctx context.Context, r Reporter) context.Context

WithReporter inserts a Reporter into the context.Context.

Types

type BacktraceLine

type BacktraceLine struct {
	PC   uintptr
	File string
	Line int
}

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

func NewError(err error, skip int) *Error

NewError wraps err as an Error and generates a backtrace pointing at the caller of this function.

func NewErrorWithContext

func NewErrorWithContext(ctx context.Context, err error, skip int) *Error

NewErrorWithContext returns a new Error with contextual information added.

func (*Error) Error

func (e *Error) Error() string

Make error implement the error interface.

type FallbackReporter

type FallbackReporter struct {
	// The first reporter to call.
	Reporter Reporter

	// This reporter will be used to report an error if the first Reporter
	// fails for some reason.
	Fallback Reporter
}

func (*FallbackReporter) Report

func (r *FallbackReporter) Report(ctx context.Context, err error) error

type LogReporter

type LogReporter struct{}

LogReporter is a Handler that logs the error to a log.Logger.

func NewLogReporter

func NewLogReporter() *LogReporter

func (*LogReporter) Report

func (h *LogReporter) Report(ctx context.Context, err error) error

Report logs the error to the Logger.

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.

func (MultiReporter) Report

func (r MultiReporter) Report(ctx context.Context, err error) error

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.

func FromContext

func FromContext(ctx context.Context) (Reporter, bool)

FromContext extracts a Reporter from a context.Context.

type ReporterFunc

type ReporterFunc func(context.Context, error) error

ReporterFunc is a function signature that conforms to the Reporter interface.

func (ReporterFunc) Report

func (f ReporterFunc) Report(ctx context.Context, err error) error

Report implements the Reporter interface.

Directories

Path Synopsis
package hb2 is a Go package for sending errors to Honeybadger using the official client library
package hb2 is a Go package for sending errors to Honeybadger using the official client library

Jump to

Keyboard shortcuts

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