raygunclient

package module
v0.0.0-...-adf0278 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2017 License: MIT Imports: 5 Imported by: 2

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. If you need to send custom stack trace, use 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
Godeps
_workspace/src/github.com/kaeuferportal/stack2struct
As this package will need to evolve with the development of go's stack trace format, this is the stack format the package currently works with: 1: goroutine x [running]: <-- ignore this line 2: path/to/package.functionName() 3: path/to/responsible/file:lineNumber +0xdeadbeef ...
As this package will need to evolve with the development of go's stack trace format, this is the stack format the package currently works with: 1: goroutine x [running]: <-- ignore this line 2: path/to/package.functionName() 3: path/to/responsible/file:lineNumber +0xdeadbeef ...
_workspace/src/github.com/pborman/uuid
The uuid package generates and inspects UUIDs.
The uuid package generates and inspects UUIDs.

Jump to

Keyboard shortcuts

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