request_audit
request_audit)
Allow collect telemetry data from requests.
Overview
request_audit instruments incoming requests in Drupal and records latency telemetry. It can log request timing data either to Watchdog or to database tables for reporting and chart visualization.
The module provides:
- An admin settings form to enable/disable telemetry and select logging destination.
- A charts page that renders latency over time buckets (via Chart.js).
- An AJAX endpoint that returns bucketed latency series data.
- A “Top 10 slow URLs” table computed from recent aggregated buckets.
Requirements
- Drupal 10 (and core versions compatible with what’s declared in
composer.json) - PHP requirements are inherited from Drupal.
- A database supported by Drupal’s database layer.
Dependencies
In composer.json the module requires:
drupal/core(^10.6 || ^11 || ^12)npm-asset/chart.js(^4.4)
Installation
Install via Composer (recommended for contributed modules):
-
From your Drupal root, require the module package:
composer require drupal/request_audit -
Enable the module:
- Via UI: Extend
- Or with Drush:
drush en request_audit
Run database updates if needed (Drupal will execute the install hook on enable):
drush updb
When enabled, the module’s request_audit.install will create these tables if they do not exist:
- request_audit_rel
- request_audit_latency_agg
Configuration
Go to:
- Configuration → System → Request audit settings
- Route:
/admin/config/system/settings(request_audit.settings)
- Route:
Settings:
- Log activity (
active) - Database
- Log database activity (
database_log) - Log queries list (
save_queries)
- Log database activity (
- Log destination (
log_to)watchdog: logs the payload to Drupal loggerdatabase: stores request timing + aggregated latency in DB
Admin permission
All admin routes require:
administer site configuration
Charts / Reporting
Go to:
- Reports → Request Audit Charts
- Route:
/admin/reports/request-audit-charts(request_audit.request_audit_charts)
- Route:
The page includes:
- A URL pattern control (glob-like, e.g.
/pay2/*) - A time window selector
- An auto-refreshing Chart.js chart
- A “Top 10 slow URLs” section (based on average latency in recent buckets)
AJAX endpoint (data provider)
The chart fetches data from:
/admin/reports/request-audit-charts/block(request_audit.request_audit_charts_block)
Query parameters:
path(optional): exact path matchpattern(optional): glob-like pattern (e.g./pay2/*)windowMinutes(optional, default:180)bucketMinutes(optional, default:5)
If neither path nor pattern is provided, it falls back to a top selection.
Data Model
request_audit_rel (per-request)
Created by request_audit.install and filled when logging to database is enabled.
Stores:
request_id,path,method- timing breakdown in milliseconds:
total_ms,routing_ms,controller_ms,render_ms,untracked_ms
- DB timing breakdown:
db_total_ms,db_select_ms,db_write_ms
timestamp
request_audit_latency_agg (aggregated)
Stores aggregated latency per:
pathbucket_start/bucket_end(UTC buckets)
Fields include:
request_countsum_latency_msavg_latency_mserrors
Bucketing is done in the event subscriber with 5-minute UTC buckets.
Architecture Notes
Core logic lives in:
Drupal\request_audit\EventSubscriber\RequestTimingSubscriber
It subscribes to Kernel events:
REQUEST,CONTROLLER,VIEW,RESPONSE,TERMINATE
Key behaviors:
- Generates a request id from
X-Request-Idor viarandom_bytes(). - When enabled and
database_logis checked, starts Drupal DB query logging usingDatabase::startLog(). - On terminate:
- analyzes logged queries
- stores per-request data into
request_audit_rel - updates aggregated bucket rows in
request_audit_latency_agg
The chart UI JS lives in:
js/request_audit_charts.js
and is declared in:request_audit.libraries.yml
(including Chart.js distribution from the npm asset).
Uninstallation
On module uninstall, request_audit_uninstall() drops:
request_audit_relrequest_audit_latency_agg