raygun4go
raygun4go copied to clipboard
Asynchronous calls to raygun, having captured stack traces in the relevant thread
The point of this small-ish change, is to allow us to call raygun asynchronously. This avoids execution delays, while still retaining the relevant stack trace. We have been using this branch in production for a couple of months now.
CreatePostandSubmitPostare 2 new methods, to be called on separate goroutines.CreatePostcaptures the stack trace into a typePost(the stack trace is stored in a private variable,.postData).CreatePostis quick and can be called inline.SubmitPostprovides an entry point with which to send thePost.postData.SubmitPostis exposed to internet speed/reliability -SubmitPostshould be called from a separate goroutine.- Also,
CreatePostprovides some more control over stack trace truncation. In the example below,4represents the usual number of stack frames to truncate. If you wrap this call inside another function, you may want to vary this parameter - e.g. we typically wrap the call two functions deep, so we use the value6.
Here is how you might use it:
// c is a *raygun4go.Client
post := c.CreatePost(errorToReport, 4)
go func() {
err = c.SubmitPost(post)
if err != nil {
log.Errorf("Error calling raygun: %s", err)
}
}()
Note that I'd normally add in some defer...recover handling, but I've left that out for sake of simplicity.
Existing usage patterns should not be affected by this change. Cheers