Repository navigation
feat: add a runnable Laravel SDK example - #286
Conversation
…avel-package-runtime
This reverts commit 5e92bd8.
|
needs #289 |
Live validation completed successfullyWe exercised the example against a real PostHog test project using synthetic data, then confirmed the ingested events through MCP. The tests below passed. Deliberate exceptions, failed jobs, and injected transport errors were expected test inputs, not unexpected failures. Example application and collectors
Remote and local feature flags
Additional edge cases, tested sequentially
The extended matrix ran against a private source copy with separate dependencies, database, caches, ports, and test-only routes/jobs. Error responses and delays were injected by a loopback recorder forwarding successful requests to real PostHog endpoints. Redis and Octane were actual services, not mocked lifecycle events. PHP was 8.5.10. MCP ingestion verification
Payload comparisons account for timestamp precision, identify/alias normalization, and resolved exception frames. Separate raw-frame source-context storage was not independently retrieved. The fixed-run audit used saved scenario outputs rather than a byte-for-byte outgoing recording. PostHog adds the sender connection IP despite GeoIP enrichment being disabled; this was observed and accounted for. No additional SDK defect was reproduced in the sequential matrix, so no further SDK fix was needed. Temporary services were stopped, the Redis container was removed, and the two uniquely named test flags were disabled. Testing credentials were removed from the private test copy. The normal sample remains running with local-first evaluation configured only in its ignored environment file. No credentials were committed. |
Synced with main after #289
Signed merge
40948d8integratesmainatbc7d741, including the URL-host fix from merged PR #289 and the core 4.20.1 version bump. This PR's diff now contains onlyexamples/laraveland its lint configuration. No core SDK, core regression test, release intent, dependency, or API snapshot changes remain in the diff.Validation after the merge passes: 2,537 core tests / 11,427 assertions, 151 Laravel package tests / 961 assertions, 29 example tests / 163 assertions, and 16 adapter/checker tests. Both public API snapshots, Composer validation, and PHP formatting checks pass. Live validation and MCP ingestion verification are summarized in the PR comment below. No project token or secret is committed.
💡 Motivation and Context
This follows the Pennant integration PR and adds a runnable Laravel 12/13 application under
examples/laravelusing both local Composer packages.The dashboard demonstrates explicit/ambient capture, identify/alias/groups, manual and framework errors, flag variants/payloads/snapshots/unresolved reasons, Pennant reads, auth/header precedence, queue context and overrides, model/domain events, and explicit flush. Artisan and scheduled commands exercise the console paths. Environment toggles enable each optional collector independently.
The baseline needs no npm, external database, queue server or PostHog credentials. It uses SQLite and defaults to disabled telemetry with a blank key. Composer path repositories are development-only. No production package metadata is changed here.
This application is for local development only. Its synthetic login intentionally has no password. It must not be exposed publicly. Browser setup is documented separately, with secret-key and duplicate-pageview warnings.
💚 How did you test it?
after_commit=truebroke the queue tests was rejected: Laravel's testing transaction manager deliberately allows callbacks outside application transactions. Added coverage verifies real application commit/rollback behavior without disabling that setting.📝 Checklist
If releasing new changes
pnpm changeto generate a change intent file. Not applicable: this PR now contains only the example and lint configuration. The core fix was handled separately in fix: normalize URL-style hosts for feature flag requests #289.🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Implemented with Pi, PHP/Composer, Git and GitHub CLI in an isolated worktree. The application exercises public package APIs and uses synthetic data only. CLI tests explicitly enable Symfony event rerouting because Laravel suppresses it during unit tests. The initial implementation used no live PostHog project. Follow-up validation used synthetic events in a development project. Human review is required before merge.
Reviewed commit:
0ce49ab1ed24c6f08f29ab73f551dc1379e0060c. Reviewed base:0377f640e79547ded44cc36b2e38cbbb26c68685. Initial isolated review has no actionable findings.The example CI follow-up uses repository-standard camel-case test names and PHP formatting. Blade templates are excluded from the PHP-only linter, and the conventional Laravel front controller is exempt only from the declarations/side-effects rule. All example tests still execute.
Stack
Merge bottom-up:
Laravel source lives in this repository but its Composer package is released separately. Publish core ^4.20 first. The distribution repository, protected release environment and Packagist setup remain administrator prerequisites. No release has been published.
Review feedback follow-up
Historical review follow-up head:
212980ce70e36e7395709b701c88e4824fb6a5d7.The Pennant form is disabled and server-guarded in POSTHOG_LOCAL_ONLY mode with explicit skipped feedback. A real SDK/mock transport regression verifies zero remote flag requests, while the remote-enabled control still returns boolean and variant values. Latest upstream fixes and internal metadata hooks are integrated.
29 example tests / 163 assertions on Laravel 12 and 13; 106 package tests / 664 assertions in the same clean-source matrix. The local-only request-count regression failed before the guard and passes afterward. Independent scoped review is clean.
The single example review concern is addressed. Local-only means no remote flag fallback; definition fetching and separately enabled analytics collectors are not redefined as offline mode.
Core human-review integration
Signed merges integrate #282 commit
858c204: non-throwing instance group validation (static facade validation unchanged), explicit typed exception source independent of mechanism/handled, provenance protection and scope ownership docs. The core suite passes 2,532 tests / 11,366 assertions. Final committed-source Laravel 12/13 matrices remain green at 106 package tests / 664 assertions and 29 example tests / 163 assertions each. The core delta received a clean isolated review; no automatic Laravel hook-source inference was added.Before the first Laravel release: server SDK registration
posthog-laravelis not yet registered on PostHog server master for PHP usage attribution, Python/Rust feature-flag library classification/parser, or SDK health frontend/backend registries. A separate backend registration/alias PR must land before the Laravel package ships, following the approach in PostHog/posthog#93911. Event ingestion itself is not rejected just because this library identifier is unclassified. SDK health/version handling must respect Laravel's independent package version, not compare0.1.xagainst PHP core4.x. No backend PR, repository or release was created by this SDK follow-up; this remains an explicit pre-release prerequisite alongside core ^4.20 publication and distribution/Packagist setup.