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

feat: Support modifying events within a callback function #146

Merged
merged 2 commits into from
Nov 9, 2020

Conversation

kattrali
Copy link
Contributor

@kattrali kattrali commented Nov 9, 2020

Goal

Support passing a function to Notify() to allow modification of the complete event, including the stacktrace, on a per-invocation basis.

bugsnag.Notify(err, func(event *bugsnag.Event) {
    event.Context = fmt.Printf("logger: %v", err)
})

Design

Check for a function argument to Notify(), aggregating any found into a list which is called once the error is constructed. Like other arguments to Notify(), subsequent arguments can override previous ones, which is why the callbacks are stored as a collection rather than overriding a single instance.

The StackFrame structure is now public to support checking against or modifying stack frame contents. There's an example in the changelog for a common case: trimming stacktraces for functions routed through a logger or common error delivery point.

Testing

  • Tested manually that callbacks are executed and in order on multiple Go versions (1.8 and 1.15)
  • Added new automated tests for common cases

@kattrali kattrali merged commit 577487c into next Nov 9, 2020
@kattrali kattrali deleted the kattrali/notify-callbacks branch November 9, 2020 16:51
@kattrali kattrali mentioned this pull request Nov 12, 2020
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.

2 participants