blueweb / newrelic-nette
New Relic integration into Nette Framework
Requires
- php: >=7.4
- nette/application: ~3.0
- nette/di: ~3.0
- nette/schema: ~1.0
Requires (Dev)
- dibi/dibi: ^4.2 || ^5.0
- phpstan/phpstan: *
- tracy/tracy: ^2.8
Suggests
- dibi/dibi: Enables the query statistics custom parameters (config option queryStats)
- tracy/tracy: Enables the Tracy panel listing all custom parameters (config option panel)
README
Repository https://github.com/blueweb/newrelic-nette.
Requirements
Library blueweb/newrelic-nette requires PHP 7.4 or higher.
Installation
The best way to install blueweb/newrelic-nette is using Composer:
$ composer require blueweb/newrelic-nette
You have to also add this to your config.neon:
extensions: newrelic: Blueweb\NewRelic\DI\DiExtension
Extension is automatically disabled in development environment. You can also manually enable/disable the extension:
newrelic: enable: false
enable covers transaction naming and error reporting. The features below are
configured independently of it.
Custom parameters
Blueweb\NewRelic\NewRelic is registered as an autowired service and is the
way to put custom parameters on the current transaction:
public function __construct(private NewRelic $newRelic) {} $this->newRelic->addParameter('order.id', $orderId); $this->newRelic->addParameters(['cart.items' => 3, 'cart.total' => 129.9]);
Parameters are sent right away. They are kept in memory as well, so the service
also works without the newrelic extension - nothing is sent, but the values
can still be inspected (see the Tracy panel below).
For values known only at the end of the transaction there is a provider, which
is evaluated in register_shutdown_function(), i.e. while the transaction is
still open:
$this->newRelic->addProvider(fn (): array => ['queue.jobs' => $this->count]);
Query statistics
When dibi/dibi is installed and a Dibi\Connection service exists, queries
are counted automatically and sent as db.queryCount, db.queryTime (ms),
db.select, db.insert, db.update, db.delete, db.transaction,
db.connect and db.other.
newrelic: queryStats: true
Note that listening on Dibi\Connection::$onEvent makes dibi build a
Dibi\Event for every query, including a debug_backtrace() call - a small
but non-zero cost per query. Turn the statistics off with queryStats: false.
Tracy panel
In development a bar panel lists all custom parameters that would be sent to New Relic, together with the information whether the extension is loaded at all. It renders the deferred provider values too.
newrelic: panel: %debugMode%