Skip to content

feat: add before send callback#162

Merged
marandaneto merged 8 commits into
mainfrom
feat/add-before-send
Jul 6, 2026
Merged

feat: add before send callback#162
marandaneto merged 8 commits into
mainfrom
feat/add-before-send

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

Customers need a configuration hook to inspect, modify, or drop events before upload, matching the before-send behavior available in other PostHog SDKs.

This adds a :before_send config callback. It receives the fully enriched event map after global/system properties, UUID, timestamp, and redaction have been applied. Returning nil drops the event.

💚 How did you test it?

  • mix format --check-formatted
  • mix test test/posthog_test.exs
  • mix posthog.public_api --check

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with the pi coding agent. The callback is applied just before handing the enriched event to the sender, with invalid return values or raised exceptions dropping only that event.

@marandaneto marandaneto self-assigned this Jul 5, 2026
@greptile-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown

Reviews (1): Last reviewed commit: "feat: add before send callback" | Re-trigger Greptile

Comment thread lib/posthog.ex Outdated
Comment thread test/posthog_test.exs
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

posthog-elixir Compliance Report

Date: 2026-07-06 07:11:26 UTC
Duration: 117637ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 610ms
Format Validation.Event Has Uuid 611ms
Format Validation.Event Has Lib Properties 610ms
Format Validation.Distinct Id Is String 610ms
Format Validation.Token Is Present 610ms
Format Validation.Custom Properties Preserved 610ms
Format Validation.Event Has Timestamp 610ms
Retry Behavior.Retries On 503 5611ms
Retry Behavior.Does Not Retry On 400 2613ms
Retry Behavior.Does Not Retry On 401 2611ms
Retry Behavior.Respects Retry After Header 5616ms
Retry Behavior.Implements Backoff 15626ms
Retry Behavior.Retries On 500 5616ms
Retry Behavior.Retries On 502 5616ms
Retry Behavior.Retries On 504 5616ms
Retry Behavior.Max Retries Respected 15625ms
Deduplication.Generates Unique Uuids 620ms
Deduplication.Preserves Uuid On Retry 5615ms
Deduplication.Preserves Uuid And Timestamp On Retry 10615ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5617ms
Deduplication.No Duplicate Events In Batch 617ms
Deduplication.Different Events Have Different Uuids 613ms
Compression.Sends Gzip When Enabled 609ms
Batch Format.Uses Proper Batch Structure 610ms
Batch Format.Flush With No Events Sends Nothing 607ms
Batch Format.Multiple Events Batched Together 615ms
Error Handling.Does Not Retry On 403 2612ms
Error Handling.Does Not Retry On 413 2611ms
Error Handling.Retries On 408 5616ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 610ms
Request Payload.Flags Request Uses V2 Query Param 610ms
Request Payload.Flags Request Hits Flags Path Not Decide 610ms
Request Payload.Flags Request Omits Authorization Header 610ms
Request Payload.Token In Flags Body Matches Init 610ms
Request Payload.Groups Round Trip 609ms
Request Payload.Groups Default To Empty Object 610ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 609ms
Request Payload.Disable Geoip Omitted Defaults To False 610ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 610ms
Request Lifecycle.No Flags Request On Init Alone 4ms
Request Lifecycle.No Flags Request On Normal Capture 610ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 1216ms
Request Lifecycle.Mock Response Value Is Returned To Caller 610ms
Retry Behavior.Retries Flags On 502 913ms
Retry Behavior.Retries Flags On 504 913ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 1213ms

@marandaneto marandaneto marked this pull request as ready for review July 5, 2026 12:30
@marandaneto marandaneto requested a review from a team as a code owner July 5, 2026 12:30
@greptile-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown

Reviews (2): Last reviewed commit: "chore: add before send changeset" | Re-trigger Greptile

@marandaneto

Copy link
Copy Markdown
Member Author

Closes #144

Comment thread lib/posthog.ex

@ioannisj ioannisj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LG, couple of comments to review

Comment thread lib/posthog.ex
@marandaneto marandaneto merged commit a014220 into main Jul 6, 2026
28 checks passed
@marandaneto marandaneto deleted the feat/add-before-send branch July 6, 2026 07:31
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