check24-cp / newrelic-bundle
Enhanced interaction with NewRelic from within a Symfony environment, ensuring optimal monitoring and logging for your applications
Installs: 4 412
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 4
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.2
- ext-curl: *
- monolog/monolog: ^3.4
- ostrolucky/polyfill-newrelic: ^1.0
- psr/log: ^2.0 || ^3.0
- symfony/console: ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/framework-bundle: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
- symfony/monolog-bundle: ^3.8
- symfony/uid: ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.39
- friendsofphp/php-cs-fixer: ^3.35
- php-http/client-common: ^2.7
- phpstan/phpstan: ^1.10
- phpstan/phpstan-symfony: ^1.3
- phpunit/phpunit: ^10.4
- symfony/messenger: ^5.4 || ^6.0 || ^7.0
- symfony/security-bundle: ^5.4 || ^6.0 || ^7.0
Suggests
- ext-newrelic: Install the New Relic PHP agent on your system
- symfony/security-bundle: Track users impacted by transaction error
README
Introduction
This bundle provides an enhanced interaction with NewRelic from within a Symfony environment, ensuring optimal monitoring and logging for your applications.
Features
- Transactions: Automatically push transactions to New Relic.
- Transaction Naming Strategies: Configurable strategies for both HTTP requests and CLI (eg: messenger).
- Logs: Push logs to NewRelic, linking them together using
traceId
. The bundle also provides batching for optimal performance, configurable via thelogging.buffer_size
. - Transaction Exclusion: Exclude specific transactions based on Symfony route name, path, or even commands.
- Exception Exclusion: Exclude specific exceptions to prevent them from appearing in NewRelic Error inbox, e.g.,
HttpExceptions
.
Installation
To install the CHECK24 New Relic bundle, use composer:
composer require check24-cp/newrelic-bundle
Configuration
After installing the bundle, you need to configure it to suit your application's needs. Here's a detailed explanation of each configuration option based on the provided extension:
Basic Configuration
- appname: The application name. If not set, it defaults to
ini_get('newrelic.appname')
. - license: Your NewRelic license. If not set, defaults to
ini_get('newrelic.license')
. - xmit: A boolean indicating if data should be transmitted to NewRelic immediately, defaults to
false
. - interactor: The service ID of the NewRelic interactor used to communicate with the agent. Defaults to
check24.new_relic.interactor
. - logging.buffer_size: Determines the number of log entries to buffer before sending them to NewRelic in bulk. The range is from 1 to 1000, with a default of 100.
Transaction Naming
- transaction_naming.messenger: Service ID for the strategy used to name messenger transactions. Defaults to
check24.new_relic.transaction_name.messenger.message_name
. - transaction_naming.request: Service ID for the strategy used to name HTTP request transactions. Defaults to
check24.new_relic.transaction_name.request.route_name
.
Exclusions
- excluded_transactions.commands: An array of CLI commands to exclude from NewRelic.
- excluded_transactions.routes: An array of Symfony route names to exclude from NewRelic.
- excluded_transactions.paths: An array of HTTP paths to exclude from NewRelic.
- excluded_exceptions: An array of exception classes to exclude from NewRelic's error inbox.
Trace ID
- trace_id_factory: Service ID for the factory responsible for creating a unique trace ID for each request or message. Defaults to
check24.new_relic.trace_id.uuid_factory
.
Example Configuration using Symfony Yaml
Here's a basic example of how you might configure the bundle using Symfony's yaml:
check24_new_relic: appname: "My Symfony App" license: "YOUR_NEWRELIC_LICENSE_KEY" xmit: false interactor: 'custom.new_relic.interactor' logging: buffer_size: 200 transaction_naming: messenger: 'custom.transaction_name.messenger' request: 'custom.transaction_name.request' excluded_transactions: commands: - 'app:exclude-this-command' routes: - 'exclude_route_name' paths: - '/exclude-this-path' excluded_exceptions: - 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' trace_id_factory: 'custom.trace_id.factory' when@dev: check24_new_relic: # This is useful to be able to get logs about different NewRelic events in Symfony's profiler interactor: 'check24.new_relic.logging_interactor'
Adjust the values as per your requirements. Ensure you replace placeholders like YOUR_NEWRELIC_LICENSE_KEY
with actual values.
Integration with Monolog
One of the standout features of this bundle is the ability to seamlessly integrate logging with NewRelic,
linking them via a trace.id
. This ensures you have all the necessary context when diagnosing issues, as you can see related
logs in NewRelic that correspond to a particular request or process.
It eliminates the disconnect often seen when logs and monitoring are handled separately.
In times of issues or outages, having this cohesive view can be invaluable,
allowing for rapid diagnosis and resolution.
To harness this logging integration, you need to configure your monolog
settings specifically to support the NewRelicHandler
provided by this bundle.
Update your config/packages/monolog.yaml
with the following configuration:
monolog: handlers: main: type: fingers_crossed action_level: error handler: nested excluded_http_codes: - 404 - 405 channels: ['!event'] nested: type: service id: 'check24.new_relic.monolog_handler'
Integration with Messenger
To be able to track messages received with Messenger, you need to update
config/packages/messenger
with the following configuration:
framework: messenger: buses: default: middleware: - check24.new_relic.messenger_middleware
Now the bundle should be able to report each consumed message as a separate transaction, using the message name (see Configuration/Transaction Naming section) as the transaction name.