{"id":15027590,"url":"https://github.com/jackwh/laravel-new-relic","last_synced_at":"2025-04-05T05:03:42.769Z","repository":{"id":38440324,"uuid":"494762719","full_name":"jackwh/laravel-new-relic","owner":"jackwh","description":"Monitor your Laravel application performance with New Relic","archived":false,"fork":false,"pushed_at":"2024-07-08T15:14:16.000Z","size":74,"stargazers_count":106,"open_issues_count":4,"forks_count":20,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-05T05:03:32.783Z","etag":null,"topics":["laravel","new-relic","new-relic-apm","new-relic-apm-reporting","performance","performance-monitor","php","php8","php81"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jackwh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-21T11:22:37.000Z","updated_at":"2025-03-12T13:39:17.000Z","dependencies_parsed_at":"2024-10-29T17:37:15.325Z","dependency_job_id":null,"html_url":"https://github.com/jackwh/laravel-new-relic","commit_stats":{"total_commits":19,"total_committers":4,"mean_commits":4.75,"dds":0.4736842105263158,"last_synced_commit":"5bef420c87fd6f70f349112762002f59dbf8e43d"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackwh%2Flaravel-new-relic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackwh%2Flaravel-new-relic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackwh%2Flaravel-new-relic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackwh%2Flaravel-new-relic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jackwh","download_url":"https://codeload.github.com/jackwh/laravel-new-relic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289409,"owners_count":20914464,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","new-relic","new-relic-apm","new-relic-apm-reporting","performance","performance-monitor","php","php8","php81"],"created_at":"2024-09-24T20:06:44.223Z","updated_at":"2025-04-05T05:03:42.746Z","avatar_url":"https://github.com/jackwh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel New Relic\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/jackwh/laravel-new-relic.svg?style=flat-square)](https://packagist.org/packages/jackwh/laravel-new-relic)\n[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/jackwh/laravel-new-relic/run-tests?label=tests)](https://github.com/jackwh/laravel-new-relic/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/jackwh/laravel-new-relic/Check%20\u0026%20fix%20styling?label=code%20style)](https://github.com/jackwh/laravel-new-relic/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/jackwh/laravel-new-relic.svg?style=flat-square)](https://packagist.org/packages/jackwh/laravel-new-relic)\n\n\u003cimg src=\"https://banners.beyondco.de/New%20Relic%20for%20Laravel.png?theme=light\u0026packageManager=composer+require\u0026packageName=jackwh%2Flaravel-new-relic\u0026pattern=circuitBoard\u0026style=style_1\u0026description=New+Relic+performance+monitoring%2C+optimised+for+Laravel+applications.\u0026md=1\u0026showWatermark=1\u0026fontSize=125px\u0026images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg\"/\u003e\n\nThis package makes it simple to set up and monitor your [Laravel](https://laravel.com) application with [New Relic APM](https://newrelic.com/products/application-monitoring).\n\nNew Relic provides some excellent low-level insights into your application. The [New Relic PHP agent](https://docs.newrelic.com/docs/apm/agents/php-agent/getting-started/introduction-new-relic-php/) 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.\n\n\u003e **New Relic has a fully-featured [free plan](https://newrelic.com/pricing)** 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.\n\u003e \n\u003e 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.\n\n## Installation\n\nTo monitor your application in production you'll need a [New Relic](https://newrelic.com) API account, and you should [install the PHP monitoring agent](https://docs.newrelic.com/docs/apm/agents/php-agent/installation/php-agent-installation-overview/). 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.\n\n\u003e 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.\n\nTo install the package, add it to your Laravel project with Composer:\n\n```bash\ncomposer require jackwh/laravel-new-relic\n```\n\nThen publish the config file:\n\n```bash\nphp artisan vendor:publish --provider=\"JackWH\\LaravelNewRelic\\LaravelNewRelicServiceProvider\"\n```\n\n\u003e **That's it, you're done! The package is ready to go, and configured out-of-the-box.**\n\n## How It Works\n\n#### The Service Provider\n\nLaravel will auto-discover the `LaravelNewRelicServiceProvider` class, which binds `NewRelicTransactionHandler` and `NewRelicTransaction` classes as [scoped singletons](https://laravel.com/docs/9.x/container#binding-scoped) to the service container.\n\nNew 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.\n\n#### Loggable Environments\nThe package checks if New Relic is installed. If it's not found, you can log simulated transactions.\n\nIn 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.\n\nDon'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.\n\n\u003e Once you're happy logging is working as expected, you can comment out `local` in the `config/new-relic.php` file.\n\u003e This is just intended to help you check the package is working before initial deployment, or when making changes\n\u003e which would affect New Relic transactions.\n\n#### Live Environments\nAssuming the New Relic extension is loaded, the package sets up hooks into Laravel to monitor requests at different stages of the lifecycle:\n- **HTTP transactions** are handled with a global `NewRelicMiddleware` on each request\n- **CLI requests** are filtered out for noise (so long-running calls like `php artisan horizon` won't skew your stats). \n- **Queued jobs** record a transaction automatically as each one starts and ends.\n- **Artisan commands** are recorded as individual transactions.\n- **Scheduled tasks** are monitored as each one is executed.\n\nThe package also registers a `php artisan new-relic:deploy` command, to notify New Relic of changes as part of your deployment process.\n\n## Configuration\n\nThe [configuration file](config/new-relic.php) 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:\n\n#### HTTP Requests\n```php\n'http'         =\u003e [\n    'middleware' =\u003e \\JackWH\\LaravelNewRelic\\Middleware\\NewRelicMiddleware::class,\n\n    // ...\n\n    'rewrite' =\u003e [\n        '/livewire/livewire.js'     =\u003e 'livewire.js',\n        '/livewire/livewire.js.map' =\u003e 'livewire.js.map',\n    ],\n\n    // ...\n\n    'ignore' =\u003e [\n        'debugbar.**',\n        'horizon.**',\n        'telescope.**',\n    ],\n],\n```\n\nThe built-in `NewRelicMiddleware` class should be fine for most use cases, but you can extend it with your own implementation if needed. \n\nThe `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.\n\nWe've set some sensible `ignore` rules by default, feel free to adjust as required.\n\n#### Queue Handling\n```php\n'queue'        =\u003e [\n    'ignore' =\u003e [\n        'connections' =\u003e ['sync'],\n        'queues'      =\u003e [],\n        'jobs'        =\u003e [],\n    ],\n],\n```\n\nBy 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.\n\n## Deployments\n\nAfter 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:\n\n```php\nphp artisan new-relic:deploy [description] [revision]\n```\n\nIf you don't provide a git revision hash, the package can attempt to auto-detect it by calling `git log --pretty=\"%H\" -n1 HEAD`\n\n---\n\n### To-Do\n\n1. Improve the loggable transactions, make it clearer that HTTP transactions will end automatically\n2. Add some tests\n3. Hopefully someone can confirm if this works with Octane?\n\n### Contributing\n\nAll contributions are welcome! And if you found this useful, I'd love to know.\n\n### Credits\n\n- [Jack Webb-Heller](https://github.com/JackWH)\n- [All Contributors](../../contributors)\n\n### License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackwh%2Flaravel-new-relic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackwh%2Flaravel-new-relic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackwh%2Flaravel-new-relic/lists"}