简体   繁体   中英

Spring Actuator /info returns an empty body

How to add custom metrics to /info endpoint in Spring Actuator 2.7.0?

Currently have the following related to actuator. I have verified that info.app.version can retrieve the proper value from pom.xml using @Value.

pom.xml

<version>0.0.1-SNAPSHOT</version>
...
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <version>2.7.0</version>
</dependency>

application.properties

info.app.version=@project.version@

management.endpoint.info.enabled=true
management.endpoints.web.exposure.include=info,health

But despite this I am only getting an empty response on /info. Response header:

< HTTP/1.1 200 
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/vnd.spring-boot.actuator.v3+json
< Transfer-Encoding: chunked
< Date: Wed, 15 Jun 2022 04:12:47 GMT


* Received 7 B chunk
* Received 5 B chunk
* Connection #26 to host localhost left intact

Response body:

{}

My understanding is any property under info is included in /info endpoint. Or does this not work on actuator v2+? Source

From the Spring-Boot 2.6 release notes https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes#actuator-env-infocontributor-disabled-by-default

You need to enable the info env property:

management.info.env.enabled=true

Latest spring boot requires two things to be set up:

1- exposing the endpoint in application.properties file:

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

You can use a wildcard and expose all endpoints if you want

management.endpoints.web.exposure.include=*

2- enabling info.env in application.properties :

management.info.env.enabled=true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM