[PHP] newrelic_name_transaction doesn't work with crons on Docker container

Hello,

I try to rename transactions with newrelic_name_transaction in crons executed in Docker container but it doesn’t work. It looks like the cron is not catched in NewRelic (on Non Web Transactions)
If I execute the cron directly on SSH on Docker it’s work (I see it on Non Web Transactions with the new name). In any case, the function returns always true.
I have the same problem with the newrelic_custom_metric function.

I have this on my Dockerfile :

RUN
curl -L https://download.newrelic.com/php_agent/release/newrelic-php5-9.20.0.310-linux.tar.gz | tar -C /tmp -zx &&
export NR_INSTALL_USE_CP_NOT_LN=1 &&
export NR_INSTALL_SILENT=1 &&
/tmp/newrelic-php5-/newrelic-install install &&
rm -rf /tmp/newrelic-php5-
/tmp/nrinstall* &&
sed -i -e ‘s/“REPLACE_WITH_REAL_KEY”/"[MY KEY]"/’
-e ‘s/newrelic.appname = “PHP Application”/newrelic.appname = “PHP Application”\nnewrelic.attributes.include = request.parameters.*/’
/usr/local/etc/php/conf.d/newrelic.ini

I use this parameters to launch the container :

spec:
restartPolicy: OnFailure
containers:
- name: cron-master
image: [MY IMAGE]
command: ["/bin/sh","-c"]
args:
- gcsfuse --key-file /root/secret/key.json -o allow_other,nonempty,rw --uid 33 --gid 33 goons-catella-prod /var/www/html/web/uploads;
php /var/www/html/bin/console scheduler:execute --env=prod -vvv;
fusermount -u /var/www/html/web/uploads;

It’s the line

php /var/www/html/bin/console scheduler:execute --env=prod -vvv;

that launch crons (it’s the Symfony Bundle jmose/command-scheduler-bundle). When I launch it manually on SSH it’s work.

However, the Agent works perfectly when i go on the website with my browser.

Could you help me please ?

Thanks a lot

Hi @christopher.zucchet1

Welcome to our Explorers Hub!!

I’m wondering if the containers where these crons are executed are short-lived containers?

I mean, you spin up the container to run the PHP command, and the container dies just after the script finishes?

thanks

Rodrigo

Yes it’s this, this is why it doesn’t work ?

There is a solution ?

Thanks

Hi @christopher.zucchet1

Yes, this is an issue that happens to short-lived containers where the daemon process is also running on them.

The issue is, that the PHP Agent reports data through the daemon process at the end of the harvest cycle (Every 1 minute). If the daemon is inside the same container and the container “dies” before the end of this harvest cycle, the daemon doesn’t have the chance of sending this information to New Relic.

There are 2 possible solutions:

  • If you need the daemon process running in the same container, you can try this solution where some time will be added in the execution

  • Also, you can have the daemon running in a separated container and it can be used by multiple other containers just with the PHP Agent

    • Personally, in your use case I’d recommend having a container just with the daemon process running (this container would be running all the time) and all the other containers where the PHP Agent is installed would use this container.
    • You can find more information here.

Let me know if you have any doubts.

thanks :slight_smile:

Rodrigo

1 Like

Hello,

Despite your solution, I have still the same problem.

I have created a container with newrelic daemon image and in my Dockerfile file of the other container, i have changed in newrelic.ini the value of newrelic.daemon.address to newrelic-daemon:31339

Thanks

Hi @christopher.zucchet1

So sorry to hear you are facing the issue still.

Hummm I would also made the same suggestions as @rcorgozinho. Please allow me to loop in some support from the PHP team. They may be able to provide more insight, please note they will reach out via this post.

Please do feel free to reach out with any updates, questions or fixes you have!

Hi @christopher.zucchet1

