Installation:
composer require c24-toys/newrelic-bundle
Add the bundle to config/bundles.php:
return [
// ...
C24Toys\NewRelicBundle\NewRelicBundle::class => ['all' => true],
];
Configuration: Publish the default config:
php bin/console config:dump-reference c24_toys_newrelic
Update config/packages/c24_toys_newrelic.yaml with your New Relic license key:
c24_toys_newrelic:
license_key: 'YOUR_NEW_RELIC_LICENSE_KEY'
transaction_name: 'default' # or 'route', 'controller', or custom
First Use Case:
php bin/console cache:clear) and verify the transaction name matches the command in New Relic.Transaction Naming Strategies:
transaction_name: route in config.transaction_name: controller to name transactions after controller classes (e.g., App\Controller\HomeController).C24Toys\NewRelicBundle\TransactionNamingStrategyInterface and bind it via dependency injection:
services:
App\Service\CustomTransactionNamer:
tags: ['c24_toys_newrelic.transaction_naming_strategy']
Middleware Integration:
use Symfony\Component\HttpKernel\Event\RequestEvent;
use C24Toys\NewRelicBundle\Event\NewRelicEvents;
public function onKernelRequest(RequestEvent $event) {
$transaction = \NewRelic::getTransaction();
$transaction->setCustomAttribute('custom_key', 'value');
}
Register the subscriber in services.yaml:
tags: ['kernel.event_subscriber']
Console Command Enhancements:
use C24Toys\NewRelicBundle\NewRelic\Console\CommandTrait;
class MyCommand extends Command {
use CommandTrait;
protected function execute(InputInterface $input, OutputInterface $output) {
$this->setNewRelicAttribute('command_type', 'custom');
// ...
}
}
Database and External Calls:
\NewRelic\Agent::getTransaction()->addCustomParameter('db_query', 'SELECT * FROM users');
NewRelicEvents::TRANSACTION or NewRelicEvents::ERROR to hook into transaction lifecycle or errors.monolog:
handlers:
newrelic:
type: service
id: c24_toys_newrelic.handler.newrelic
%kernel.environment% to toggle New Relic in dev/staging:
c24_toys_newrelic:
enabled: '%env(bool:NEW_RELIC_ENABLED)%'
License Key Sensitivity:
config/packages/ exposes it. Use environment variables:
license_key: '%env(NEW_RELIC_LICENSE_KEY)%'
php bin/console debug:config c24_toys_newrelic).Transaction Naming Conflicts:
Performance Overhead:
c24_toys_newrelic:
enabled: false # Set to true in production
Console Command Transactions:
ignore_user_abort(true) or split into smaller commands.newrelic.ini file (if manually configured) isn’t conflicting with the bundle.\NewRelic\Agent::getTransaction()->getName() to debug transaction names dynamically.Custom Metrics:
\NewRelic\Agent::recordCustomMetric('Custom/Category', 42);
c24_toys_newrelic.metric_recorder to centralize metric recording.Error Handling:
NewRelicEvents::ERROR:
public function onNewRelicError(NewRelicErrorEvent $event) {
$event->getError()->setCustomAttribute('user_id', $this->getUserId());
}
Async Processing:
\NewRelic\Agent::getApplication()->startTransaction('BackgroundJob', 'Job/ProcessOrder');
try {
// Job logic
} finally {
\NewRelic\Agent::getApplication()->endTransaction();
}
newrelic.ini (not the bundle):
transaction_tracer.transaction_threshold = 0.5
c24_toys_newrelic:
ignored_urls:
- '^/api/doc'
- '^/webhook/'
How can I help you explore Laravel packages today?