raygun4go icon indicating copy to clipboard operation
raygun4go copied to clipboard

Asynchronous calls to raygun, having captured stack traces in the relevant thread

Open laher opened this issue 10 years ago • 0 comments

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.

  • CreatePost and SubmitPost are 2 new methods, to be called on separate goroutines.
  • CreatePost captures the stack trace into a type Post (the stack trace is stored in a private variable, .postData). CreatePost is quick and can be called inline.
  • SubmitPost provides an entry point with which to send the Post.postData. SubmitPost is exposed to internet speed/reliability - SubmitPost should be called from a separate goroutine.
  • Also, CreatePost provides some more control over stack trace truncation. In the example below, 4 represents 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 value 6.

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

laher avatar Oct 26 '15 07:10 laher