Download the PHP package uzapoint/auditable without Composer
On this page you can find all versions of the php package uzapoint/auditable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download uzapoint/auditable
More information about uzapoint/auditable
Files in uzapoint/auditable
Package auditable
Short Description Distributed audit logging for Laravel microservices via RabbitMQ with OpenTelemetry trace correlation
License MIT
Informations about the package auditable
Uzapoint Auditable
Distributed audit logging for Laravel microservices. The package publishes audit events from each service to RabbitMQ and includes helpers for Eloquent model auditing, manual audit logs, user context resolution, OpenTelemetry trace correlation, and fallback storage when publishing fails.
Requirements
- PHP 8.4 or newer
- Laravel 11, 12, or compatible 13.x release
- RabbitMQ
- Redis if you consume events with
uzapoint/eventbus-coreidempotency enabled - A central audit/log service with a table that can store consumed audit records
Installation
Install the package in every microservice that should publish audit events:
The package depends on uzapoint/eventbus-core, which provides the RabbitMQ publisher and consumer command.
If Laravel package discovery is not available, register the service providers manually in config/app.php:
Configure RabbitMQ
AuditPublisher publishes to the RabbitMQ topic exchange audit.events with the routing key audit.events. The event bus reads RabbitMQ connection values from config('queue.connections.rabbitmq'), so add a RabbitMQ connection to config/queue.php in each publishing service:
Add the matching environment variables:
Configure Auditing
The package merges config/auditable.php by default. To customize config and publish the fallback migration into an application, run:
This publishes:
config/auditable.phpdatabase/migrations/2026_07_15_000001_create_failed_audit_events_table.php
You can also publish each asset type separately:
Set the service identity in .env. These values are added to every published audit payload so the central audit service can identify the source service.
Important config values:
Use events => ['*'] to publish every supported event. Sensitive fields are recursively replaced with ***REDACTED*** inside changes and properties.
Enable Model Auditing
Add the Auditable trait to any Eloquent model that should publish audit events.
The trait publishes:
createdwhen a model is createdupdatedwhen persisted attributes changedeletedwhen a model is deletedrestoredfor models using soft deletesvoidedwhenstatuschanges tovoidedapprovedwhenstatuschanges frompendingtoapprovedorcompletedrejectedwhenstatuschanges frompendingtorejected
Each event includes the subject type, subject id, causer context, old/new changes, service metadata, host, timestamp, optional batch UUID, and current OpenTelemetry trace/span ids.
Manual Audit Logs
Use the facade when you need to audit an action that is not tied directly to an Eloquent lifecycle event:
You can also inject Uzapoint\Auditable\Services\AuditPublisher and call publish(array $payload) directly when you already have the full audit payload.
User Context
UserContextResolver resolves the causer in this order:
- Gateway headers and request input
- Request body values
- Context set for a queued job or consumed message
auth('api')->user()- A system context
For HTTP requests through an API gateway, pass these values when available:
The resolver also reads user_id, person, terminal_id, and terminal_information from the request body.
For queued jobs or message handlers, set the user context before changing audited models:
To pass context into a new message, include:
Batch Correlation
Use BatchContext when a workflow changes several models and you want all audit events to share a single batch id:
The batch UUID is added to meta.batch_uuid on every audit payload published while the context is active.
Fallback Storage
When RabbitMQ publishing fails, the publisher can insert the payload into a local fallback table for retry. Publish the migration and run migrations:
The table defaults to failed_audit_events and stores the JSON payload, failure time, retry time, attempts, processed time, and error text.
Central Audit Service Consumer
In the central audit service, consume the audit.events exchange and route messages to ProcessAuditEvents.
Publish the event bus config:
Configure config/eventbus.php:
Run the consumer:
ProcessAuditEvents inserts records into config('auditable.table', 'activity_logs'). Make sure the central audit service has a compatible activity_logs table or set auditable.table to the table name you want to use.
The expected columns are:
Typical Microservice Setup Checklist
- Install
uzapoint/auditable. - Add the RabbitMQ connection to
config/queue.php. - Set
AUDIT_SERVICE_NAME,AUDIT_SERVICE_ENV, and RabbitMQ environment variables. - Run
php artisan vendor:publish --tag=auditableto publish package config and fallback migration. - Run
php artisan migrateif local failed-publish storage is required. - Add
Uzapoint\Auditable\Traits\Auditableto each model that should publish audit events. - Forward gateway user headers or set
UserContextResolverin queued/message workflows. - Run the central audit service consumer for the
audit.eventsqueue.
Troubleshooting
- If no events reach the audit service, verify RabbitMQ credentials in
config('queue.connections.rabbitmq')and confirm the central service is consumingaudit.events. - If audit records have
source_service=unknown, setAUDIT_SERVICE_NAMEin the publishing service. - If causer fields are empty, forward the gateway headers or set
UserContextResolverbefore updating audited models. - If sensitive data appears in payloads, add the exact field names to
auditable.sensitive_fields. - If consumed events are ignored, confirm
config/eventbus.phpmaps theaudit.eventsrouting key toUzapoint\Auditable\Jobs\ProcessAuditEvents::class.
All versions of auditable with dependencies
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
uzapoint/eventbus-core Version ^1.0
open-telemetry/sdk Version ^1.15
symfony/http-client Version ^8.1
nyholm/psr7 Version ^1.8
open-telemetry/api Version ^1.10