Refactor event processing pipeline into type-specific handlers#120574
Draft
mwarkentin wants to merge 3 commits into
Draft
Refactor event processing pipeline into type-specific handlers#120574mwarkentin wants to merge 3 commits into
mwarkentin wants to merge 3 commits into
Conversation
Extract three handler functions from the monolithic process_event: _process_transaction_event, _process_feedback_event, _process_error_event. Each handler is self-contained for its event type's pipeline, eliminating footguns where code for one type accidentally affects another (e.g., feedback data being stored in Redis but never consumed or cleaned up). The process_event function now acts as a thin dispatcher: shared pre-processing (deduplication, killswitches, JSON parse) followed by routing to the appropriate handler. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LtwaTTFKxXUAqBUqV79zpw
…uard unknown types The default handler processes errors, security reports (csp, hpkp, expectct, expectstaple, nel), generic events, and default/untyped events — not just errors. Rename to _process_default_event to reflect this. Add an explicit allowlist of known event types for the default pipeline. Unknown types now log an error and emit a metric instead of silently flowing through the error pipeline. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LtwaTTFKxXUAqBUqV79zpw
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LtwaTTFKxXUAqBUqV79zpw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR refactors the
process_eventfunction to improve code organization and maintainability by extracting event type-specific processing logic into dedicated handler functions.Changes
New helper functions:
_lookup_organization(): Fetches and caches the organization on a project, with proper error handling_set_dedup_and_signal(): Handles deduplication cache setting and event_accepted signal emission_process_transaction_event(): Dedicated handler for transaction events_process_feedback_event(): Dedicated handler for feedback events_process_default_event(): Dedicated handler for default pipeline events (error, csp, hpkp, etc.)New constant:
_DEFAULT_PIPELINE_EVENT_TYPES: A frozenset of event types that use the standard preprocess → symbolicate → save pipelineRefactored
process_event()function:Benefits
process_event()function is now a clear dispatcher rather than a monolithic handlerTest Plan
Existing tests should continue to pass as this is a refactoring that preserves all existing behavior. The dispatch logic ensures events are routed to the same handlers as before, just through a cleaner code path.
https://claude.ai/code/session_01LtwaTTFKxXUAqBUqV79zpw