Documentation ¶
Index ¶
- Constants
- Variables
- func BeforeNotify(handler func(notice *Notice) error)
- func Configure(c Configuration)
- func Flush()
- func Handler(h http.Handler) http.Handler
- func Monitor()
- func MonitorCtx(ctx context.Context)
- func Notify(ctx context.Context, err interface{}, extra ...interface{}) (string, error)
- func SetContext(ctx context.Context, c Context) context.Context
- type Backend
- type CGIData
- type Client
- func (client *Client) BeforeNotify(handler func(notice *Notice) error)
- func (client *Client) Configure(config Configuration)
- func (client *Client) Flush()
- func (client *Client) Handler(h http.Handler) http.Handler
- func (client *Client) Monitor(ctx context.Context)
- func (client *Client) Notify(ctx context.Context, err interface{}, extra ...interface{}) (string, error)
- func (client *Client) SetContext(ctx context.Context, val Context) context.Context
- type Configuration
- type Context
- type Error
- type ErrorClass
- type Feature
- type Fingerprint
- type Frame
- type Logger
- type Notice
- type Params
- type Payload
- type Tags
Constants ¶
const VERSION = "0.5.0"
VERSION defines the version of the honeybadger package.
Variables ¶
var ( // client is a pre-defined "global" client. DefaultClient = New(Configuration{}) // Config is a pointer to the global client's Config. Config = DefaultClient.Config // Notices is the feature for sending error reports. Notices = Feature{"notices"} )
var ( ErrRateExceeded = errors.New("Rate exceeded: slow down!") ErrPaymentRequired = errors.New("Payment required: expired trial or credit card?") )
Errors returned by the backend when unable to successfully handle payload.
Functions ¶
func BeforeNotify ¶ added in v0.0.2
BeforeNotify adds a callback function which is run before a notice is reported to Honeybadger. If any function returns an error the notification will be skipped, otherwise it will be sent.
func Configure ¶
func Configure(c Configuration)
Configure updates configuration of the global client.
func Flush ¶
func Flush()
Flush blocks until all data (normally sent in the background) has been sent to the Honeybadger service.
func Handler ¶
Handler returns an http.Handler function which automatically reports panics to Honeybadger and then re-panics.
The request context is what's passed to notify.
func Monitor ¶
func Monitor()
Monitor is used to automatically notify Honeybadger service of panics which happen inside the current function. In order to monitor for panics, defer a call to Monitor. For example:
func main { defer honeybadger.Monitor() // Do risky stuff... }
The Monitor function re-panics after the notification has been sent, so it's still up to the user to recover from panics if desired.
The Monitor function doesn't have access to any set context from `SetContext` calls.
func MonitorCtx ¶ added in v0.5.0
MonitorCtx is used to automatically notify Honeybadger service of panics which happen inside the current function. In order to monitor for panics, defer a call to MonitorCtx. For example:
func handler(ctx context.Context) { defer honeybadger.MonitorCtx(ctx) // Do risky stuff... }
The MonitorCtx function re-panics after the notification has been sent, so it's still up to the user to recover from panics if desired.
Has access to any context set when using `SetCtx`
func Notify ¶
Notify reports the error err to the Honeybadger service.
The first argument err may be an error, a string, or any other type in which case its formatted value will be used.
It returns a string UUID which can be used to reference the error from the Honeybadger service, and an error as a second argument.
Types ¶
type Backend ¶
The Backend interface is implemented by the server type by default, but a custom implementation may be configured by the user.
func NewNullBackend ¶ added in v0.0.3
func NewNullBackend() Backend
NewNullBackend creates a backend which swallows all errors and does not send them to Honeybadger. This is useful for development and testing to disable sending unnecessary errors.
type CGIData ¶
type CGIData hash
CGIData stores variables from the server/request environment indexed by key. Header keys should be converted to upercase, all non-alphanumeric characters replaced with underscores, and prefixed with HTTP_. For example, the header "Content-Type" would become "HTTP_CONTENT_TYPE".
type Client ¶
type Client struct { Config *Configuration // contains filtered or unexported fields }
Client is the manager for interacting with the Honeybadger service. It holds the configuration and implements the public API.
func (*Client) BeforeNotify ¶ added in v0.0.2
BeforeNotify adds a callback function which is run before a notice is reported to Honeybadger. If any function returns an error the notification will be skipped, otherwise it will be sent.
func (*Client) Configure ¶
func (client *Client) Configure(config Configuration)
Configure updates the client configuration with the supplied config.
func (*Client) Flush ¶
func (client *Client) Flush()
Flush blocks until the worker has processed its queue.
func (*Client) Handler ¶
Handler returns an http.Handler function which automatically reports panics to Honeybadger and then re-panics.
func (*Client) Monitor ¶
Monitor automatically reports panics which occur in the function it's called from. Must be deferred.
type Configuration ¶
type Configuration struct { APIKey string Root string Env string Hostname string Endpoint string Timeout time.Duration Logger Logger Backend Backend }
Configuration manages the configuration for the client.
type Error ¶
type Error struct { Message string Class string Stack []*Frame // contains filtered or unexported fields }
Error provides more structured information about a Go error.
type ErrorClass ¶ added in v0.0.2
type ErrorClass struct {
Name string
}
ErrorClass represents the class name of the error which is sent to Honeybadger.
type Feature ¶
type Feature struct {
Endpoint string
}
Feature references a resource provided by the API service. Its Endpoint maps to the collection endpoint of the /v1 API.
type Fingerprint ¶ added in v0.0.2
type Fingerprint struct {
Content string
}
Fingerprint represents the fingerprint of the error, which controls grouping in Honeybadger.
func (*Fingerprint) String ¶ added in v0.0.2
func (f *Fingerprint) String() string
type Frame ¶
type Frame struct { Number string `json:"number"` File string `json:"file"` Method string `json:"method"` }
Frame represent a stack frame inside of a Honeybadger backtrace.
type Logger ¶
type Logger interface {
Printf(format string, v ...interface{})
}
The Logger interface is implemented by the standard log package and requires a limited subset of the interface implemented by log.Logger.
type Notice ¶
type Notice struct { APIKey string Error Error Token string ErrorMessage string ErrorClass string Tags []string Hostname string Env string Backtrace []*Frame ProjectRoot string Context Context Params Params CGIData CGIData URL string Fingerprint string }
Notice is a representation of the error which is sent to Honeybadger, and implements the Payload interface.