Monitor your Laravel application performance with New Relic

Overview

Laravel New Relic

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package 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, and with little to no impact on performance.

New Relic has a fully-featured free plan which is ideal for growing Laravel applications. This package isn't affiliated with them — I just built it because I've found the service very helpful whilst scaling my app, and wanted a more tailored solution for Laravel.

Whilst New Relic can monitor a Laravel application out-of-the-box, this package reports transactions that are optimised for Laravel, and reported in a more consisted way.

Installation

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 before deploying.

If you're installing this on a server which is already being monitored by New Relic, be aware this package reports transactions with different naming conventions than New Relic normally auto-detects. If your existing New Relic data is very important to you, don't install this.

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.

How It Works

The Service Provider

Laravel will auto-discover the LaravelNewRelicServiceProvider class, which binds NewRelicTransactionHandler and NewRelicTransaction classes as scoped singletons to the service container.

New Relic's transaction API only allows a single transaction to be active at a time. 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.

Loggable Environments

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 which would affect New Relic transactions.

Live Environments

Assuming the New Relic extension is loaded, the package sets up hooks into Laravel to monitor requests at different stages of the lifecycle:

  • HTTP transactions are handled with a global NewRelicMiddleware on each request
  • CLI requests are filtered out for noise (so long-running calls like php artisan horizon won't skew your stats).
  • Queued jobs record a transaction automatically as each one starts and ends.
  • Artisan commands are recorded as individual transactions.
  • Scheduled tasks are monitored as each one is executed.

The package also registers a php artisan new-relic:deploy command, to notify New Relic of changes as part of your deployment process.

Configuration

The configuration file is documented in detail — read through each comment to understand how it will affect transaction reporting. A few settings worth pointing out here are below:

HTTP Requests

'http'         => [
    'middleware' => \JackWH\LaravelNewRelic\Middleware\NewRelicMiddleware::class,

    // ...

    'rewrite' => [
        '/livewire/livewire.js'     => 'livewire.js',
        '/livewire/livewire.js.map' => 'livewire.js.map',
    ],

    // ...

    'ignore' => [
        'debugbar.**',
        'horizon.**',
        'telescope.**',
    ],
],

The built-in NewRelicMiddleware class should be fine for most use cases, but you can extend it with your own implementation if needed.

The rewrite key is useful for routes which don't have names defined (often the case with packages that expose public resources, like Livewire). You can rewrite their names for consistency here.

We've set some sensible ignore rules by default, feel free to adjust as required.

Queue Handling

'queue'        => [
    'ignore' => [
        'connections' => ['sync'],
        'queues'      => [],
        'jobs'        => [],
    ],
],

By default the sync connection will be ignored. This means a new job starting on this queue won't interrupt the existing transaction that started at the beginning of the request. You can also filter out specific queues and jobs, too.

Deployments

After each new deployment, you should notify New Relic so they can report on metric variances across multiple releases. The package includes a command to do this:

php artisan new-relic:deploy [description] [revision]

If you don't provide a git revision hash, the package can attempt to auto-detect it by calling git log --pretty="%H" -n1 HEAD


To-Do

  1. Improve the loggable transactions, make it clearer that HTTP transactions will end automatically
  2. Add some tests
  3. Hopefully someone can confirm if this works with Octane?

Contributing

All contributions are welcome! And if you found this useful, I'd love to know.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
Releases(v1.0.2)
  • v1.0.2(Jun 3, 2022)

    What's Changed

    • Fix deploy command by @ksimenic in https://github.com/JackWH/laravel-new-relic/pull/1

    New Contributors

    • @ksimenic made their first contribution in https://github.com/JackWH/laravel-new-relic/pull/1
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(May 21, 2022)

  • v1.0.0(May 21, 2022)

Owner
Jack
Jack
A MCPE server software that backporting new Minecraft: Bedrock Edition to older PocketMine versions with better stability and performance.

CoarseMC is a server software that backports new Minecraft: Bedrock Edition versions to older PocketMine versions with better stability and performance, while retaining as many features from the new PocketMine-MP versions as possible.

null 5 May 21, 2022
Remote or monitor your PocketMine:MP server via browser.

PMRemote Remote or monitor your server via browser. Features Monitor (TPS, Server load, Players count) TODO: Remote (Access server console like RCON,

null 11 Dec 7, 2022
Yab copy to new - A Textpattern plugin. Copies the current article content to a new one.

yab_copy_to_new Displays a new button in article write tab to copy the current article to a new one. Version: 0.2 Table of contents Plugin requirement

Tommy Schmucker 2 Dec 15, 2017
A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch screens with a resolution of 1024x600 connected to a Raspberry Pi.

EDStatusPanel A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch scr

marcus-s 24 Oct 4, 2022
UpDown is an uptime monitor, We send out notifications when something's wrong.

About UpDown Updown is an uptime monitor, We send out notifications when something's wrong. Be the first to know that your website is down! Reliable m

Hussam Adil 4 May 8, 2022
My intention with this app is that new developers can have a concrete application with Laravel + VueJS where they can use it as example to learn the right way

My intention with this app is that new developers can have a concrete application with Laravel + VueJS where they can use it as example to learn the right way, implementing the best practices possible and at the same time learn how TDD is done. So this will be an example application but completely usable for any similar case.

Eng Hasan Hajjar 2 Sep 30, 2022
Track your farming and pool performance on the Binance Smart Chain

farm.army - Frontend Track your farming and pool performance on the Binance Smart Chain. Tech Stack PHP 8 + Symfony node.js + npm (Webpack, Symfony en

farm.army 28 Sep 3, 2022
Your performance & security consultant, an artisan command away.

Enlightn A Laravel Tool To Boost Your App's Performance & Security Introduction Think of Enlightn as your performance and security consultant. Enlight

Enlightn 726 Jan 1, 2023
RMT is a handy tool to help releasing new version of your software

RMT - Release Management Tool RMT is a handy tool to help releasing new versions of your software. You can define the type of version generator you wa

Liip 442 Dec 8, 2022
Quickly and easily preview and test your Magento 2 order confirmation page, without hacks or spending time placing new order each time

Preview Order Confirmation Page for Magento 2 For Magento 2.0.x, 2.1.x, 2.2.x and 2.3.x Styling and testing Magento's order confirmation page can be a

MagePal :: Magento Extensions 71 Aug 12, 2022
Project template for starting your new project based on the Sulu content management system

Sulu is a highly extensible open-source PHP content management system based on the Symfony framework. Sulu is developed to deliver robust multi-lingua

Sulu CMS 188 Dec 28, 2022
Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files.

Class Preloader for PHP This tool is used to generate a single PHP script containing all of the classes required for a specific use case. Using a sing

Class Preloader 356 Nov 26, 2022
Performance fixes for magento 2 core.

magento2-performance-fixes Performance fixes for magento 2 core. Problem and solution's concept - briefly PHP / Magento doesn't support concurency req

Mariusz Łopuch 48 Dec 30, 2022
High-performance, low-memory-footprint, single-file embedded database for key/value storage

LDBA - a fast, pure PHP, key-value database. Information LDBA is a high-performance, low-memory-footprint, single-file embedded database for key/value

Simplito 12 Nov 13, 2022
A plugin to test Server->getPlayerExact() vs Map performance

PeformanceTests A plugin to test Server->getPlayerExact() vs Map<username, Player> performance Timings with Server->getPlayerExact() https://timings.p

KingOfTurkey38 1 Feb 25, 2022
High performance pocketmine 4.0 vote plugin

Voting38 This is a threaded high performance voting plugin for PocketMine-MP API 4.0 You can configure messages and voting rewards in the config. Ther

KingOfTurkey38 7 Jun 1, 2022
A cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services.

Motan Overview Motan is a cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services. Related

Weibo R&D Open Source Projects 5.8k Dec 20, 2022