Drupal integration for Perfbase.
This module is a thin adapter over perfbase/php-sdk. It connects Drupal runtime lifecycles to the Perfbase profiler and ingestion API without implementing its own transport, trace format, or profiler runtime.
This module currently profiles:
- HTTP requests
- Drush and Symfony console commands
- Drupal cron runs
- Core Queue API worker execution
This module does not currently add dedicated support for:
- Messenger workers
- Batch API execution
- Install/update hook specific instrumentation
- Drupal-specific render/entity/cache enrichment beyond what the Perfbase extension already captures
- PHP
>=8.1 <8.6 - Drupal
^10.3 || ^11.0 - Composer
- Perfbase PHP extension installed and enabled
- A valid Perfbase API key
Install the module with Composer:
composer require perfbase/drupalEnable the module:
drush en perfbaseOr enable it through the Drupal admin UI.
The module stores runtime configuration in Drupal config as perfbase.settings.
Configuration is resolved in this order:
- module defaults
- saved Drupal config
settings.phpoverrides
That resolution logic is implemented in src/Config/ConfigResolver.php.
The settings form is available at:
/admin/config/development/perfbase
The form is implemented in src/Form/PerfbaseSettingsForm.php.
At minimum, production installs should set:
enabled: trueapi_key: <your Perfbase API key>
Recommended starting values:
sample_rate: 0.1profile_http: trueprofile_console: falseprofile_cron: trueprofile_queue: truedebug: falselog_errors: true
Use settings.php for deployment-time overrides that should win over saved config:
$settings['perfbase'] = [
'enabled' => TRUE,
'api_key' => 'pb_live_xxxxx',
'api_url' => 'https://ingress.perfbase.cloud',
'sample_rate' => 0.10,
'profile_http' => TRUE,
'profile_console' => FALSE,
'profile_cron' => TRUE,
'profile_queue' => TRUE,
'environment' => 'production',
'app_version' => '2026.04.08',
];| Key | Type | Default | Notes |
|---|---|---|---|
enabled |
bool | false |
Module is effectively disabled until this is true and api_key is non-empty |
debug |
bool | false |
Re-throws profiler exceptions instead of failing open |
log_errors |
bool | true |
Logs profiler/runtime failures when not in debug mode |
api_key |
string | '' |
Required for submission |
api_url |
string | https://ingress.perfbase.cloud |
Override for self-hosted or non-default receiver endpoints |
timeout |
int | 10 |
Submission timeout in seconds |
proxy |
string | '' |
Optional outbound proxy URL |
flags |
int | 8145 |
Passed through to the shared SDK as Perfbase feature flags |
sample_rate |
float | 0.1 |
Value from 0.0 to 1.0 |
profile_http |
bool | true |
Enables HTTP request profiling |
profile_console |
bool | false |
Enables console / Drush profiling |
profile_cron |
bool | true |
Enables cron profiling |
profile_queue |
bool | true |
Enables core Queue API profiling |
environment |
string | '' |
Optional environment label |
app_version |
string | '' |
Optional application version label |
include |
map | * per context |
Include filters for http, console, cron, and queue |
exclude |
map | empty per context | Exclude filters for http, console, cron, and queue |
Default values are defined in config/install/perfbase.settings.yml.
Each supported context has include and exclude filters:
httpconsolecronqueue
Supported filter forms:
*or.*for match-all/regex/expressions- shell-style glob patterns
Example:
include:
http:
- 'GET /admin/*'
console:
- 'cache:*'
cron:
- 'cron.run'
queue:
- 'my_worker'
exclude:
http:
- 'GET /healthz'
console:
- 'list'Matching is implemented in src/Support/FilterMatcher.php.
HTTP profiling is wired through Symfony kernel events:
kernel.requestkernel.responsekernel.exceptionkernel.terminate
Implementation:
Console and Drush command profiling is wired through Symfony console events:
console.commandconsole.errorconsole.terminate
Implementation:
Cron profiling is implemented by decorating Drupal’s cron service and wrapping run().
Implementation:
Queue profiling is implemented by decorating plugin.manager.queue_worker and wrapping worker instances returned by createInstance().
Implementation:
src/Queue/PerfbaseQueueWorkerManagerDecorator.phpsrc/Queue/ProfiledQueueWorker.phpsrc/Lifecycle/QueueItemLifecycle.php
The module keeps span names and action values low-cardinality:
- HTTP uses route-based or normalized request naming
- console uses the command name
- cron uses stable cron action naming
- queue uses the queue worker plugin ID
http_url is recorded without query strings.
Common attributes include:
sourceactionenvironmentapp_versionhostnamephp_version
HTTP requests also attach:
http_methodhttp_urlhttp_status_codeuser_ipuser_agentuser_idwhen availabledrupal.route_namewhen available
Naming logic is implemented in src/Support/SpanNaming.php.
- The module is fail-open in production mode.
- Profiling errors are logged when
log_errorsis enabled. - Debug mode rethrows exceptions so integration issues are visible during development.
- Submission occurs through the shared SDK and uses the installed Perfbase PHP extension.
Shared runtime services:
src/Runtime/PerfbaseFactory.phpsrc/Runtime/ActiveLifecycleRegistry.phpsrc/Support/ErrorHandler.php
- Use
settings.phpfor API keys and deployment-controlled overrides. - Keep
debugdisabled in production. - Start with a conservative
sample_rateand increase as needed. - Exclude health checks, noisy admin paths, or high-volume commands if they are not useful to retain.
- If you use a custom receiver, set
api_urlexplicitly.
Current package validation includes:
- PHPUnit
- PHPStan level 9 with Drupal-aware analysis
- PHPCS with Drupal coding standards
- GitHub Actions coverage for one representative PHP version per supported Drupal line:
- Drupal
10.3on PHP8.1 - Drupal
11.xon PHP8.3
- Drupal
Recent local coverage:
- Lines:
89.04% - Methods:
73.74%
The current suite focuses on unit coverage plus fixture-backed wiring checks. It is not yet a full booted-Drupal kernel test suite.
Install dependencies:
composer installRun the full validation stack:
composer run lintRun individual checks:
composer run test
composer run phpstan
composer run phpcs
XDEBUG_MODE=coverage vendor/bin/phpunit -c phpunit.xml --coverage-textThis package keeps Drupal scaffold output for fixture-based validation under tests/fixtures/drupal/web.
Full documentation is available at perfbase.com/docs.
- Docs: perfbase.com/docs
- Issues: github.com/perfbaseorg/drupal/issues
- Support: support@perfbase.com
Apache-2.0. See LICENSE.txt.