newrelic / newrelic-php-agent

The New Relic PHP Agent
https://opensource.newrelic.com/projects/newrelic/newrelic-php-agent
Apache License 2.0
120 stars 62 forks source link

Add Ignore URL Path Regex? #435

Open mcouillard opened 2 years ago

mcouillard commented 2 years ago

As supported by the Ruby agent, can this agent be enhanced to skip transaction or even metric collection by URL path regex? https://docs.newrelic.com/docs/apm/agents/ruby-agent/api-guides/ignoring-specific-transactions/

We're using Laminas (Zend) for MVC.

ElasticAPM offers this via elastic_apm.transaction_ignore_urls https://www.elastic.co/guide/en/apm/agent/php/master/configuration-reference.html#config-transaction-ignore-urls

Having this allows us to skip certain ping / health checks that happen frequently for internal purposes, like load balancing.

mcouillard commented 2 years ago

Looks like this in-code solution does offer a solution: https://docs.newrelic.com/docs/apm/agents/php-agent/php-agent-api/newrelic_ignore_transaction

But I was really seeking a config option outside of code in order to keep new relic specific logic outside of our codebases.

mmenozzi commented 2 years ago

Yes, moreover when PHP is executed in a PHP-FPM container with an health check configured to hit the PHP-FPM ping.path is not possible to add a newrelic_ignore_transaction() call somewhere because it's PHP-FPM itself who generate the response to the ping request.

Usually the health check is configured to run frequently (for example every 10 seconds) and all those transactions are tracked by NewRelic so, on a low traffic application, is probably the "Most time consuming transaction" (it appears as a transaction named /200).

It would be very useful if we can exclude it with a NewRelic PHP Agent configuration.