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
Make airbrake hook non-blocking #157
Conversation
I'm not sure it's the right solution btw. Having a AddAsyncHook is probably better since we leave the decision to the user. |
@@ -25,6 +25,11 @@ func NewHook(endpoint, apiKey, env string) *airbrakeHook { | |||
} | |||
|
|||
func (hook *airbrakeHook) Fire(entry *logrus.Entry) error { | |||
go hook.fire(entry) // Don't block logging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better way to do this is that NewHook
spawns a go routine that reads off a channel, avoiding spawning an unlimited number of goroutines. The channel should be buffered, and if fire()
can't write to it it prints an error like the current one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
I'll update that today.
Thanks
The fire() func is spawned only once and will loop over a buffered channel. The channel size can be set using graylog.BufSize, but the default 1024 should be more than enough. Remember the call to Fire will start to block if the channel is full (airbrake doesn't respond). Please not that tobi/airbrake-go *never* times out on sending the error to airbrake, so I think this is a timebomb. The official github.com/airbrake/gobrake has a default timeout of 10s, which is a lot better I think.
Done! |
Ya, let's switch. |
The api is slightly different: airbrake.ApiKey = hook.APIKey
airbrake.Endpoint = hook.Endpoint
airbrake.Environment = hook.Environment from github.com/airbrake/gobrake airbrake = gobrake.NewNotifier(projectId, apiKey)
airbrake.SetContext("environment", "production") There 2 options:
Any ideas here? |
for the record, tobi's version is also using a old endpoint by default:
whereas gobrake is using:
|
Let's break the API. It's for the better long-term. Please update the README as well 👍 |
Thanks for the insight, will do that today. |
Okkkk, so I just discover gobrake only works with func (n *Notifier) Notify(e interface{}, req *http.Request) error {
notice := n.Notice(e, req, 3)
if err := n.SendNotice(notice); err != nil {
log.Printf("gobrake failed (%s) reporting error: %v", err, e)
return err
}
return nil
} That's lame... So we'll stick to tobi's version, and I'll create a PR in @tobi 's repo to make sure http requests don't stack to death if airbrake api is unreachable. Sorry for the mess. |
Can't you just pass it |
sounds like we can: https://github.com/airbrake/gobrake/blob/master/notice.go#L55 will try that and let you know |
- fixes examples in README.md that incorrectly state usage of RFC3339Nano format instead of RFC3339
I have updated the list to be a table instead. It's much more readable than the previous version, and used in a lot of places (ex: https://github.com/codegangsta/negroni/blob/master/README.md)
There you go! |
The build is failing because of the import path:
But I can ensure they are working:
|
👍 to making the hook non-blocking, I think this is important. I too like the idea of using the official Airbrake client, however that presents a problem in that:
|
I don't have a solution for this. Thanks |
Sure. Whatever is best On Thursday, April 9, 2015, Philippe Lafoucrière notifications@github.com
|
Thanks for the input, I'll propose a pull request then in the coming days. |
@gravis do you have an update on this? |
I'm fighting emergencies currently, and didn't find time to update tobi's version yet :( |
otherwise, notifications (http post request to the API) can stack forever if the server is not responding. see sirupsen/logrus#157 (comment)
@gravis ping :) |
@sirupsen, we're waiting for @tobi to merge: |
I'll send him an email and ask him to add me as contributor. |
On the other hand, internally we don't have any use for a custom endpoints anymore going forward. How about you rebase this and we get it in? |
Also are you interested in taking over maintenance of the Airbrake hook under your personal Github to keep as much as possible out of core? |
Sure. How would you see that? We're merging this, and then we create the new repo? |
Ok, will do that today or tomorrow then. |
We'll close this PR and merge a change that points to your repository in the README :) |
I'm a crappy dependency for software projects these days. Happy to add someone else to that repo so you don't have to wait for me.
(mobile) On Oct 5, 2015, 8:13 AM -0400, Simon Eskildsennotifications@github.com, wrote:
|
@tobi feel free to add me. We may go ahead with something else though. |
Ok, the change has been merged in tobi's repo.
|
Logging should not wait for airbrake to be notified.