Skip to content

feat(laravel)!: deliver audit events through Queen only (v2.9.0) - #20

Merged
albertovincenzi merged 1 commit into
mainfrom
feat/audit-queen-delivery
Oct 20, 2026
Merged

albertovincenzi merged 1 commit into
mainfrom
feat/audit-queen-delivery

Conversation

@albertovincenzi

@albertovincenzi albertovincenzi commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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, the require_transaction setting and the synchronous HTTP delivery (AuditClient::record(), recordAudit(), TraceFlowSDK::recordAudit()).

  • New 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 throws AuditDeliveryException.
    • One partition per subject (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.
    • Does nothing while TRACEFLOW_ENABLED=false.
  • LogsAudit uses publishAfterCommit; no transaction is required any more.
  • Config traceflow.audit.queen: url (defaults to QUEEN_URL), bearer_token (defaults to QUEEN_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-client is a suggested dependency (it requires PHP 8.3).
  • Version 2.9.0. This is a breaking change against 2.8.0, which was released on 2026-10-19 and is not used by any default branch in the organization (GitHub code search for 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), new AuditPublisherTest (8, including the cooldown) with a fake Queen client; mutation checks: publishing before commit and throwing after commit both fail the tests
  • PHPStan level 5 on src: no error in the changed files (existing errors in transports unchanged); Pint on the changed files
  • tests/audit-installed-framework-smoke.php against cb-backend's installed Laravel 11
  • Local end to end with the real Queen PHP client 2.4.3 and a Queen 2.5.1 broker, read by the Traceflow consumer; with the broker down, publish() fails at once with a retryable error

Release

  • v2.9.0-rc.1 is on Packagist for the cb-backend stage pilot. It was pushed as a tag only to smartpricing/traceflow-laravel, from a local git subtree split --prefix=php/laravel of branch release/laravel-2.9.0-rc.1 (this branch plus the version bump). The tag did not go through split-laravel.yml, because a tag there also force-pushes the split to the split repository's main.
  • After merging, tag v2.9.0 on main as usual. Delete release/laravel-2.9.0-rc.1 afterwards.
  • Stage: cb-backend stage ran 2.9.0-rc.1 with the Smartpay pilot (smartpricing/cb-backend#1597); results in that PR. traceflow-service#46 (consumer) is merged and runs in prod.

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>
@albertovincenzi
albertovincenzi merged commit 5f2b1d4 into main Oct 20, 2026
5 checks passed
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.

1 participant