-
Notifications
You must be signed in to change notification settings - Fork 28
feat: add a notice class and before_notify hook #203
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
Conversation
74ff496
to
07d1cc2
Compare
07d1cc2
to
f1a0295
Compare
f1a0295
to
289cbf8
Compare
The main goal of this PR was to add a `before_notify` hook as part of the configuration. This allows the library to be configured to intercept, inspect, and alter a error notice before it is sent off to Honeybadger. To make this easier, a new `Notice` class has been added so that there is a single object that gets passed into the hook. The payload is generate upon instantiation and can be later inspected or altered in the hook. This preemptive generation isn't ideal because it's a little cumbersome to work with the notice payload. However, the plugins implement the `generate_payload` method which takes in the formatted notice payload. After this, I'd like to take a stab at making it easier to manipulate a notice without having to dig into the final payload.
289cbf8
to
e6b47ee
Compare
I know we are looking for parity with the Ruby client, but what if we switch from side‐effecting halt() to a return‐value API where:
I think it would also simplify things to remove the filtering logic out of the Notice class and into notify() flow, along with the skipping logic of Thoughts? |
I think that makes a lot of sense! Let me refactor and add some tests. |
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.
Looking good! Perhaps we should open another issue for changing the logging to structured 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.
This looks good!
I have one recommendation to move the tags tests from test_core to test_notice.
|
||
logging.getLogger("honeybadger").addHandler(logging.NullHandler()) | ||
logger = logging.getLogger("honeybadger") |
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 believe removing the null handler will attach the logger to the root.
https://github.com/honeybadger-io/honeybadger-python?tab=readme-ov-file#logging
The main goal of this PR was to add a
before_notify
hook as part of the configuration. This allows the library to be configured to intercept, inspect, and alter a error notice before it is sent off to Honeybadger.To make this easier, a new
Notice
class has been added so that there is a single object that gets passed into the hook.The payload is generate upon instantiation and can be later inspected or altered in the hook.This preemptive generation isn't ideal because it's a little cumbersome to work with the notice payload. However, the plugins implement thegenerate_payload
method which takes in the formatted notice payload. After this, I'd like to take a stab at making it easier to manipulate a notice without having to dig into the final payload.The payload is a cached property allowing the
before_notify
hook to alter the payload before sending.The
before_notify
hook must return the notice in order for the notice to be sent. ANone
value will halt the sending.Closes: #187 and #185