Installation
composer require check24-cp/newrelic-bundle
Enable the bundle in config/bundles.php:
Check24Cp\NewRelicBundle\NewRelicBundle::class => ['all' => true],
Basic Configuration
Add minimal config to config/packages/check24_cp_newrelic.yaml:
check24_cp_newrelic:
license: 'YOUR_NEWRELIC_LICENSE_KEY'
appname: 'your-app-name'
First Use Case Immediately start monitoring HTTP requests and CLI commands (e.g., Messenger) with default transaction naming. Verify in New Relic UI under "Transactions" and "Logs".
HTTP Request Monitoring
transaction_name_strategy to customize naming:
check24_cp_newrelic:
transaction_name_strategy: 'Check24Cp\NewRelicBundle\TransactionNameStrategy\RouteBasedStrategy'
excluded_routes: ['healthcheck', 'api/v1/health']
CLI/Command Monitoring
@NewRelic\Transaction:
use Check24Cp\NewRelicBundle\Attribute\NewRelicTransaction;
#[NewRelicTransaction('my_command')]
public function __invoke(CommandInterface $command): void
Log Forwarding
logging:
buffer_size: 50 # Default: 10
batch_interval: 1000 # Milliseconds
traceId (auto-injected by the bundle).Exception Handling
HttpException):
excluded_exceptions:
- Symfony\Component\HttpKernel\Exception\HttpException
kernel.request or messenger.message to customize behavior dynamically.NewRelic service directly:
$this->newRelic->recordCustomMetric('custom.metric', 42);
$this->newRelic->setAttribute('user.id', $user->id);
Configuration Overrides
newrelic.ini values. Set xmit: true in config to force immediate transmission (default: false for batching).xmit if relying on newrelic.ini defaults.Transaction Naming Collisions
/api/users vs. api.users).RouteBasedStrategy or implement a custom strategy:
transaction_name_strategy: 'App\Custom\TransactionNameStrategy'
Log Buffering Delays
buffer_size or slow network may delay log visibility.newrelic.log for errors and adjust batch_interval.CLI Transaction Leaks
#[NewRelicTransaction] with explicit names or wrap in try-finally:
$this->newRelic->startTransaction('long_running_task');
try { /* ... */ } finally { $this->newRelic->endTransaction(); }
debug: true # Logs to `var/log/newrelic.log`
NewRelic\Agent::init() failures indicate misconfigured license.excluded_routes/excluded_exceptions are regex-compatible:
excluded_routes: ['^/api/health.*'] # Regex pattern
Custom Transaction Name Strategies
Implement TransactionNameStrategyInterface:
class CustomStrategy implements TransactionNameStrategyInterface {
public function getName(Request $request): string { /* ... */ }
}
Register in config:
transaction_name_strategy: 'App\CustomStrategy'
Log Processor Hooks
Extend LogProcessorInterface to modify logs before sending:
class CustomLogProcessor implements LogProcessorInterface {
public function process(array $log): array { /* ... */ }
}
Bind as a service:
services:
App\CustomLogProcessor:
tags: ['check24_cp_newrelic.log_processor']
Attribute Injection Add custom attributes to transactions dynamically:
$this->newRelic->setAttribute('custom.key', $value);
Useful for correlating logs/metrics with business context (e.g., user.id).
How can I help you explore Laravel packages today?