Skip to content

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

Merged
merged 1 commit into from
May 28, 2025

Conversation

rabidpraxis
Copy link
Contributor

Adds a before_event callback with a similar implementation as the before_notice with one small change: This only rejects an event with an explicit False return. If the result is None, 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?

  • Also fix config bleeding issue with asgi test

Also fix config bleeding issue with asgi test
@rabidpraxis rabidpraxis requested review from roelbondoc, a team and Copilot May 23, 2025 18:20
Copy link

@Copilot Copilot AI left a 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 in Configuration with default passthrough behavior.
  • Apply before_event logic in Honeybadger.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):
Copy link
Preview

Copilot AI May 23, 2025

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),
Copy link
Preview

Copilot AI May 23, 2025

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.

@roelbondoc
Copy link
Contributor

Adds a before_event callback with a similar implementation as the before_notice with one small change: This only rejects an event with an explicit False return. If the result is None, 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?

This sounds good to me!

@rabidpraxis rabidpraxis merged commit eadb4fd into insights-instrumentation May 28, 2025
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