Skip to content

Conversation

@pauldambra
Copy link
Member

we've got this in posthog-js and posthog-ruby
let's add it here

ultimate power to edit/drop/fix events as you see fit

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Adds a before_send callback feature to the Python SDK, enabling event modification or filtering before transmission to PostHog, aligning with existing JS and Ruby SDK implementations.

  • Implements new BeforeSendCallback type in types.py allowing events to be modified or dropped with type-safe handling
  • Adds robust error handling in client.py to maintain original event data if callback fails
  • Includes comprehensive documentation in BEFORE_SEND.md with examples for PII filtering and event transformation
  • Adds thorough test coverage in test_client.py validating event modification, dropping, and error cases

4 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

@pauldambra pauldambra requested a review from a team June 9, 2025 12:34
exception_autocapture_integrations=None,
project_root=None,
privacy_mode=False,
before_send=None,
Copy link
Member Author

Choose a reason for hiding this comment

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

interestingly adding a type to this parameter kicked mypy into being strict about the other parameters and we got ~14 errors

i'm going to punt on that for now since this PR doesn't introduce them

Copy link
Member

@robbie-c robbie-c left a comment

Choose a reason for hiding this comment

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

Aren't you on vacation today?

@pauldambra
Copy link
Member Author

Aren't you on vacation today?

contributing to open source while you're on vacation is totally standard, right?

(will probably cancel day off since I've ended up working 🤣)

@pauldambra pauldambra merged commit 800527d into master Jun 9, 2025
6 checks passed
@pauldambra pauldambra deleted the feat/before_send branch June 9, 2025 12:56
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.

3 participants