Recent Tutorials and Articles
    Adding Custom Attributes to Spring Boot Actuator Info Endpoint
    Published on: 2018-09-08 07:09:02
    Posted By: Amit Kumar

    This tutorial describes how to expose custom attributes to info endpoint of Spring Boot 2.x.x Actuator.

    Abstract


    Spring Boot has been getting quite popular for Microservices development for good reasons. One of the reasons is to provide production ready endpoints for service management such as endpoints for metrics, service info, health check, env variables, heap dump to name some of those.

    In this article, we will talk about Service info endpoint that can be used to provide any kind of service information such as java version, deployed artifact name, service version or any kind of parameters that you want to provide.

    Before we move ahead, please ensure that you have required libraries in your application and have endpoints enabled by following Mapping Spring Boot Actuator Endpoints to custom path.

    Exposing Properties in Info Endpoint


    Info endpoint is exposed in Spring Boot 2.x.x at http://hostname:port/<servletpath>/actuator/info endpoint while in Sprint Boot 1.x.x it is available at http://hostname:port/<servletpath>/info endpoint. <servletpath> points to / by default and can be changed using properties server.servlet.path and server.servlet-path in Spring boot 2.x.x and 1.x.x respectively.

    Exposing properties to Info endpoint is as simple as defining them with prefix info in your properties (application.properties) or yaml file (application.yml) as shown below.

    # Exposing other property values
    info.service.name=${spring.application.name}
    
    # Exposing values from maven properties
    [email protected]@
    [email protected]@
    [email protected]@
    [email protected]@

    Please note that ${...} is used to refer other Spring Boot properties and @[email protected] is used to refer to properties from Maven pom.xml file.

     

    After defining above properties, you should see an output similar to below on hitting info endpoint -

    {
       "app":{
          "java":{
             "source":"1.8.0_101",
             "target":"1.8.0_101"
          }
       },
       "artifact":{
          "name":"test-service-demo",
          "version":"0.1.0-SNAPSHOT"
       },
       "service":{
          "name":"Test Service Demo"
       }
    }

     

    Thank you for reading through the tutorial. In case of any feedback/questions/concerns, you can communicate same to us through your comments and we shall get back to you as soon as possible.

    Posted By: Amit Kumar
    Published on: 2018-09-08 07:09:02

    Comment Form is loading comments...