raygunclient

package
v0.0.0-...-646386c Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2016 License: MIT, MIT Imports: 5 Imported by: 0

README

Raygun Client Build Status Coverage Status GoDoc

A Raygun.io golang client for handling errors.

##Usage

import (
	"github.com/gsblue/raygunclient"
    "errors"
)
var n raygunclient.Notifier

func init() {
	n := raygunclient.NewClient("your api key", "application version no", nil)
}

func SomeFunctionWhichNeedsToHandleError() {

	if someErr := doSomeWork(); someErr != nil {
        entry := NewErrorEntry(someErr)
        entry.SetUser("user identifier").
            SetTags([]string{"tag 1", "tag 2"}).
            SetCustomData(&struct{ OrderNo int }{340})
        
        if err := n.Notify(entry); err != nil {
            panic(err)
        }
    }
}

func doSomeWork() error {
    return errors.New("some error")
}

If you are capturing an error in context of a http request, you can send the request data too

import (
	"github.com/gsblue/raygunclient"
    "errors"
)
var n raygunclient.Notifier

func init() {
	n := raygunclient.NewClient("your api key", "application version no", nil)
}

func handle(w http.ResponseWriter, r *http.Request) {
    
    if someErr := doSomeWork(); someErr != nil {
        entry := NewErrorEntry(someErr)
        entry.SetRequest(r)
        
        if err := n.Notify(entry); err != nil {
            panic(err)
        }
    }
}

func doSomeWork() error {
    return errors.New("some error")
}

Note, by default stack trace is captured and sent to raygun. But if you want to use send custom stack trace, you can use the NotifyWithStackTrace method.

Pull requests are welcome.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOptions

type ClientOptions struct {
	Silent bool
	Debug  bool
}

ClientOptions provides the options to configure the behavior of the client

type ErrorEntry

type ErrorEntry struct {
	Error      error
	Request    *httpdata.HTTPRequest
	CustomData interface{}
	User       string
	Tags       []string
}

ErrorEntry holds the information about the error and meta data needed to be recorded in raygun

func NewErrorEntry

func NewErrorEntry(err error) *ErrorEntry

NewErrorEntry creates a new error entry

func (*ErrorEntry) SetCustomData

func (e *ErrorEntry) SetCustomData(data interface{}) *ErrorEntry

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

func (*ErrorEntry) SetRequest

func (e *ErrorEntry) SetRequest(r *http.Request) *ErrorEntry

SetRequest is a chainable option-setting method to add a request to this entry.

func (*ErrorEntry) SetTags

func (e *ErrorEntry) SetTags(tags []string) *ErrorEntry

SetTags is a chainable option-setting method to add tags to this entry.

func (*ErrorEntry) SetUser

func (e *ErrorEntry) SetUser(u string) *ErrorEntry

SetUser is a chainable option-setting method to add an affected Username to this entry.

type Notifier

type Notifier interface {
	Notify(entry *ErrorEntry) error
	NotifyWithStackTrace(entry *ErrorEntry, t stack.Trace) error
}

Notifier notifies raygun about the error

func NewClient

func NewClient(apiKey, version string, opts *ClientOptions) Notifier

NewClient creates a new client to send errors to raygun

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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