Laravel New Relic is a fantastic package that makes it simple to set up and monitor your Laravel application with New Relic APM. New Relic provides some excellent low-level insights into your application. The New Relic PHP agent is particularly useful in production environments, as it hooks in at a lower level than other monitoring services, with little to no impact on performance.
To monitor your application in production you'll need a New Relic API account, and you should install the PHP monitoring agent. You don't need to install New Relic in your development environment (unless you really want to). If the extension isn't detected the package will simulate calls to the New Relic PHP agent, and log each one so you can test it before deploying.
To install the package, add it to your Laravel project with Composer:
composer require jackwh/laravel-new-relic
Then publish the config file:
php artisan vendor:publish --provider="JackWH\LaravelNewRelic\LaravelNewRelicServiceProvider"
That's it, you're done! The package is ready to go, and configured out-of-the-box.
The Service Provider
Laravel will auto-discover the
LaravelNewRelicServiceProvider class, which binds
NewRelicTransaction classes as scoped
singletons to the service container.
New Relic's transaction API only allows a single transaction to be active simultaneously. That's why the classes are loaded as singletons. Generally speaking, don't try to start a new transaction mid-way through the request lifecycle.
The package checks if New Relic is installed. If it's not found, you can log simulated transactions. In a loggable environment, the package will simulate calls it would normally make to New Relic's methods (e.g.
newrelic_start_transaction()). These are loaded from the
LoggableNewRelicFunctions.php helper file. You can check your logs to see what's happening under the hood.
Don't worry if your logs don't show a "transaction ended" item, as New Relic automatically finishes them at the end of a request. This is only really important for long-running processes, like the queue handler. Once you're happy logging is working as expected, you can comment out local in the
config/new-relic.php file. This is just intended to help you check the package is working before initial deployment, or when making changes that would affect New Relic transactions.
Assuming the New Relic extension is loaded, the package sets up hooks into Laravel to monitor requests at different stages of the lifecycle:
NewRelicMiddlewareon each request
php artisan horizonwon't skew your stats).
The package also registers a
php artisan new-relic:deploy command, to notify New Relic of changes as part of your deployment process.
This package has a lot more, For more details, you can visit its complete documentation and source code on Github.
At Codebirsk, we facilitate the development of CRM software, SASS, and eCommerce web applications. Our main aim is to provide a smooth user experience. Our expert team of developers has years of experience in providing thriving web applications across the globe. So You can get in touch with us for any suggestions about the development of tailored and dynamic web applications for your enterprise.
Published at : 10-06-2022
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.