Skip to content

feat!: add per-event capture options - #1023

Merged
eli-r-ph merged 1 commit into
v1from
v1-capture-options
Oct 14, 2026
Merged

eli-r-ph merged 1 commit into
v1from
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 reads processing options, such as process_person_profile and cookieless_mode, from a per-event options object. Python callers had no way to set them directly. This PR adds an options argument, as posthog-go and posthog-rs already have. Stacked on #1050.

Changes

  • capture, capture_ai, set, set_once, group_identify, alias and capture_exception take options=, on Client, AsyncPosthog and the module.
  • Options are sent as given; the SDK does not check keys or value types.
  • A non-dict options is logged and the event is sent without it.
  • The legacy $cookieless_mode, $ignore_sent_at, $product_tour_id and $process_person_profile properties still fill their option, and are always removed from properties.
  • An option beats its legacy property, and a None option counts as unset.
  • before_send sees options and can change it.
  • Event uuids accept only the forms the other SDKs accept; any other value is replaced and logged.
  • Minimal $feature_flag_called events keep the properties that carry options, so those options are no longer lost.

Global and context options come next, in #1024.

💚 How did you test it?

  • Wire-builder tests cover legacy properties, option precedence, unknown keys, non-dict options and uuid forms.
  • test_event_options.py checks that options reaches the wire from every method, on both clients, including before_send changes.
  • Reverting each change fails its test.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

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

🤖 Generated with Claude Code

@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-14T03:50:28.472481+00:00
Duration: 246370ms

✅ 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 ✅ 511ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 506ms
Required Headers.Has Authorization Bearer Header ✅ 505ms
Required Headers.Has Content Type Json ✅ 506ms
Required Headers.Has Posthog Sdk Info Format ✅ 505ms
Required Headers.Has Posthog Attempt Header ✅ 506ms
Required Headers.Has Posthog Request Id ✅ 505ms
Required Headers.Has Posthog Request Timestamp ✅ 507ms
Required Headers.Has User Agent ✅ 506ms
Body Format.Body Has Created At And Batch ✅ 506ms
Body Format.No Api Key In Body ✅ 505ms
Body Format.No Sent At In Body ✅ 506ms
Event Format.Event Has Required Root Fields ✅ 505ms
Event Format.Event Uuid Is Valid ✅ 506ms
Event Format.Event Timestamp Is Rfc3339 ✅ 505ms
Event Format.Non Utc Event Timestamp Is Converted To Utc ✅ 509ms
Event Format.Distinct Id Is String ✅ 506ms
Event Format.Distinct Id At Root Not Properties ✅ 505ms
Event Format.Custom Properties Preserved ✅ 507ms
Event Format.Set Properties Preserved ✅ 511ms
Event Format.Set Once Properties Preserved ✅ 505ms
Event Format.Groups Properties Preserved ✅ 505ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 506ms
Event Format.Event Has Required Root Fields Batch ✅ 507ms
Event Format.Event Uuid Is Valid Batch ✅ 508ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 508ms
Event Format.Distinct Id Is String Batch ✅ 508ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 507ms
Event Format.Custom Properties Preserved Batch ✅ 508ms
Event Format.Set Properties Preserved Batch ✅ 507ms
Event Format.Set Once Properties Preserved Batch ✅ 508ms
Event Format.Groups Properties Preserved Batch ✅ 508ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 507ms
Batch Behavior.Multiple Events In Single Batch ✅ 510ms
Batch Behavior.Batch Envelope Smoke ✅ 509ms
Batch Behavior.Flush With No Events Sends Nothing ✅ 503ms
Batch Behavior.Flush At Triggers Batch ✅ 1006ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 506ms
Deduplication.Generates Unique Uuids ✅ 510ms
Deduplication.Different Events Same Content Different Uuids ✅ 507ms
Deduplication.Preserves Uuid On Retry ✅ 6508ms
Deduplication.Preserves Timestamp On Retry ✅ 6513ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 6516ms
Deduplication.No Duplicate Events In Batch ✅ 512ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 506ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 12518ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 6514ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 3011ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 6512ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 506ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 510ms
Response Format Validation.Success No Retry After When All Ok ✅ 508ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 1508ms
Response Format Validation.Success No Retry After When Drop Only ✅ 507ms
Response Format Validation.Response Echoes Request Id ✅ 506ms
Retry Behavior.Retries On 408 ✅ 6512ms
Retry Behavior.Retries On 500 ✅ 6514ms
Retry Behavior.Retries On 503 ✅ 7516ms
Retry Behavior.Retries On 504 ✅ 6513ms
Retry Behavior.Retryable Errors Have Retry After ✅ 3510ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 11510ms
Retry Behavior.Does Not Retry On 400 ✅ 2506ms
Retry Behavior.Does Not Retry On 401 ✅ 2509ms
Retry Behavior.Does Not Retry On 402 ✅ 2506ms
Retry Behavior.Does Not Retry On 413 ✅ 2507ms
Retry Behavior.Does Not Retry On 415 ✅ 2507ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 2509ms
Retry Behavior.Implements Backoff ✅ 18513ms
Retry Behavior.Max Retries Respected ✅ 18524ms
Partial Batch Handling.Handles 200 Full Success ✅ 2507ms
Partial Batch Handling.Handles 200 With All Ok ✅ 3511ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 3510ms
Partial Batch Handling.Does Not Retry Limited Events ✅ 3508ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 6513ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 6514ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 6516ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 6513ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 6513ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 6509ms
Partial Batch Handling.Respects Retry After On Partial ✅ 8515ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 3512ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry ✅ 3512ms
Compression.Sends Gzip Content Encoding ✅ 506ms
Compression.No Content Encoding When Disabled ✅ 505ms
Compression.Compressed Body Is Decompressible ✅ 506ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 2507ms
Event Options.Cookieless Mode Override ✅ 506ms
Event Options.Disable Skew Correction Override ✅ 505ms
Event Options.Process Person Profile Override ✅ 506ms
Event Options.Product Tour Id Override ✅ 505ms
Event Options.Unset Options Omitted ✅ 506ms
Event Options.Options Override In Batch ✅ 508ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties ✅ 505ms
Geoip And Historical Migration.Historical Migration Set In Body ✅ 506ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 505ms

