We have several web applications based on Spring 4.x(without spring boot) that have a large amount on startup code(init-methods on spring beans and ApplicationListener). Is there a way to have a transaction over the complete startup?
My first idea was to add the CaptureTransaction to the ApplicationListener and init methods but this would create multiple transactions. Does anyone have a better idea?
The Java agent is currently not capable of tracing the startup.
What could work for Spring, at least, is to instrument org.springframework.context.ConfigurableApplicationContext#refresh.
Currently, this is only possible if you add a custom Byte Buddy advice to instrument that method. However, we have plans to make it configurable to instrument arbitrary methods: https://github.com/elastic/apm-agent-java/issues/347
That sounds awesome but I guess it may take a while until it is available, right?
For anyone tumbling over this thread having the same problem, my workaround is:
I subclassed XmlWebApplicationContext with a custom class and overwrote the relevant refresh() method.
This method only calls the base method but can be annotated with @CaptureTransaction.
In web.xml I had to add the context-param contextClass pointing to my custom ApplicationContext.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.