Skip to content

Conversation

@alexander-alderman-webb
Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb commented Sep 11, 2025

Some of the event processors in our integrations have a return type of Event when they never return None, while others keep the more general Optional[Event]. Returning Event where possible allows us to see at a glance that the event processors set by the integration cannot drop an event.

Also make use of the EventProcessor in a few more places.

@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner September 11, 2025 07:35
@codecov
Copy link

codecov bot commented Sep 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.57%. Comparing base (94a92d8) to head (9d333e1).
⚠️ Report is 5 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4789      +/-   ##
==========================================
+ Coverage   84.55%   84.57%   +0.02%     
==========================================
  Files         158      158              
  Lines       16479    16479              
  Branches     2855     2855              
==========================================
+ Hits        13933    13937       +4     
+ Misses       1700     1695       -5     
- Partials      846      847       +1     
Files with missing lines Coverage Δ
sentry_sdk/integrations/arq.py 95.04% <ø> (ø)
sentry_sdk/integrations/asgi.py 90.64% <ø> (ø)
sentry_sdk/integrations/aws_lambda.py 29.00% <ø> (ø)
sentry_sdk/integrations/dramatiq.py 83.75% <ø> (ø)
sentry_sdk/integrations/fastapi.py 89.02% <ø> (ø)
sentry_sdk/integrations/gcp.py 0.00% <ø> (ø)
sentry_sdk/integrations/huey.py 97.46% <ø> (ø)
sentry_sdk/integrations/spark/spark_driver.py 66.26% <ø> (ø)
sentry_sdk/integrations/spark/spark_worker.py 82.14% <ø> (ø)
sentry_sdk/integrations/starlette.py 85.02% <ø> (ø)

... and 2 files with indirect coverage changes

Comment on lines 272 to +273
def event_processor(self, event, hint, asgi_scope):
# type: (Event, Hint, Any) -> Optional[Event]
# type: (Event, Hint, Any) -> Event
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method considered public because there's no leading underscore?

Copy link
Contributor

@antonpirker antonpirker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An event processors return type must be Optional[Event] because as how event processors work, you either return an (optionally updated) event or you return None which means the event will be dropped.

@alexander-alderman-webb
Copy link
Contributor Author

Why does an event processor need to return Optional[Event] if there are no code paths where the event is dropped from the specific event processor? Currently in the SDK we have event processors typed like this:

def _make_request_event_processor(req, integration):
# type: (Any, Any) -> Callable[[Event, Dict[str, Any]], Event]
def event_processor(event, hint):
# type: (Event, Dict[str, Any]) -> Event

I'm happy to close the PR if it breaks anything since it's just meant to improve readability.

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