GithubHelp home page GithubHelp logo

isabella232 / raygun4go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mindscapehq/raygun4go

0.0 0.0 0.0 64 KB

Go SDK for Raygun

Home Page: https://raygun.com

License: MIT License

Go 100.00%

raygun4go's Introduction

raygun4go

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/MindscapeHQ/raygun4go

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. It'll automatically capture any panic and report it. Having found the right spot, just add the following example code:

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

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 send the error to Raygun.

Manually sending errors

To send errors manually you can use CreateError(message string), or SendError(error error). CreateError creates an error and immediately reports it, SendError immediately reports the error.

if err := raygun.CreateError("something bad happened"); err != nil {
    log.Printf("failed to report error to Raygun: %v\n", err)
}
err := something.Do()
if err := raygun.SendError(err); err != nil {
    log.Printf("failed to report error to Raygun: %v\n", err)
}

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.

Custom grouping

By default, the Raygun service will group errors together based on stacktrace content. If you have any cases where you want to control the error grouping yourself, then you can provide a custom-grouping-key callback function. Below is a simple example of this, that returns a hard-coded grouping key, which would cause all errors to be grouped together:

raygun.CustomGroupingKeyFunction(func(error, raygun4go.PostData)string{return "customGroupingKey"})

The callback takes the original error, and the Raygun PostData payload structure that is about to be serialized and sent to Raygun. In your callback, you can check these values to help build your own grouping key logic based on different cases that you want to control. For any error you don't want to group yourself, return an empty string - Raygun will then use the default grouping.

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.

raygun4go's People

Contributors

ajmath avatar alissonsales avatar andersonq avatar crahles avatar douglas-soares avatar izsi-salmon avatar jaycoba avatar laher avatar quantumnightmare avatar r2k1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.