Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

laher
Copy link
Contributor

@laher laher commented Oct 26, 2015

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

…sly. 2. control over stack trace truncation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant