Detach java agent

Kibana version: 7.1.1

Elasticsearch version: 7.1.1

APM Server version: 7.1.1

APM Agent language and version: Java - 1.7.0

Browser version: n/a

Original install method (e.g. download page, yum, deb, from source, etc.) and version:
It`s a test environment on my laptop.
APM-Server, EL and Kibana running via docker-compose
Java-Agent installed by "apm-agent-attach-1.7.0.jar"

Fresh install or upgraded from other version?: Fresh

Is there anything special in your setup? For example, are you using the Logstash or Kafka outputs? Are you using a load balancer in front of the APM Servers? Have you changed index pattern, generated custom templates, changed agent configuration etc.

Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):
The application is a spring-boot sample with one Controller and two post methods.
I attach the agent using "apm-agent-attach-1.7.0.jar'" with the pid.
Everything ok with the attach process.

My Question is: Is it possible to detach the agent from target application without restart it?

Hi and welcome to the forum :wave:

That is currently not possible but we have ideas how to add that in the future. However, you can dynamically set active to false to disable the agent at runtime. Does that work for you?

Hi, thank you!

Yes works for my use case. How can I do that? - by another "attach" with the "active=false" arg?


No, that wouldn't be the way.
Actually, I am not aware of a convenient way to do that...

The way to dynamically change configurations, like active, is through the configuration file, which should be located alongside the agent jar on the same directory. When using the remote attach option, like you do, the attach process puts a temporary agent jar file in a temp folder. If you can locate the temp folder it is placed at (eg echo $TMPDIR in macOS), you can put the configuration file there and do it through there, but of course this will be subject to the temp dir maintenance policy of the OS.

Another hackish option is to add endpoints to your application, like /deactivate and /activate in which you can set the related system property, for example:

System.setProperty("", Boolean.FALSE.toString());

Maybe @felixbarny has a "proper" way of doing that. Otherwise, we should certainly address that.

If you could just switch to using -javaagent instead of the remote attach, that would make things easier.


1 Like

Hi! Thank you for your response.

For the scenarios where we have full control of the application, we can use -javaagent.
But we have some exceptions scenarios (legacy apps of our customers) that we can use only the remote attach option.

Your idea about add endpoints like /deactivate and /activate could be a viable solution, if we can customize the agent injecting a servlet to expose the resources.

What do you think?

No, we don't do that.

What about adding a config option that tells the agent where the properties file is located, then use a constant location for the file? Would that help? This means you still need to access the server and modify the file. How useful is that?
And just out of curiosity- how high would you rank the importance of such switch-off option? Or, in other words- how problematic is restarting the application when you want to stop tracing?

BTW, we are working now on adding a mechanism that will allow configuring the agents through the APM UI. In the first version (of which release is not yet determined) this will only include the transaction_sample_rate, which not exactly what you want, but mostly. I definitely see the ability to turn active to false one that should follow.

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