Install the Bundle
composer require temando/newrelic-bundle
(Note: The composer.json lists temando/newrelic-bundle, but the README references ekino/newrelic-bundle. Use the correct namespace for your project.)
Enable the Bundle
Add to AppKernel.php:
new Temando\Bundle\NewRelicBundle\TemandoNewRelicBundle(),
Configure Basic Settings
# app/config/config.yml
ekino_new_relic:
enabled: true
license_key: "YOUR_NEW_RELIC_LICENSE_KEY" # Required
application_name: "YourAppName"
First Use Case Deploy and check New Relic dashboard to verify transactions (e.g., routes, CLI commands) are being recorded.
Transaction Naming
transaction_naming: route) names transactions after Symfony routes (e.g., homepage).transaction_naming: controller for controller class names (e.g., AppBundle:Post:show).TransactionNamingStrategyInterface for bespoke logic (e.g., naming by user action):
transaction_naming: service
transaction_naming_service: app.newrelic.transaction_namer
// src/AppBundle/Service/NewRelicTransactionNamer.php
class NewRelicTransactionNamer implements TransactionNamingStrategyInterface
{
public function getTransactionName(Request $request) {
return $request->get('action', 'default_transaction');
}
}
Ignoring Transactions
ignored_routes: [admin_dashboard]
ignored_paths: [^/api/health]
ignored_commands: [app:cache:warmup]
CLI Command Monitoring
Enable with log_commands: true to track background jobs (e.g., cron tasks):
php bin/console app:send-email
(Transaction name = command name.)
Deployment Notifications Automate via Capifony or manually:
php bin/console newrelic:notify-deployment --revision="abc123" --description="Hotfix for login bug"
Symfony Cache
Enable using_symfony_cache: true to split ESI transactions (improves granularity):
using_symfony_cache: true
RUM Instrumentation
/editor?_instrument=false
config.yml:
instrument: true
Exception Logging Enable to send errors to New Relic:
log_exceptions: true
Debugging
Use logging: true to log New Relic interactions to Symfony’s log (e.g., app/log/dev.log).
License Key Required
license_key, the bundle logs warnings but won’t send data to New Relic.license_key in config.yml or environment variables.Transaction Naming Conflicts
home for / and /home).controller or a custom strategy for disambiguation.CLI Command Delays
Symfony Cache Overhead
using_symfony_cache: true adds minor performance cost but improves accuracy.RUM Instrumentation Side Effects
instrument: false) removes all browser monitoring._instrument param for dynamic control.Check Logs
Enable logging: true to debug New Relic interactions:
logging: true
(Logs appear in app/log/dev.log or prod.log.)
Verify Transactions
newrelic_set_transaction_name() manually in controllers for edge cases:
use NewRelic\Agent;
Agent::setTransactionName('CustomTransaction');
API Key Permissions
api_key (for deployment notifications) has "Deploy notifications" permissions in New Relic.Environment-Specific Config
Override settings per environment (e.g., config_dev.yml):
# app/config/config_dev.yml
ekino_new_relic:
logging: true
ignored_routes: [admin_dashboard_dev]
Custom Transaction Naming
Extend the bundle by implementing TransactionNamingStrategyInterface:
namespace AppBundle\Service;
use Ekino\Bundle\NewRelicBundle\TransactionNamingStrategy\TransactionNamingStrategyInterface;
use Symfony\Component\HttpFoundation\Request;
class CustomNamer implements TransactionNamingStrategyInterface
{
public function getTransactionName(Request $request) {
return 'Custom:' . $request->get('_route');
}
}
Register as a service:
services:
app.newrelic.transaction_namer:
class: AppBundle\Service\CustomNamer
tags:
- { name: ekino_new_relic.transaction_naming_strategy }
Event Listeners
Hook into New Relic events (e.g., newrelic.transaction):
use Ekino\Bundle\NewRelicBundle\Event\NewRelicEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class NewRelicSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
NewRelicEvents::TRANSACTION => 'onTransaction',
];
}
public function onTransaction(NewRelicTransactionEvent $event)
{
// Modify transaction name/data
}
}
Sonata Admin/Block Integration
sonata_admin config:
sonata_admin:
dashboard:
blocks:
- { type: ekino.newrelic.block.simple, position: right }
{{ sonata_block_render({ 'type': 'ekino.newrelic.block.simple' }, {
'reference': 'YOUR_NEW_RELIC_APP_ID'
}) }}
How can I help you explore Laravel packages today?