-
Notifications
You must be signed in to change notification settings - Fork 28
feat(insights): before_event callback #213
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
Also fix config bleeding issue with asgi test
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.
Pull Request Overview
Adds support for a before_event
callback to allow users to mutate or skip events, and fixes configuration bleeding in ASGI tests.
- Introduce
before_event
option inConfiguration
with default passthrough behavior. - Apply
before_event
logic inHoneybadger.event
to handle in-place mutation, replacement, or explicit rejection. - Add tests for
before_event
behavior and reset global config in ASGI tests to avoid bleed.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
File | Description |
---|---|
honeybadger/config.py | Add before_event to OPTIONS and default. |
honeybadger/core.py | Integrate before_event callback in event . |
honeybadger/tests/test_core.py | New tests for mutated, replaced, and skipped events. |
honeybadger/tests/contrib/test_asgi.py | Reset global config in ASGI event test to avoid bleed. |
@@ -107,6 +107,17 @@ def event(self, event_type=None, data=None, **kwargs): | |||
"The first argument must be either a string or a dictionary" | |||
) | |||
|
|||
if callable(self.config.before_event): |
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.
The event
method docstring should be updated to describe the new before_event
callback behavior: how return values are interpreted (False to skip, None for in-place mutation, a dict to replace).
Copilot uses AI. Check for mistakes.
@@ -22,6 +22,7 @@ class Configuration(object): | |||
# Insights options | |||
("insights_enabled", bool), | |||
# Events options | |||
("before_event", callable), |
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.
[nitpick] Consider using collections.abc.Callable
instead of the built-in callable
for clearer type intent in the OPTIONS
tuple.
Copilot uses AI. Check for mistakes.
This sounds good to me! |
Adds a
before_event
callback with a similar implementation as thebefore_notice
with one small change: This only rejects an event with an explicitFalse
return. If the result isNone
, which is typically no return, then we assume that the user is mutating the payload and use the one passed in. @roelbondoc, what do you think about this tweak?