aeatech/cli-snapshot-profiler-newrelic-bundle
Symfony bundle for profiling CLI commands with New Relic snapshot/transactions. Supports production use, configurable via env vars, and can profile all commands or only selected command names. Requires PHP 8.2+ and the New Relic extension.
Installation:
composer require aeatech/cli-snapshot-profiler-newrelic-bundle
Enable the bundle in config/bundles.php:
AEATech\CLISnapshotProfilerNewrelicBundle\AEATechCLISnapshotProfilerNewrelicBundle::class => ['dev' => true, 'prod' => true],
Configure Environment Variables:
Add these to your .env:
AEA_TECH_CLI_SNAPSHOT_PROFILER_NEWRELIC_APP_NAME="MyCLIApp"
AEA_TECH_CLI_SNAPSHOT_PROFILER_NEWRELIC_LICENSE="your_newrelic_license_key"
Enable Profiling:
Update config/packages/aea_tech_cli_snapshot_profiler_newrelic.yaml:
aea_tech_cli_snapshot_profiler_newrelic:
is_profiling_enabled: true
First Use Case:
Run a CLI command (e.g., php bin/console your:command). New Relic will now profile the execution.
Profiling CLI Commands:
Symfony\Component\Console\Command\Command and are registered as services.Conditional Profiling: Use environment variables or config overrides to toggle profiling dynamically:
# config/packages/dev/aea_tech_cli_snapshot_profiler_newrelic.yaml
aea_tech_cli_snapshot_profiler_newrelic:
is_profiling_enabled: "%kernel.debug%"
Event-Based Profiling: Configure event matching to profile specific CLI invocations (e.g., by command name or arguments):
aea_tech_cli_snapshot_profiler_newrelic:
events:
- command: "your:command"
arguments:
--force: true
Integration with Artisan:
Profile Artisan commands (e.g., migrations, cache clears) by ensuring they are invoked via symfony/console:
php bin/console cache:clear --env=prod
Custom Profiler Extensions:
Extend the bundle’s profiler by implementing AEATech\CLISnapshotProfilerNewrelicBundle\Profiler\ProfilerInterface and binding it as a service.
New Relic Extension Version:
ext-newrelic >= 12.1. Older versions may cause errors or incomplete profiling.php -m | grep newrelic
Environment-Specific Config:
prod may impact performance. Test thoroughly in staging first.%kernel.debug% or environment-specific configs to avoid accidental production profiling.Command Registration:
php your_script.php) require manual instrumentation.License Key Exposure:
AEA_TECH_CLI_SNAPSHOT_PROFILER_NEWRELIC_LICENSE is not committed to version control. Use .env or a secure secrets manager.Profiling Overhead:
Logs: Enable debug mode to log profiler events:
aea_tech_cli_snapshot_profiler_newrelic:
debug: true
Check var/log/dev.log for errors or warnings.
New Relic Dashboard:
aea_tech_cli_snapshot_profiler transaction name.Common Errors:
ext-newrelic is installed and enabled..env and New Relic’s account.Exclude Sensitive Commands: Use event matching to exclude commands with sensitive data:
aea_tech_cli_snapshot_profiler_newrelic:
events:
- exclude: true
command: "user:reset-password"
Custom Metrics: Add custom metrics via New Relic’s API in your command logic:
\NewRelic\Agent::recordCustomMetric('Custom/CLI/YourCommand', 42);
CI/CD Integration: Enable profiling in CI pipelines to catch performance regressions early:
# .github/workflows/ci.yml
env:
AEA_TECH_CLI_SNAPSHOT_PROFILER_NEWRELIC_IS_PROFILING_ENABLED: true
Performance Baselines: Use New Relic’s "Baseline" feature to track CLI performance trends over time.
Bundle Updates:
Monitor for updates to the bundle or ext-newrelic that may require config adjustments.
How can I help you explore Laravel packages today?