APM Java agent: capture startup

Hello,

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 :slight_smile:

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

Cheers,
Felix

Hi Felix,

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.

Regards,
Wolfram

Hi Wolfram,

depends on you definition of "a while". Here is a PR for just that: https://github.com/elastic/apm-agent-java/pull/398 :slight_smile:

Cheers,
Felix

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