• spring-boot-starter-parent: 2.6.5, 2.6.6
  • micrometer ref: https://github.com/micrometer-metrics/micrometer/issues/3108#issuecomment-1086000015
  • bug in file: https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/startup/StartupTimeMetricsListener.java#L126
  • ref: https://github.com/spring-projects/spring-boot/issues/30497

demo

  • buld & start
  • hit url: http://localhost:8080/actuator/prometheus
  • you will see: application_started_time{env="moj test",main-application-class="com.example.demo.DemoApplication",} 1.262

demo.zip

Comment From: wilkinsona

It's the naming convention's job to convert both metric names and tag keys to the required format. You are trying to use NamingConvention.snakeCase which only converts . to _, leaving - unchanged. This code is part of Micrometer and is out of Spring Boot's control.

Micrometer has a naming convention, PrometheusNamingConvention, that is specifically intended for use with Prometheus and is the default naming convention of PrometheusMeterRegistry. If I remove MetricConfiguration from the sample, PrometheusNamingConvention is used and the tag key meets Prometheus' requirements:

# HELP application_started_time_seconds Time taken (ms) to start the application
# TYPE application_started_time_seconds gauge
application_started_time_seconds{env="moj test",main_application_class="com.example.demo.DemoApplication",} 2.83
…
# HELP application_ready_time_seconds Time taken (ms) for the application to be ready to service requests
# TYPE application_ready_time_seconds gauge
application_ready_time_seconds{env="moj test",main_application_class="com.example.demo.DemoApplication",} 2.901

Comment From: sysmat

Yes, when not using MeterRegistryCustomizer it works fine, but when using it with PrometheusMeterRegistry, PrometheusNamingConvention something is not working properly. I'll post to micrometer

Comment From: sysmat

  • is there any way with application configuration to add a prefix to each metric?

Comment From: wilkinsona

is there any way with application configuration to add a prefix to each metric?

Questions like this belong on Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Before asking on Stack Overflow, please take a moment to read the Micrometer documentation, particularly the section on transforming metrics.

Comment From: sysmat

@wilkinsona thx