feat: add request context support#140
Open
dustinbyrne wants to merge 3 commits intomainfrom
Open
Conversation
fba69fa to
7d3f75f
Compare
7d3f75f to
4d8feea
Compare
dustinbyrne
commented
May 7, 2026
Comment on lines
-253
to
-255
| if ($noDistinctIdProvided) { | ||
| $properties['$process_person_profile'] = false; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
This moved into applyCaptureContext
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Add request-scoped PostHog context helpers so PHP server-side captures, exception events, and feature flag calls can inherit request metadata when framework middleware opts in.
This keeps the SDK framework-neutral while giving Laravel, Symfony, and other integrations a shared core API.
Behavior:
PostHog::withContext()/Client::withContext()wrap a callback with scoped context.Clientand per Fiber, and restored automatically.contextFromHeaders()extracts PostHog frontend tracing headers (X-PostHog-Distinct-Id,X-PostHog-Session-Id).capture()applies contextual distinct ID, session ID, and properties while preserving explicit capture values.$process_person_profile: false; generated IDs are not used for deprecatedsend_feature_flagsevaluation.['fresh' => true].💚 How did you test it?
vendor/bin/phpcs --standard=phpcs.xml lib/RequestContext.php lib/Client.php lib/PostHog.php lib/ExceptionCapture.php test/RequestContextTest.php test/ExceptionCaptureTest.php examples/request-context-laravel-middleware.php examples/request-context-symfony-kernel.phpvendor/bin/phpunit --no-coverage --filter 'RequestContextTest|ExceptionCaptureTest'vendor/bin/phpunit --no-coverage(passes with existing warnings/deprecations)📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file