Detach java agent runtime

Hi Team,
I believe provision for detaching java agent from the process without restarting is quite critical. This will be one of the key feature asked during go live. I see that changing the value for "elastic.apm.active" to false dynamically can stop the instrumentation, however the object pools and other threads will remain in the JVM.

One of the option could to call "ElasticApmInstrumentation.tracer.stop()" from JMX or somewhere. Though this stops most of the APM related threads and unloads the instrumentation I still see apm-reporter thread running.

Would this be the right approach to detach the agent?

What's your concern when these are still running?

Setting elastic.apm.active should do what you want and also gives you the possibility to activate the agent again at runtime.

After a timeout of 5s this thread should stop too.

If we just use elastic.apm.active=false, no matter how long we wait threads apm-reporter, apm-request-timeout-timer, configuration-reloader, apm-metrics-reporter will still be running. The only way to stop these threads is using stop method.

Please refer the Other Thread to know why I want all threads to be closed, issue with active flag and what are the actions I am taking to dettach the agent.