Spring Boot: configuring the Actuator “info” endpoint

Actuator is a software module you can add to any Spring Boot project to expose many features for monitoring and managing the application. This article describes how to use and configure one of the essential features of Actuator, the “info” endpoint.

A brief introduction to Actuator

Actuator adds handy features, especially for “production” environments, to get a wide range of information, statistics, and metrics about the running application.

The first important thing to know about Actuator is that it is not normally included in a Spring Boot application by default. If you want to integrate Actuator into your project, using the spring-boot-starter-actuator “starter” dependency is the simple and recommended way.

For Maven projects, you have to add the following dependency:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

For Gradle projects, you must add the equivalent descriptor in either Groovy or Kotlin DSL.

Once Actuator is integrated into a project, it can expose a set of additional endpoints using two different technologies: HTTP and JMX. JMX is the Java Management Extensions, a Java technology that allows applications to expose properties and operations using a specific network protocol. You can read more on Wikipedia: https://en.wikipedia.org/wiki/Java_Management_Extensions

Beware that not all endpoints are by default exposed on both HTTP and JMX because several endpoints may disclose “sensitive” information. In general, you should be very careful about which endpoints you want to expose, depending on the application environment (e.g., “development”, “production”, etc.).

This article mainly focuses on accessing Actuator through HTTP because it is the simplest and most immediate way.

The “info” endpoint

The info endpoint is one of the essential features of Spring Boot Actuator. This endpoint is very helpful for getting some basic (and typically “static”) information about the application, like Operating System information, Java information, and so on.

Based on the Spring Boot version, the info HTTP endpoint may or may not be exposed by default. It is exposed by default on all Spring Boot versions up to 2.4.x. However, starting from Spring Boot 2.5.0, it is no longer exposed by default. This critical change is described in the Spring Boot 2.5 Release Notes, section “Secure Info Endpoint”.

In this article, I suppose you are using a recent version of Spring Boot (version 2.5.0 or higher, preferably 2.7.x or 3.x). Thus, you must manually configure the exposure of the info endpoint over HTTP using the management.endpoints.web.exposure.include configuration property. This property lists the IDs of the endpoints that Actuator exposes over the web (HTTP).

For example:

In application.properties (or YAML equivalent):

management.endpoints.web.exposure.include = health, info

Note that the health endpoint is already exposed by default, but with the above line, it remains exposed. This include property is not additive!

There are other properties described in the Spring Boot reference: Exposing Endpoints. However, for this article, it’s just sufficient to use the “web” include property to expose the info endpoint over HTTP.

Requesting the info endpoint

When the info endpoint is exposed over HTTP, it responds to the path /actuator/info. If you perform a GET request to this endpoint with no other specific configuration, you should obtain an “empty” JSON object in response like the following:

$> curl http://localhost:8080/actuator/info -i -X GET
HTTP/1.1 200
Content-Type: application/vnd.spring-boot.actuator.v3+json
Transfer-Encoding: chunked
Date: Sun, 05 Mar 2023 17:07:21 GMT

{}

The above response is normal and should not alarm or surprise you. All information this endpoint exposes is produced by one or more implementations of the InfoContributor interface. Spring Boot Actuator already provides some predefined implementations of this interface, and you can also implement your custom “info contributor”. I will describe this latter case in a forthcoming article.

In general, if you see an empty {} JSON object from the info HTTP endpoint, it is because there are no “active” contributions to this endpoint. In the following subsections, we will see how to activate one or more of the predefined contributors provided by Spring Boot Actuator.

The build info contributor

The BuildInfoContributor is a predefined InfoContributor implementation available since Spring Boot 1.4.0. This contributor provides information about the application build performed by Maven/Gradle. This contributor is generally enabled by default. However, you must apply an extra setup to see some concrete values.

Indeed, this contributor relies on the presence of the META-INF/build-info.properties file. This file is usually not automatically generated. You can use either Maven or Gradle to create this file during the build phase. The Spring Boot reference documentation contains all the necessary information in the section Generate Build Information.

Once you have applied this extra setup, the META-INF/build-info.properties file will be created/updated on each build. At this point, if you request the info HTTP endpoint, you should see a "build" key in the main JSON object like the following:

{
    "build": {
        "artifact": "your-artifact",
        "name": "artifact name",
        "time": "2023-02-19T14:58:55.322Z",
        "version": "1.2.3",
        "group": "your.group"
    }
}

Final note: you can entirely disable the BuildInfoContributor using the following configuration property:

In application.properties (or YAML equivalent):

management.info.build.enabled = false

The environment info contributor

The EnvironmentInfoContributor is a predefined InfoContributor implementation available since Spring Boot 1.4.0, and it is disabled by default. You can enable this contributor using the following configuration property:

In application.properties (or YAML equivalent):

management.info.env.enabled = true

This contributor is a bit particular and different from the other predefined contributors because its sole purpose is to gather information from all Environment properties with the “info.” prefix. So, if you configure, for example:

In application.properties (or YAML equivalent):

info.app-author = John Doe
info.app-license = MIT License

Then you will see a distinct key in the main JSON object for each configured info.*** property like the following:

{
    "app-author": "John Doe",
    "app-license": "MIT License"
}

You could also set these info properties using Java code, typically at the application startup. This contributor is particularly good at exposing static information like author name(s), license info, version info, etc.

The Git info contributor

The GitInfoContributor is a predefined InfoContributor implementation available since Spring Boot 1.4.0. This contributor provides information about the Git commit during the build. This contributor is generally enabled by default. However, you must apply an extra setup to see some concrete values.

Indeed, this contributor relies on the presence of the git.properties file located at the “root” on the classpath. This file can be generated using a specific Maven/Gradle plugin described in the Spring Boot reference documentation: Generate Git Information (for Spring Boot 2.x) or Generate Git Information (for Spring Boot 3.x).

Beware (if you haven’t noticed from the documentation) that, for Maven projects, there is a difference between Spring Boot 2.x and 3.x about this plugin:

  • Spring Boot 2.x uses the Maven plugin pl.project13.maven:git-commit-id-plugin
  • Spring Boot 3.x uses the Maven plugin io.github.git-commit-id:git-commit-id-maven-plugin

Each of these plugins is pre-configured in the spring-boot-starter-parent POM, and the version is “managed” in the spring-boot-dependencies POM. So, in the basic scenario, you don’t need to specify the <version> tag or other explicit configuration.

Once you have applied this extra setup, the git.properties file will be created/updated on each build. At this point, if you request the info HTTP endpoint, you should see a "git" key in the main JSON object like the following:

{
    "git": {
        "branch": "main",
        "commit": {
            "id": "456953c",
            "time": "2023-01-22T20:00:03Z"
        }
    }
}

The git.properties file, however, contains much more information that is not exposed by default. Therefore, if you want to have the complete set of data, you must set the management.info.git.mode configuration property to full (default value is simple):

In application.properties (or YAML equivalent):

management.info.git.mode = full

Final note: you can entirely disable the GitInfoContributor using the following configuration property:

In application.properties (or YAML equivalent):

management.info.git.enabled = false

The Java info contributor

The JavaInfoContributor is a predefined InfoContributor implementation available since Spring Boot 2.6.0, and it is disabled by default. You can enable this contributor using the following configuration property:

In application.properties (or YAML equivalent):

management.info.java.enabled = true

This contributor provides information about the Java specification, the Java runtime, and the JVM. When this contributor is enabled, it produces a "java" key in the main JSON object like the following:

{
    "java": {
        "version": "11.0.18",
        "vendor": {
            "name": "Oracle Corporation",
            "version": "18.9"
        },
        "runtime": {
            "name": "Java(TM) SE Runtime Environment",
            "version": "11.0.18+9-LTS-195"
        },
        "jvm": {
            "name": "Java HotSpot(TM) 64-Bit Server VM",
            "vendor": "Oracle Corporation",
            "version": "11.0.18+9-LTS-195"
        }
    }
}

All the pieces of information you see in the above JSON are taken directly from Java System properties (using System.getProperty("java.version") and so on).

The O.S. info contributor

The OsInfoContributor is a predefined InfoContributor implementation available since Spring Boot 2.7.0, and it is disabled by default. You can enable this contributor using the following configuration property:

In application.properties (or YAML equivalent):

management.info.os.enabled = true

This contributor provides some information about the Operating System. When this contributor is enabled, it produces an "os" key in the main JSON object like the following:

{
    "os": {
        "name": "Windows 10",
        "version": "10.0",
        "arch": "amd64"
    }
}

Similarly to the Java info contributor, also this contributor takes the values from Java System properties (using System.getProperty("os.name") and so on).

Conclusions

In this article, I provided the essential information to configure and use the Actuator “info” endpoint at the basic level. This is certainly sufficient in most cases. However, if you want to go deeper and understand how to implement the InfoContributor interface, check out my second article on this topic: Spring Boot: custom “info” contributors for Actuator

Similar Posts