goaraygun

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2017 License: MIT Imports: 6 Imported by: 0

README

goa-raygun

A Goa middleware to recover panics and send them to RayGun. Godoc

The minimal setup to have it working is to put the Notify middleware in your middleware chain:

service.Use(middleware.RequestID())
service.Use(middleware.ErrorHandler(service, true))

// this is the middleware
notify := goaraygun.New("MYSECRETRAYGUNKEY", nil)
service.Use(notify.Middleware())

service.Use(middleware.Recover())

And that's it. Panics and crashes will be sent to Raygun using the key you specified

Cleaner errors

The goa recover middleware creates an error with all the stacktrace in the error message, while raygun wants it outside. You can simply use the goaraygun.Recover middleware:

service.Use(middleware.RequestID())
service.Use(middleware.ErrorHandler(service, true))
notify := goaraygun.New("MYSECRETRAYGUNKEY", nil)
service.Use(notify.Middleware())

// It creates errors more raygun-friendly, but still understandable by ErrorHandler
service.Use(goaraygun.Recover())

Send errors directly

You can use the goa-raygun manager to send an error directly to raygun. Useful if you don't want to stop execution but you still want to know if something went wrong:

notify.Error(context.Background(), err, request, data)

Debugging

If you don't want to send errors while you are debugging you can use the Silent Option. It will print the error in the stdout instead of sending it to the server

notify := goaraygun.New("MYSECRETRAYGUNKEY", &goaraygun.Opts{Silent: true})
service.Use(notify.Middleware())

User info

Every app has its way to retrieve the user info, so if you want that info on raygun you'll have to work a bit for it:

func GetUser(ctx context.Context, req *http.Request) string {
	...
}
notify := goaraygun.New("MYSECRETRAYGUNKEY", &goaraygun.Opts{GetUser: GetUser})
service.Use(notify.Middleware())

Documentation

Overview

Package goaraygun provides a couple of middlewares for https://goa.design/ to send failures to https://raygun.com/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Recover

func Recover() goa.Middleware

Recover is a middleware that recovers panics and maps them to errors. Use this instead of the goa one to have cleaner errors without the stacktrace in their main message.

Types

type Manager added in v1.1.0

type Manager struct {
	Opts Opts
	Key  string
}

Manager exposes a Notify middleware and and an Error function. Use the Notify middleware in the goa middleware chain, and the Error method to send an error to

func New added in v1.1.0

func New(key string, opts *Opts) *Manager

New returns a new Manager

func (*Manager) Error added in v1.1.0

func (m *Manager) Error(ctx context.Context, err error, req *http.Request, tags []string, data interface{})

Error sends a custom error to raygun. You can provide a request, tags and custom data if you want

func (*Manager) Middleware added in v1.1.0

func (m *Manager) Middleware() goa.Middleware

Middleware is a middleware that sends critical errors to Raygun. It should sit between ErrorHandler and Recover in the middleware chain. Key is the raygun api key, opts can be nil or can be an Opts struct

type Opts

type Opts struct {
	// Version is an optional value to provide the version of the app you are monitoring
	Version string
	// Silent is an optional value to avoid sending errors but just to print them in the stdout. Useful for debugging
	Silent bool
	// Skip is an optional function to decide if the error is worth sending to raygun or not.
	// If it's not defined, only panics and status codes of 500 are sent.
	Skip func(ctx context.Context, err error) bool
	// GetUser is an optional function to retrieve the username from the context and/or the request
	GetUser func(ctx context.Context, req *http.Request) string
}

Opts contain the configuration of the Notify middleware

Jump to

Keyboard shortcuts

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