Add buffering ApplicationStartup variant
As of spring-projects/spring-framework#24878, Spring Framework provides an `ApplicationStartup` infrastructure that applications can use to collect and track events during the application startup phase. This commit adds a new `BufferingApplicationStartup` implementation that buffer `StartupStep`s and tracks their execution time. Once buffered, these steps can be pushed to an external metrics system or drained through a web endpoint, to a file... Closes gh-22603
This commit is contained in:
@@ -443,6 +443,37 @@ This feature could also be useful for any service wrapper implementation.
|
||||
TIP: If you want to know on which HTTP port the application is running, get the property with a key of `local.server.port`.
|
||||
|
||||
|
||||
[[boot-features-application-startup-tracking]]
|
||||
=== Application Startup tracking
|
||||
During the application startup, the `SpringApplication` and the `ApplicationContext` perform many tasks related to the application lifecycle,
|
||||
the beans lifecycle or even processing application events.
|
||||
With {spring-framework-api}/core/metrics/ApplicationStartup.html[ApplicationStartup`], Spring Framework {spring-framework-docs}/core.html#context-functionality-startup[allows you track the application startup sequence with `StartupStep`s].
|
||||
This data can be collected for profiling purposes, or just to have a better understanding of an application startup process.
|
||||
|
||||
You can choose a `ApplicationStartup` implementation when setting up the `SpringApplication` instance.
|
||||
For example, to use the `BufferingApplicationStartup`, you could write:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
public static void main(String[] args) {
|
||||
SpringApplication app = new SpringApplication(MySpringConfiguration.class);
|
||||
app.setApplicationStartup(new BufferingApplicationStartup(2048));
|
||||
app.run(args);
|
||||
}
|
||||
----
|
||||
|
||||
The first available implementation, `FlightRecorderApplicationStartup` is provided by Spring Framework.
|
||||
It adds Spring-specific startup events to a Java Flight Recorder session and is meant for profiling applications and correlating their Spring context lifecycle with JVM events (such as allocations, GCs, class loading...).
|
||||
Once configured, you can record data by running the application with the Flight Recorder enabled:
|
||||
|
||||
[source,bash,indent=0]
|
||||
----
|
||||
$ java -XX:StartFlightRecording:filename=recording.jfr,duration=10s -jar demo.jar
|
||||
----
|
||||
|
||||
Spring Boot ships with the `BufferingApplicationStartup` variant; this implementation is meant for buffering the startup steps and draining them into an external metrics system.
|
||||
Applications can ask for the bean of type `BufferingApplicationStartup` in any component.
|
||||
Additionally, Spring Boot Actuator will <<production-ready-features.adoc#production-ready-endpoints, expose a `startup` endpoint to expose this information as a JSON document>>.
|
||||
|
||||
[[boot-features-external-config]]
|
||||
== Externalized Configuration
|
||||
|
||||
Reference in New Issue
Block a user