Raygun4go - Go error reporting


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 where it is viewable in the Crash Reporting dashboard.


Getting Started


$ 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. 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 print the resulting error message. If you remove the line


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


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


If set to true, this prevents the handler from sending the error to Raygun, printing it instead.


Adds the responsible http.Request to the error.


If your program has a version, you can add it here.


Adds the given tags to the error. These can be used for filtering later.


Add arbitrary custom data to you error. Will only reach Raygun if it works with json.Marshal().


Add the name of the affected user to the error.

GitHub repository

You can find the source code for this library at https://github.com/MindscapeHQ/raygun4go. If you have any issues or feature requests you can add them there, or by clicking on the Feedback button in the Raygun web app's sidebar.

Documentation missing?

If we don't have documentation about your desired topic, send us a message and we'll create it for you.