Feature_Flags Tests

✅ 17/17 tests passed

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

Feature_Flags_Local_Evaluation Tests

✅ 4/4 tests passed

View Details
Test Status Duration
Versioned Boolean Matching.Matching Version Missing ✅ 42ms
Versioned Boolean Matching.Matching Version 1 ✅ 41ms
Versioned Boolean Matching.Matching Version 2 ✅ 41ms
Versioned Boolean Matching.Version Only Reload 1 2 1 2 Missing ✅ 21ms

@eli-r-ph

eli-r-ph commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@greptileai review

@eli-r-ph
eli-r-ph marked this pull request as ready for review October 7, 2026 20:43
@eli-r-ph
eli-r-ph requested a review from a team as a code owner October 7, 2026 20:43
Comment thread posthog/async_client.py
uuid: Optional[Union[str, UUID]] = None,
disable_geoip: Optional[bool] = None,
distinct_id: Optional[ID_TYPES] = None,
options: Optional[Dict[str, Any]] = None,

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.

worth using stronger types? e.g.

 class CaptureOptions(TypedDict, total=False):
     cookieless_mode: Optional[bool]
     disable_skew_correction: Optional[bool]
     process_person_profile: Optional[bool]

@eli-r-ph eli-r-ph Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤔 good callout I considered this - as long as no SDK code changes are needed for future options once we define them, the solution does what we want 👍

I rejected TypedDict here so far for two reasons:

  1. the backend does a curated lenient parse on these values for "boolean-intent" that will shore up some current silent fails in legacy capture, that will now apply uniformly across v1 SDKs; with TypedDict, legacy hoisted props would fail hard on non-bool values just on this SDK, or we'd need to dup the backend parsing then keep it in parity w/capture
  2. I think as we add future options to TypedDict that aren't in the schema, mypy and friends might flag end user call sites that apply them with warnings?

If I'm missing something let me know, happy to adjust, but I'm leaning towards keeping this as is for those reasons?

@dustinbyrne
dustinbyrne requested a review from a team October 7, 2026 23:02
@eli-r-ph
eli-r-ph force-pushed the v1-capture-options branch from ea1d279 to 9705c81 Compare October 8, 2026 16:25
@eli-r-ph
eli-r-ph force-pushed the v1-capture-ai-config branch from ba59e9d to 44d141d Compare October 8, 2026 16:25
@eli-r-ph
eli-r-ph requested a review from dustinbyrne October 8, 2026 23:25
@eli-r-ph
eli-r-ph force-pushed the v1-capture-options branch from 9705c81 to 965fbe6 Compare October 8, 2026 23:40
@eli-r-ph
eli-r-ph force-pushed the v1-capture-ai-config branch from 682fd47 to 2e1ba3c Compare October 10, 2026 23:34
@eli-r-ph
eli-r-ph changed the base branch from v1-capture-ai-config to v1 October 10, 2026 23:34
@eli-r-ph
eli-r-ph changed the base branch from v1 to v1-fastmcp-4011-test-fix October 11, 2026 20:17
@eli-r-ph eli-r-ph changed the title feat!: per-event capture options and legacy property hoisting feat!: add per-event capture options Oct 13, 2026
Base automatically changed from v1-fastmcp-4011-test-fix to v1 October 14, 2026 03:42
@eli-r-ph
eli-r-ph merged commit 305e74e into v1 Oct 14, 2026
37 checks passed
@eli-r-ph
eli-r-ph deleted the v1-capture-options branch October 14, 2026 03:46
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