Repository navigation
feat(laravel)!: deliver audit events through Queen only (v2.9.0) - #20
Merged
Merged
Conversation
Audit events are pushed to a Queen MQ queue that the Traceflow worker reads. The transactional outbox from 2.8.0 is removed with its migrations, the publish/status/retry commands, the require_transaction setting and the synchronous HTTP delivery. AuditPublisher pushes one partition per subject with the event ID as transaction ID. Inside a transaction the push waits for the commit and a rollback sends nothing; a failure after the write is reported, not thrown. A short timeout and a cooldown after a failure keep an outage from slowing every request. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
Summary
Audit events are delivered only through a Queen MQ queue. The transactional outbox shipped in 2.8.0 is removed: its table, migrations,
traceflow:audit-publish,traceflow:audit-status,traceflow:audit-retry,AuditOutbox, therequire_transactionsetting and the synchronous HTTP delivery (AuditClient::record(),recordAudit(),TraceFlowSDK::recordAudit()).AuditPublisher:publishAfterCommit($event, $connection): inside a transaction the push waits for the outermost commit and a rollback pushes nothing; outside a transaction it pushes right after the write. A failure is reported to the exception handler, never thrown, because the business write has already committed (that event is lost).publish($event): pushes at once and throwsAuditDeliveryException.type:id, hashed above 200 bytes to fit the broker's name budget), the event ID as transaction ID, so a repeated push is stored once.TRACEFLOW_ENABLED=false.LogsAuditusespublishAfterCommit; no transaction is required any more.traceflow.audit.queen:url(defaults toQUEEN_URL),bearer_token(defaults toQUEEN_BEARER_TOKEN),queue(traceflow.audit),timeout_ms(2000),retry_attempts(1),cooldown_seconds(30: after a failed push, the pushes of the next 30 s are skipped and reported, so a Queen outage costs at most one timeout per process and window).queen-mq/php-clientis a suggested dependency (it requires PHP 8.3).LogsAudit,AuditOutbox,traceflow:audit-publish,traceflow_audit_outbox).The Traceflow side is smartpricing/traceflow-service (Queen consumer,
AUDIT_QUEEN_ENABLED).Test plan
vendor/bin/phpunit --testsuite=Unit(149), newAuditPublisherTest(8, including the cooldown) with a fake Queen client; mutation checks: publishing before commit and throwing after commit both fail the testssrc: no error in the changed files (existing errors in transports unchanged); Pint on the changed filestests/audit-installed-framework-smoke.phpagainst cb-backend's installed Laravel 11publish()fails at once with a retryable errorRelease
v2.9.0-rc.1is on Packagist for the cb-backend stage pilot. It was pushed as a tag only to smartpricing/traceflow-laravel, from a localgit subtree split --prefix=php/laravelof branchrelease/laravel-2.9.0-rc.1(this branch plus the version bump). The tag did not go throughsplit-laravel.yml, because a tag there also force-pushes the split to the split repository'smain.v2.9.0onmainas usual. Deleterelease/laravel-2.9.0-rc.1afterwards.2.9.0-rc.1with the Smartpay pilot (smartpricing/cb-backend#1597); results in that PR. traceflow-service#46 (consumer) is merged and runs in prod.