Search code examples
phpmonitoringnewrelic

Newrelic: ignore specific part of transaction


For some service we want to see only few parts of every transaction - all except external web services.

I've found newrelic_ignore_apdex and newrelic_ignore_transaction methods here. But calling of this methods will ignore whole transaction not only specific part.

Is there way to completely ignore a part of transaction?

newrelic example


Solution

  • If I understood your needs, it might be more appropriate to use

    newrelic_end_of_transaction ( ) or newrelic_end_transaction ( [ignore] ) to stop th transaction from being recorded at a certain point

    together with newrelic_start_transaction (appname [, license] ) if you need to reopen the transaction later on.

    you find both of them here https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api

    Quoting from NewRelic docs

    newrelic_end_of_transaction ( )

    function newrelic_end_of_transaction (): null
    

    Stop recording the web transaction immediately. Usually used when a page is done with all computation and is about to stream data (file download, audio or video streaming, etc.) and you don't want the time taken to stream to be counted as part of the transaction. This is especially relevant when the time taken to complete the operation is completely outside the bounds of your application. For example, a user on a very slow connection may take a very long time to download even small files, and you wouldn't want that download time to skew the real transaction time.

    on the other hand here is the description of the start function

    newrelic_start_transaction (appname [, license] )

    function newrelic_start_transaction (string $appname, string $license = ini_get('newrelic.license')): bool
    

    If you have ended a transaction before your script terminates (perhaps due to it just having finished a task in a job queue manager) and you want to start a new transaction, use this call. This will perform the same operations that occur when the script was first started. Of the two arguments, only the application name is mandatory. However, if you are processing tasks for multiple accounts, you may also provide a license for the associated account. The license set for this API call will supersede all per-directory and global default licenses configured in INI files. This function will return true if the transaction was successfully started.

    Please note some difference between newrelic_end_transaction ( [ignore] ) and newrelic_end_of_transaction ( )

    Despite being similar in name to newrelic_end_of_transaction above, this call serves a very different purpose. newrelic_end_of_transaction simply marks the end time of the transaction but takes no other action. The transaction is still only sent to the daemon when the PHP engine determines that the script is done executing and is shutting down. This function on the other hand, causes the current transaction to end immediately, and will ship all of the metrics gathered thus far to the daemon unless the ignore parameter is set to true. In effect this call simulates what would happen when PHP terminates the current transaction.

    Know I did a lot of quoting, but the documentation is so explicit that I found useless to say the same things in a different way. Hope this will help