Let me confirm if I had understood how you configured your environment:

  • You have your short-lived container with the PHP Agent only
  • Also you have a dedicated container just to the daemon process (good)
    • This container is used by the containers with the PHP Agent to send data to New Relic.

Having this, are you seeing the crons from this container reported to New Relic and just the transaction name is not correct?

Or aren’t you seeing the transaction reported at all?

thanks

Rodrigo

Hello,

For the environment, that’s right !

For the crons :

  • if I execute one directly on Docker container, I see it on NewRelic (Unknow or a specific name if I use newrelic_name_transaction) on “Transactions” screen and on “Events” screen if I use newrelic_record_custom_event
  • if I let the container run the cron, I have nothing on both screens (not even Unknow on “Transactions” screen)

However on browser mode, It works !

Thanks

Hi @christopher.zucchet1

Thanks for the information.

Can you send me the logs from the PHP Agent when you let the container run the cron?

Usually, they are written to /var/log/newrelic/php_agent.log so you will need to change the setting newrelic.logfile to stdout or any other place that allows you to get the information after the container finishes. (If it finishes after running the cron)

thanks

Rodrigo

Hello,

I have uploaded two files : one it’s the log that u asked me, the second it’s a screenshot of NewRelic (screen Transactions).

To launch crons, we use a Cron Master Bundle (jmose/command-scheduler-bundle) on a Symfony project. In the log, you will see that it launch the cron app:change-date-facture that contains the command “newrelic_name_transaction(“Cron_ChangeDateFactureCommand”)”

If I launch the Cron Master or app:change-date-facture directly on the container, I have normally on Transactions screen a line with Cron_ChangeDateFactureCommand but not in this case.


log.txt (5.9 KB)

Hey there @christopher.zucchet1,

I hope you are well.

We appreciate you giving us the screenshot and log, the extra information definitely helps. The team is still reviewing this and will provide an update shortly. Thank you for your patience as we continue to provide support. Please let us know if there is any update on your end or if you have further questions. I hope you have a great day!

Hello,

Do you have some news about my problem ?

Thanks

Hey there @christopher.zucchet1 ,

Thanks for reaching out to the New Relic Community! I think I might be able to shed some light on your situation. Have you tried forcing a background job to name/rename the transactions? The docs I’ve included Here should help.

If you have any questions or extra details to add in the meantime, then please don’t hesitate to reach out.

Cheers

Hello,

No it’s not work better…

I would like to have some feedback about files that I have sent (log and screen).

Thanks

Hey @christopher.zucchet1,

Thank you for letting us know that you are still needing assistance. Our support engineers are looking at this further and will provide an update shortly. Please let us know if you have further questions. I hope you have a great day!

Hey there @christopher.zucchet1 ,

Thanks for sending those logs over! I’ve gone through them and unfortunately they don’t uncover much. My suspicions were, in fact, peaked a bit at the fact that there may be a deprecation issue happening at php.INFO.

Cheers

Hello,

Thanks for your reviewing.

It can’t be a problem of PHP because NewRelic works in “Web mode”.

Actually we have 2 Docker containers :

  • one for the Web version
  • one for the crons (configured to be executed every 15 minutes)

And a daemon for the Newrelic Agent (port 31339).

In the Dockerfile, we install the NewRelic agent and modify the newrelic.ini file to change newrelic.daemon.address from /tmp/.newrelic.sock to newrelic-daemon:31339 for both containers.

Maybe the agent need time to be operational when the containers of crons is executed ? You have an example of agent installation with Docker ?

Thanks

Hi @christopher.zucchet1

Could you run your cronjob once more and send us the logs both from the PHP Agent and also from the daemon in the other container?

thanks

Rodrigo

Hello,

Here is logs.

agent.txt (6.1 KB)
daemon.txt (366 Bytes)

Thanks

Hello @christopher.zucchet1,

Thank you for providing those for us. Our support team is reviewing this and will get an update out to you shortly. Please let us know if we can assist with anything else as well!