Skip to content

feat: enable data filtering for batches#1245

Open
jaissica12 wants to merge 11 commits intodevelopmentfrom
feat/add-batch-filtering-before-kit-forwarding
Open

feat: enable data filtering for batches#1245
jaissica12 wants to merge 11 commits intodevelopmentfrom
feat/add-batch-filtering-before-kit-forwarding

Conversation

@jaissica12
Copy link
Copy Markdown
Contributor

@jaissica12 jaissica12 commented Apr 9, 2026

Background

  • Kits that implement processBatch receive the full unfiltered batch from the SDK. Unlike individual events (which go through sendEventToForwarders with 5 types of data filtering), batches were forwarded without any filtering applied. This meant kits receiving batches could see events, user attributes, user identities, and event attributes that should have been blocked or stripped based on dashboard-configured filter rules.

What Has Changed

  • Applied the same 5 data filters to sendBatchToForwarders that already exist in sendEventToForwarders: attribute forwarding rules, event name/type filters, event attribute filters, user identity filters, and user attribute filters
  • Extracted shared filter helper functions (isBlockedByForwardingRule, isBlockedByEventFilter, filterEventAttributes, filterUserIdentities) from inline code in sendEventToForwarders so both event and batch paths reuse the same logic
  • Added reverse-mapping functions in sdkToEventsApiConverter.ts (getMessageTypeFromEventType, getEventCategoryFromCustomEventType, getIdentityTypeFromBatchKey, getEventNameFromBatchEvent) to translate batch snake_case fields back to SDK numeric types needed by the filter functions
  • If all events in a batch are filtered out, processBatch is skipped entirely for that forwarder

Screenshots/Video

1 2 3 4 5

Checklist

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have tested this locally.

Additional Notes

  • {Any additional information or context relevant to this PR}

Reference Issue (For employees only. Ignore if you are an outside contributor)

  • Closes NA

@jaissica12 jaissica12 marked this pull request as ready for review April 9, 2026 16:15
@jaissica12 jaissica12 requested a review from a team as a code owner April 9, 2026 16:15
@cursor
Copy link
Copy Markdown

cursor bot commented Apr 9, 2026

PR Summary

Medium Risk
Changes core kit forwarding behavior by filtering/stripping events and user data from processBatch payloads, which can alter what downstream integrations receive. Risk is mitigated by extensive new test coverage, but edge cases in event-type/category mapping could still affect filtering outcomes.

Overview
Batches sent to kits via processBatch now have the same filtering applied as single-event forwarding: attribute-based forwarding rules, event name/type and screen name filters, event-attribute stripping, and user identity/user attribute filtering. If a batch originally contained events but all are filtered out for a given forwarder, processBatch is skipped for that forwarder.

Filtering logic previously inlined in sendEventToForwarders is extracted into a new shared forwarder-utils.ts, and new helpers in types.ts/sdkToEventsApiConverter.ts map batch payload fields back to the SDK’s numeric message/event/identity types to support consistent filtering across event and batch paths. Expanded tests validate batch filtering behavior and parity between single-event and batch forwarding.

Reviewed by Cursor Bugbot for commit 55c561f. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 49e0cc8. Configure here.

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
34.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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