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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions raygun4go.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,22 @@ func (c *Client) CreateError(message string) error {
return c.submit(post)
}

//Post holds postData (including a stack). This allows for asynchronous reporting to raygun (without losing the stack trace)
type Post struct {
postData postData
}

//CreatePost is a wrapper to manually post errors to raygun. It also allows to specify the index for stack trace truncation.
func (c *Client) CreatePost(err error, stackTruncateAt int) Post {
post := c.createPost(err, currentStackAt(stackTruncateAt))
return Post{postData: post}
}

//SubmitPost is a wrapper to manually post errors to raygun asynchronously (having previously captured a stack trace on a separate goroutine, using c.CreatePost())
func (c *Client) SubmitPost(post Post) error {
return c.submit(post.postData)
}

// submit takes care of actually sending the error to Raygun unless the silent
// option is set.
func (c *Client) submit(post postData) error {
Expand Down
8 changes: 6 additions & 2 deletions request_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ func newErrorData(err error, s stackTrace) errorData {
}
}

// currentStac returns the current stack. However, it omits the first 3 entries
// currentStack returns the current stack. However, it omits the first 4 entries
// to avoid cluttering the trace with raygun4go-specific calls.
func currentStack() stackTrace {
return currentStackAt(4)
}

func currentStackAt(index int) stackTrace {
s := make(stackTrace, 0, 0)
stack2struct.Current(&s)
return s[3:]
return s[index:]
}

// stackTraceElement is one element of the error's stack trace. It is filled by
Expand Down