raygun4go

package module
v0.0.0-...-5ec555c Latest Latest
Warning

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

Go to latest
Published: May 23, 2016 License: MIT Imports: 13 Imported by: 0

README

raygun4goGAE

Build Status Build status Coverage GoDoc GoReportcard

raygun4go adds Raygun-based error handling to your golang code. It catches all occuring errors, extracts as much information as possible and sends the error to Raygun via their REST-API.

Getting Started

Installation
  $ go get github.com/miko-code/raygun4goGAE
Basic Usage

Include the package and then defer the HandleError-method as soon as possible in a context as global as possible. In webservers, this will probably be your request handling method, in all other programs it should be your main-method. Having found the right spot, just add the following example code:

//generate new appengine context
ctx := appengine.NewContext(r)

raygun, err := raygun4go.New("appName", "apiKey")
if err != nil {
  log.Println("Unable to create Raygun client:", err.Error())
}
raygun.Silent(true)
defer raygun.HandleError(ctx)

raygun.CreateError("this is error", ctx)


where appName is the name of your app and apiKey is your Raygun-API-key. If your program runs into a panic now (which you can easily test by adding panic("foo") after the call to defer), the handler will print the resulting error message. If you remove the line

raygun.Silent(true)

the error will be sent to Raygun using your API-key.

Options

The client returned by New has several chainable option-setting methods

Method Description
Silent(bool) If set to true, this prevents the handler from sending the error to Raygun, printing it instead.
Request(*http.Request) Adds the responsible http.Request to the error.
Version(string) If your program has a version, you can add it here.
Tags([]string) Adds the given tags to the error. These can be used for filtering later.
CustomData(interface{}) Add arbitrary custom data to you error. Will only reach Raygun if it works with json.Marshal().
User(string) Add the name of the affected user to the error.

Bugs and feature requests

Have a bug or a feature request? Please first check the list of issues.

If your problem or idea is not addressed yet, please open a new issue.

Documentation

Overview

Package raygun4go adds Raygun-based error handling to your golang code.

It basically adds an error-handler that recovers from all panics that might occur and sends information about that error to Raygun. The amount of data being sent is configurable.

Basic example:

raygun, err := raygun4go.New("appName", "apiKey")
if err != nil {
  log.Println("Unable to create Raygun client:", err.Error())
}
defer raygun.HandleError()

This will send the error message together with a stack trace to Raygun.

However, raygun4go really starts to shine if used in a webserver context. By calling

raygun.Request(*http.Request)

you can set a request to be analyzed in case of an error. If an error occurs, this will send the request details to Raygun, including

  • hostname
  • url
  • http method
  • ip adress
  • url parameters
  • POSTed form fields
  • headers
  • cookies

giving you a lot more leverage on your errors than the plain error message could provide you with.

Chainable configuration methods are available (see below) to set the affected version, user, tags or custom data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the struct holding your Raygun configuration and context information that is needed if an error occurs.

func New

func New(appName, apiKey string) (c *Client, err error)

New creates and. returns a Client, needing an appName and an apiKey. It also creates a unique identifier for you program.

func (*Client) CreateError

func (c *Client) CreateError(message string, ctx gcontext.Context)

CreateError is a simple wrapper to manually post messages (errors) to raygun

func (*Client) CustomData

func (c *Client) CustomData(data interface{}) *Client

CustomData is a chainable option-setting method to add arbitrary custom data to the context. Note that the given type (or at least parts of it) must implement the Marshaler-interface for this to work.

func (*Client) HandleError

func (c *Client) HandleError(ctx gcontext.Context)

HandleError sets up the error handling code. It needs to be called with

defer c.HandleError()

to handle all panics inside the calling function and all calls made from it. Be sure to call .this in your main function or (if it is webserver) in your request handler as soon as possible.

func (*Client) Request

func (c *Client) Request(r *http.Request) *Client

Request is a chainable option-setting method to add a request to the context.

func (*Client) Silent

func (c *Client) Silent(s bool) *Client

Silent sets the silent-property on the Client. If true, errors will not be sent to Raygun but printed instead.

func (*Client) Tags

func (c *Client) Tags(tags []string) *Client

Tags is a chainable option-setting method to add tags to the context. You can use tags to filter errors in Raygun.

func (*Client) User

func (c *Client) User(u string) *Client

User is a chainable option-setting method to add an affected Username to the context.

func (*Client) Version

func (c *Client) Version(v string) *Client

Version is a chainable option-setting method to add a version to the context.

type UserCustomData

type UserCustomData interface{}

UserCustomData is the interface that needs to be implemented by the custom data to be sent with the error. Being 'interface{}' suggests that it could be anything, but the data itself or contained data should respond to json.Marshal() for the data to be transmitted.

Jump to

Keyboard shortcuts

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