# README
Raygun
An unofficial library to send crash reporting to Raygun.
Crash reporting to Raygun is extremely simple: It's an authenticated http POST with json data.
This library provides the struct and some helper methods to help fill them with data.
Recover panics
The classic way to use raygun is to recover panics and send info to the raygun server:
import "github.com/codeclysm/raygun"
func main() {
defer func() {
if e := recover(); e != nil {
post := raygun.NewPost()
post.Details.Error = raygun.FromErr(err)
raygun.Submit(post, "thisismysecretkey", nil)
}
}
panic("This is a panic")
}
Customize error report
A raygun.Post
is just a struct, so you can edit all the fields before sending it. You can fill info about a Request, or about the Window size:
post := raygun.NewPost()
post.Details.Request = raygun.Request{}
post.Details.Environment = raygun.Environment{
WindowBoundsWidth: 500
}
Helpers
raygun.FromErr
and raygun.FromReq
build info from errors and requests. FromErr
also includes a stacktrace, compatible with the stacktraces from https://github.com/pkg/errors and https://github.com/juju/errors:
err := raygun.FromErr(errors.New("new error))
{
"message":"new error",
"stackTrace":[
{
"lineNumber":77,
"className":"github.com/codeclysm/raygun_test",
"fileName":"/opt/workspace/github.com/codeclysm/raygun/raygun_test.go",
"methodName":"wrapErr"
},
{
"lineNumber":31,
"className":"github.com/codeclysm/raygun_test",
"fileName":"/opt/workspace/github.com/codeclysm/raygun/raygun_test.go",
"methodName":"TestFromErr"
},
{
"lineNumber":657,
"className":"testing",
"fileName":"/usr/local/go/src/testing/testing.go",
"methodName":"tRunner"
},
{
"lineNumber":2197,
"className":"runtime",
"fileName":"/usr/local/go/src/runtime/asm_amd64.s",
"methodName":"goexit"
}
]
}
# Functions
FromErr creates an error struct from an error If the error satisfies the interfaces `Class() string` and/or `Data() interface{}` it will use them to construct the Error struct.
FromReq returns a Request struct from a http request.
NewPost creates a new post by collecting data about the system, such as the current timestamp, os version and architecture, and number of cpus.
Submit sends the error to raygun.
# Variables
Endpoint contains the endpoint of the raygun api.
# Structs
Breadcrumb is a step that the user did in the application.
Client contains the info about the app generating the error.
Context holds information on the program context.
Details contains the info about the circumstances of the error.
Environment contains the info about the machine.
Error contains the info about the actual error.
Post is the full body of a raygun message.
Request holds all information on the request from the context.
Response contains the status code.
StackTraceElement is one element of the error's stack trace.
User holds information on the affected user.
# Type aliases
StackTrace implements the interface to add a new stack element.