-
Notifications
You must be signed in to change notification settings - Fork 63
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
Is it possible to have async beforeNotify handler? #981
Comments
Hey @jhulme-ut, thank you for reporting an issue! Let me start by saying that we have considered promise-based beforeNotifyHandlers already in the past, so I understand where you are coming from! We will consider this feature once more and come back with updates. |
So initially I didnt think this was possible. I stared at this for what felt like hours. But im realizing it doesnt have to affect the final boolean returned. That can work as normal. Technically for this particular use-case we just need to make sure all promises have resolved before we build the payload here: honeybadger-js/packages/core/src/client.ts Line 197 in a5fd0e9
So ideally I think if we introduce a Give me a little bit and I'll see if I can whip up a PR. |
Hmm, not sure about this. I remember discussing with @joshuap in the past that the boolean result is an indicator on whether the notice will be sent to Honeybadger. I don't know how much of that boolean flag is used, but if we introduce promise-based Alternatively, @KonnorRogers, it may worth looking into the |
We used to use the boolean approach in the Ruby gem (I forget, it may still work that way as a fall back), but we ended up going with this approach, which might be useful here: Honeybadger.configure do |config|
config.before_notify do |notice|
# Use your own error grouping
notice.fingerprint = App.exception_fingerprint(notice)
# Ignore notices with sensitive data
notice.halt! if notice.error_message =~ /sensitive data/
# Avoid using all your quota for non-production errors by allowing
# only 10 errors to be sent per minute
notice.halt! if !Rails.env.production? && Redis.current.incr(key = "honeybadger_errors:#{(Time.now - Time.now.sec).to_i}") > 10
Redis.current.expire(key, 120)
end
end https://docs.honeybadger.io/lib/ruby/gem-reference/configuration/#changing-notice-data |
@subzero10 So this would be specific to the return value of We could check the return values of all the functions prior to calling Honeybadger.beforeNotify(async () => {
return await getBool()
})
Honeybadger.notify() // => will always return true regardless of getBool, however we could stop the execution of sending to HB. It may be easier to visualize in the form of a PR. it should be quite minimal as well and shouldnt break any existing functionality unless someone is currently returning |
@KonnorRogers I'm not following. Consider this usage:
Currently If we change this behavior and it always returns That's why I suggested we attempt to implement this using the |
@subzero10 So perhaps Im not explaining correctly. It wont always return true. Itll only return true in that case. In this case: Honeybadger.beforeNotify(async () => {
return await getBool()
})
Honeybadger.beforeNotify(() => false)
Honeybadger.notify() // Returns false. Dont send to HB. Will not return The problem with "just getting it to run with notifyAsync" is that notifyAsync hooks directly into |
OK, I get it now! For existing implementations, where For example, a modified version of above:
Are we OK with this behavior? Considering the options, it's a pretty good workaround. Though, it could be confusing. We'd want to document it clearly. |
What are the steps to reproduce this issue?
I would like to be able to do something like:
So that we can call async methods to add data to the notice.
What happens?
Typescript complains because the beforeNotify handler doesn't allow Promises.
What were you expecting to happen?
I would like to be able to use async functions in beforeNotify.
Any logs, error output, etc?
n/a
What versions are you using?
Package Name: honeybadger-js
Package Version: 4.8.0
The text was updated successfully, but these errors were encountered: