Skip to content

feat!: per-event capture options and legacy property hoisting - #1023

Draft
eli-r-ph wants to merge 1 commit into
v1-capture-ai-configfrom
v1-capture-options
Draft

eli-r-ph wants to merge 1 commit into
v1-capture-ai-configfrom
v1-capture-options

Conversation

@eli-r-ph

@eli-r-ph eli-r-ph commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Capture v1 sends processing options (process_person_profile, cookieless_mode, disable_skew_correction, product_tour_id) in a per-event options object. Until now the SDK only filled it from legacy $ properties, coerced the values, and gave callers no way to set options directly. posthog-go and posthog-rs v1 already take per-event options and send them as given.

New options argument on capture, capture_ai, set, set_once, group_identify, alias and capture_exception, on Client, AsyncPosthog and the module-level functions. For example: posthog.capture("signed_up", distinct_id=..., options={"cookieless_mode": True}).

Behavior changes:

  • Options are sent as given. The SDK checks neither keys nor value types; PostHog validates them. Unknown keys pass through. A value that is not a dict is logged as an error, and the event is sent without it.
  • Legacy properties are no longer coerced. $cookieless_mode, $ignore_sent_at, $product_tour_id and $process_person_profile still fill the matching option, unchanged. Before, "true" became True and an unparseable value was dropped. The property is always removed from properties.
  • An option wins over its legacy property. A null option counts as unset, so the property fills it. This matches go and rs.
  • The legacy properties move into options once, after before_send. That was already the case. before_send now also sees options and can change it.
  • Event uuids accept only the forms other SDKs accept:
    • hyphenated, 32 hex, {...} braced and urn:uuid: in any case; each is canonicalized
    • anything else, such as Python's uuid: prefix or misplaced hyphens, is replaced with a generated uuid and logged
    • this now applies to AsyncPosthog too, which before accepted anything uuid.UUID() parses
  • Minimal $feature_flag_called events keep $cookieless_mode, $ignore_sent_at, $product_tour_id and $window_id. The allowlist runs before the legacy properties move into options, so these were dropped and their options lost. posthog-go has the same fix in feat!: add default and request-context options; event values win over defaults posthog-go#359.

Not in this PR: global and context options, the layer-order change, and the personless option (next PR in the stack), and AI wrappers and MCP moving to options (the one after).

💚 How did you test it?

  • Wire builder:
    • each legacy property fills its option unchanged
    • option vs legacy, with the option set, null or missing
    • unknown options pass through
    • a non-dict is logged and ignored
    • the input is not mutated
    • accepted and rejected uuid forms
  • Clients: new test_event_options.py. It checks that options reaches the wire from every method on Client and AsyncPosthog. A before_send that returns a new event can change options and remove a legacy property. A non-dict options is logged and the event is still sent.
  • Minimal flag events: a gated event with legacy option super properties keeps the options and window_id.
  • Break-on-purpose: each of these was reverted in turn, and the matching test failed every time:
    • the legacy property winning
    • alias dropping options
    • the four allowlist keys
    • lenient uuid parsing
    • async capture dropping options
    • sync and async ignoring the hook's options
  • I ran ruff, mypy (baseline), the strict type smoke, the full pytest suite, the adapter tests, python -W error -c "import posthog", the public API snapshot and uv lock --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

Covered by the existing capture-v1-major changeset; the migration guide lands later in this stack.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Written with Cursor (Claude Opus) under the direction of the assignee.

Agreed before implementation:

  • options pass through unchanged
  • non-dict options logged and ignored
  • only string $session_id/$window_id move to top-level fields
  • hoisting once, after before_send
  • an option wins over its legacy property
  • the uuid forms, matching posthog-go uuid.Validate

Agent calls worth review:

  • the queued message always carries options (maybe {}), so before_send sees the key
  • a null legacy property still fills an unset option as null, as in posthog-rs

@eli-r-ph eli-r-ph self-assigned this Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

posthog-python Compliance Report

Date: 2026-10-07T02:08:45.202684+00:00
Duration: 246900ms

✅ All Tests Passed!

116/116 tests passed


Capture_V1 Tests

✅ 95/95 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 515ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 509ms
Required Headers.Has Authorization Bearer Header ✅ 508ms
Required Headers.Has Content Type Json ✅ 509ms
Required Headers.Has Posthog Sdk Info Format ✅ 509ms
Required Headers.Has Posthog Attempt Header ✅ 508ms
Required Headers.Has Posthog Request Id ✅ 509ms
Required Headers.Has Posthog Request Timestamp ✅ 508ms
Required Headers.Has User Agent ✅ 509ms
Body Format.Body Has Created At And Batch ✅ 510ms
Body Format.No Api Key In Body ✅ 508ms
Body Format.No Sent At In Body ✅ 508ms
Event Format.Event Has Required Root Fields ✅ 509ms
Event Format.Event Uuid Is Valid ✅ 509ms
Event Format.Event Timestamp Is Rfc3339 ✅ 509ms
Event Format.Non Utc Event Timestamp Is Converted To Utc ✅ 513ms
Event Format.Distinct Id Is String ✅ 509ms
Event Format.Distinct Id At Root Not Properties ✅ 508ms
Event Format.Custom Properties Preserved ✅ 509ms
Event Format.Set Properties Preserved ✅ 510ms
Event Format.Set Once Properties Preserved ✅ 508ms
Event Format.Groups Properties Preserved ✅ 511ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 508ms
Event Format.Event Has Required Root Fields Batch ✅ 511ms
Event Format.Event Uuid Is Valid Batch ✅ 511ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 511ms
Event Format.Distinct Id Is String Batch ✅ 512ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 511ms
Event Format.Custom Properties Preserved Batch ✅ 510ms
Event Format.Set Properties Preserved Batch ✅ 512ms
Event Format.Set Once Properties Preserved Batch ✅ 511ms
Event Format.Groups Properties Preserved Batch ✅ 511ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 511ms
Batch Behavior.Multiple Events In Single Batch ✅ 514ms
Batch Behavior.Batch Envelope Smoke ✅ 513ms
Batch Behavior.Flush With No Events Sends Nothing ✅ 505ms
Batch Behavior.Flush At Triggers Batch ✅ 1009ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 509ms
Deduplication.Generates Unique Uuids ✅ 515ms
Deduplication.Different Events Same Content Different Uuids ✅ 510ms
Deduplication.Preserves Uuid On Retry ✅ 6517ms
Deduplication.Preserves Timestamp On Retry ✅ 6518ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 6520ms
Deduplication.No Duplicate Events In Batch ✅ 515ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 509ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 12519ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 6518ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 3017ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 6518ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 510ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 512ms
Response Format Validation.Success No Retry After When All Ok ✅ 510ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 1513ms
Response Format Validation.Success No Retry After When Drop Only ✅ 511ms
Response Format Validation.Response Echoes Request Id ✅ 509ms
Retry Behavior.Retries On 408 ✅ 6517ms
Retry Behavior.Retries On 500 ✅ 6518ms
Retry Behavior.Retries On 503 ✅ 7519ms
Retry Behavior.Retries On 504 ✅ 6518ms
Retry Behavior.Retryable Errors Have Retry After ✅ 3514ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 11522ms
Retry Behavior.Does Not Retry On 400 ✅ 2512ms
Retry Behavior.Does Not Retry On 401 ✅ 2511ms
Retry Behavior.Does Not Retry On 402 ✅ 2512ms
Retry Behavior.Does Not Retry On 413 ✅ 2512ms
Retry Behavior.Does Not Retry On 415 ✅ 2510ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 2512ms
Retry Behavior.Implements Backoff ✅ 18526ms
Retry Behavior.Max Retries Respected ✅ 18526ms
Partial Batch Handling.Handles 200 Full Success ✅ 2510ms
Partial Batch Handling.Handles 200 With All Ok ✅ 3515ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 3512ms
Partial Batch Handling.Does Not Retry Limited Events ✅ 3514ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 6519ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 6515ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 6521ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 6519ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 6515ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 6515ms
Partial Batch Handling.Respects Retry After On Partial ✅ 8517ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 3514ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry ✅ 3514ms
Compression.Sends Gzip Content Encoding ✅ 509ms
Compression.No Content Encoding When Disabled ✅ 508ms
Compression.Compressed Body Is Decompressible ✅ 509ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 2511ms
Event Options.Cookieless Mode Override ✅ 509ms
Event Options.Disable Skew Correction Override ✅ 509ms
Event Options.Process Person Profile Override ✅ 508ms
Event Options.Product Tour Id Override ✅ 508ms
Event Options.Unset Options Omitted ✅ 509ms
Event Options.Options Override In Batch ✅ 511ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties ✅ 508ms
Geoip And Historical Migration.Historical Migration Set In Body ✅ 508ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 509ms

Feature_Flags Tests

✅ 17/17 tests passed

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

Feature_Flags_Local_Evaluation Tests

✅ 4/4 tests passed

View Details
Test Status Duration
Versioned Boolean Matching.Matching Version Missing ✅ 54ms
Versioned Boolean Matching.Matching Version 1 ✅ 60ms
Versioned Boolean Matching.Matching Version 2 ✅ 56ms
Versioned Boolean Matching.Version Only Reload 1 2 1 2 Missing ✅ 27ms

@eli-r-ph eli-r-ph mentioned this pull request Oct 7, 2026
3 of 18 tasks

This branch has not been deployed

No deployments
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.

1 participant