Collect metrics during application context startup
See original GitHub issueDebugging issues about slow application startup times or even figuring out the sequence of events during the application context startup can be challenging.
This issue is about providing a low-cost, safe and metadata-rich strategy to collect metrics during the application context startup. This should be opt-in only and have little to no cost when disabled.
Collected data and metrics should help to:
- have a better understanding of the application context startup process
- identify problematic infrastructure components (like beans taking a lot of time or resources during
@PostConstruct
processing, creating beans that should have been guarded with conditions, etc).
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Enable Spring Boot Application Startup Metrics to Diagnose ...
A quick guide to enable Spring Boot ApplicationStartup Metrics to monitor in startup actuator endpoint and Java Flight Recorder.
Read more >Tutorial | Metrics and Tracing with Spring
Spring offers the pieces you need to add metrics and tracing to your Spring applications. This tutorial walks through how to create such...
Read more >How Do I Access The Spring Boot Startup Actuator During A Test
One possible way to enable ApplicationStartup data collection during a Spring Boot Test is to create a ContextCustomizer.
Read more >Spring Boot Startup Actuator Endpoint - Baeldung
Tracking the various steps during application startup can provide useful information that can help us to understand the time spent during ...
Read more >Defining custom metrics in a Spring Boot application using ...
For example, if you have a metric that counts the HTTP requests in your application, you can annotate it with the URI the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve been working on this a bit and I’ll try to summarize the current state of affairs here.
Feature description
This feature is about adding a metrics-like abstraction to the Spring application context and instrumenting various infrastructure components in Spring Framework.
We’d like to achieve the following:
Non-goals:
ContextEvent API
By default, the Spring application context will use a “no-op” implementation that won’t record metrics events.
Applications can configure a
ContextEventFactory
on the context directly withorg.springframework.context.ConfigurableApplicationContext#setContextEventFactory
.This
ContextEventFactory
can then be used to create events, add metadata to these events and record them. Here’s an example of instrumentation for the Spring application context (here, scanning base packages):The current state of this change does not ship any implementation (besides the “no-op” version) in Spring Framework directly.
Spring Boot integration
I’ve tested this infrastructure with a couple of implementations in Spring Boot - also taking the opportunity to instrument the lifecycle of Spring Boot applications (specific events, startup phase before the context creation, web server setup, etc).
A first draft implementation is measuring execution time and buffering the events, then exposing them as a startup timeline. Once exported, we can use this data to represent the startup sequence with something like this (here, a quick proof of concept with a JavaScript library):
Another implementation delegates events directly to Java Flight Recorder:
Next steps
If we make good progress on these 3 points, we can consider moving this issue to a 5.3 milestone.
@mdeinum this is the right issue. Right now we’re thinking about providing an extension point for registering an implementation that would receive those events and could delegate to JFR, a library (like Micrometer) or anything custom.
This would be a good start in Framework and we could provide such implementations in Spring Boot. What do you think?