How to use APM with php

Hi

After reading the documentation for the PHP APM Agent 3 times, I still don't understand how it works. Initial situation: one has written a web page in PHP and uses for example the monolog handler.

(1) Is the workflow as follows: First you install the agent. Then you have to configure monolog so that all logs are written to the syslogs and then the installed agent reads the syslogs and sends them to APM?

(2) What if you have several websites on one webserver and want to log them separately (e.g. separate log levels)? Do they all have to log to the same syslog file?

(3) How can I send additional information e.g. UserContext (Id, email, ...)?

Many thanks for any help

Hi @tronje85,

Welcome to our community!

You can just install the agent and that is it. I recommend you to try Elastic APM on your PHP application by following setup and configuration steps.

The way Elastic APM PHP agent works has nothing to do with Monolog and/or syslog. The agent can monitor an application regardless whether the application uses or doesn't use Monolog and/or syslog. I'm not sure what made you think that the agent's implementation somehow relies on Monolog and/or syslog (please let us know). Maybe what confused you is the fact that the agent can be configured to write its own logs to syslog. But agent's logs are optional and they are used only for troubleshooting issues with the agent itself. You can completely disable agent's logs and it should not affect its functionality.

If you are really interested in the agent's implementation details you can of course see all them since it's an open source project. The main part of automatic instrumentation relies on PHP Zend engine allowing extensions to overwrite internal functions.

At the moment setting user's details such as ID and email is not implemented but it's in our backlog (issue #597 - Add public API to set user part of transaction context). I'll try to push it closer to the top of the backlog to have it implemented ASAP. You can subscribe to the issue to get notified when it's implemented.

As a workaround I can suggest using agent's public API to set labels. For example:

ElasticApm::getCurrentTransaction()->context()->setLabel('user email', 'myemail@mysite');

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.