Oh there is more to it. As confirmed earlier setting active=false
doesn't kill APM Agent threads and calling ElasticApmInstrumentation.tracer.stop()
does so.
Hence if we call the stop method straight after setting active=false
the configuration thread might get killed before it actually sets active=false
. In such scenario It continues to create span and transaction with valid tracing IDs but don't publish data to APM Server as data sending thread is also killed in stop method.
But in this case if we also set ElasticApmInstrumentation.tracer=null
the APM Agents actually shuts down which I believe is complete dettachment
. We dont see anything happening in the APM log and no running threads in JVM. We can see following shut down message in the APM log:
2019-08-08 04:58:22.665 [RMI TCP Connection(13)-10.199.92.86] DEBUG co.elastic.apm.agent.bci.MatcherTimerLifecycleListener - Total time spent matching: 1,356 ,255,300ns | Advice name | Type ns | Method ns | | ApacheHttpAsyncClientInstrumentation | 1,076,625,285 | 0 |
Now if we just set active=false
and don't call the stop method JMS will not create tracing IDs but in the APM log we can still see its intercepting the calls and doing some stuff. I am also using log correction feature and in this case it stamps string of zeros in tracing id. When agent is shut down using first approach the tracing ids are blank.
2019-08-08 05:36:07,368 INFO [jmsContainer-1] [00000000000000000000000000000000] ae.MyClass.shouldContinue:1163 - null,null,null,0,null,null,FFDPSX,null,null,null,
Following is the snippet of the apm.log after setting active=false
2019-08-08 05:36:07.368 [jmsContainer-1] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - decrement references to 'JMS RECEIVE from topic XXX-MY-TOPIC' 00-00000000000000000000000000000000-0000000000000000-00 (75264a27) (1) 2019-08-08 05:36:07.368 [jmsContainer-1] TRACE co.elastic.apm.agent.impl.transaction.AbstractSpan - decrementing references at java.lang.RuntimeException: This is an expected exception. Is just used to record where the reference count has been decremented. at co.elastic.apm.agent.impl.transaction.AbstractSpan.decrementReferences(AbstractSpan.java:260) at co.elastic.apm.agent.impl.transaction.Transaction.decrementReferences(Transaction.java:224) at co.elastic.apm.agent.impl.transaction.AbstractSpan.deactivate(AbstractSpan.java:211) at com.xxx.MySolaceMessageListener.onMessage(MySolaceMessageListener.java:49)
2019-08-08 04:19:33.572 [jmsContainer-1] DEBUG co.elastic.apm.agent.impl.transaction.AbstractSpan - decrement references to 'JMS RECEIVE from topic XXX-MY-TOPIC' 00-00000000000000000000000000000000-0000000000000000-00 (90c4e8f) (0) 2019-08-08 04:19:33.572 [jmsContainer-1] TRACE co.elastic.apm.agent.impl.transaction.AbstractSpan - decrementing references at java.lang.RuntimeException: This is an expected exception. Is just used to record where the reference count has been decremented. at co.elastic.apm.agent.impl.transaction.AbstractSpan.decrementReferences(AbstractSpan.java:260) at co.elastic.apm.agent.impl.transaction.Transaction.decrementReferences(Transaction.java:224) at co.elastic.apm.agent.impl.ElasticApmTracer.endTransaction(ElasticApmTracer.java:393) at co.elastic.apm.agent.impl.transaction.Transaction.doEnd(Transaction.java:161) at co.elastic.apm.agent.impl.transaction.AbstractSpan.end(AbstractSpan.java:184) at co.elastic.apm.agent.impl.transaction.AbstractSpan.end(AbstractSpan.java:175) at com.xxx.MySolaceMessageListener.onMessage(MySolaceMessageListener.java:49)