Skip to content

feat: add before send callback#260

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

feat: add before send callback#260
marandaneto merged 5 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 PostHogOptions.BeforeSend, invoked after event enrichment (SDK properties, super properties, $is_server, groups, and feature flags) and before batch serialization. Returning null drops the event.

💚 How did you test it?

  • dotnet test tests/UnitTests/UnitTests.csproj --filter 'FullyQualifiedName~PostHogClientTests.TheCaptureMethod'
  • dotnet build src/PostHog/PostHog.csproj

📝 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 pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with the pi coding agent. The hook runs after the event is fully enriched by moving before-send processing into the batch resolution path, so feature flag enrichment is visible to the callback before serialization. A dropped event is filtered out of the outgoing batch.

@marandaneto marandaneto self-assigned this Jul 5, 2026
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

posthog-dotnet Compliance Report

Date: 2026-07-06 07:06:37 UTC
Duration: 4432ms

✅ All Tests Passed!

17/17 tests passed


Feature_Flags Tests

17/17 tests passed

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

@greptile-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

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

Comment thread tests/UnitTests/PostHogClientTests.cs Outdated
@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
Contributor

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

@ioannisj ioannisj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LG, left a small comment

Comment thread src/PostHog/PostHogClient.cs Outdated
@marandaneto
marandaneto merged commit d543f28 into main Jul 6, 2026
20 checks passed
@marandaneto
marandaneto deleted the feat/add-before-send branch July 6, 2026 07:30
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