Skip to content

feat: add capture options to the request context - #315

Open
eli-r-ph wants to merge 5 commits into
v1from
eli/v1-request-context-options
Open

eli-r-ph wants to merge 5 commits into
v1from
eli/v1-request-context-options

Conversation

@eli-r-ph

@eli-r-ph eli-r-ph commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

RequestContext sets default properties for every event in a request, but not capture options. The other v1 server SDKs let a request context set options too (posthog-python set_context_option, posthog-go RequestContext.Options, posthog-node context options), so a request can, for example, turn on cookieless_mode for all its events.

Changes

  • RequestContext::option(key, value) sets a capture option for every event in the context, including exceptions from exception_options or the scoped context.
  • The context fills an option only when the event leaves it unset: missing or null. An option the event sets wins, as with properties. For exceptions, the last value set for a key decides.
  • PostHogLayer keeps the options of a RequestContext the application puts in the request extensions, as it keeps its identity and properties.
  • A context process_person_profile replaces the false that Event::new_anon sets for a personless event, so the personless default is the lowest layer, as in posthog-python and posthog-go.
  • README, migration guide and a minor changeset describe it; the public API snapshot gains the new method.

💚 How did you test it?

  • test_request_context: the explicit-context test covers a filled option, an event option that wins, and a null event option the context fills; the scoped test checks the option on queued, batch and exception events on the wire. Both fail without the change.
  • A unit test checks exception_options keeps the caller's options and fills only unset ones, including a key set and then cleared with null; it fails without the change.
  • test_tower: an application context option reaches the handler's events; it fails without the change.
  • test_request_context: a context process_person_profile: true reaches a personless event, and an event's own false still wins; it fails without the change.
  • cargo test --all-features (618 passed; 619 with fix!: fill a request context $set key by key and let the context beat flag-event defaults #316) and --no-default-features --features error-tracking,tls (479 passed), cargo clippy --tests -- -D warnings (with and without mcp), cargo fmt -- --check, scripts/check-public-api.sh.

📝 Checklist

  • All commits are signed (see Commit signing)
  • 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

🤖 Generated with Claude Code

eli-r-ph and others added 3 commits October 28, 2026 15:26
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Automated advisory code review.

Comment thread src/request_context.rs
Comment thread src/request_context.rs Outdated
@marandaneto
marandaneto requested a review from a team October 29, 2026 11:42
…xception option

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eli-r-ph
eli-r-ph requested a review from marandaneto October 29, 2026 18:17

@turnipdabeets turnipdabeets 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.

LGTM, the shape matches set_context_option in Python and RequestContext.Options in Go. One non-blocking suggestion inline.

Comment thread src/request_context.rs
…le default

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

3 participants