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?
Hi and thanks for another great question
The Java agent is currently not capable of tracing the startup.
What could work for Spring, at least, is to instrument
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.
depends on you definition of "a while". Here is a PR for just that: https://github.com/elastic/apm-agent-java/pull/398
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.