Issue
I am currently using spring boot 2.7.0-M1
and following is my dependencies in build.gradle
:
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.boot:spring-boot-starter-cache'
compileOnly 'org.projectlombok:lombok'
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'io.micrometer:micrometer-registry-datadog:latest.release'
datadogagent("com.datadoghq:dd-java-agent:$datadoghq_dd_version")
implementation("com.datadoghq:dd-trace-api:${datadoghq_dd_version}")
However, when i try to set micrometer bean:
@Configuration
public class MeterRegistryConfig {
@Bean
MeterRegistry meterRegistry(ApplicationContext context) {
DatadogConfig config = new DatadogConfig() {
@Override
public Duration step() {
return Duration.ofSeconds(10);
}
@Override
public String get(String k) {
return null; // accept the rest of the defaults
}
};
return new DatadogMeterRegistry(config, Clock.SYSTEM);
}
}
I am getting a startup error:
2022-02-05 05:07:56.457 ERROR 7897 --- [ restartedMain] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'compositeMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/CompositeMeterRegistryConfiguration.class]: Unsatisfied dependency expressed through method 'compositeMeterRegistry' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'meterRegistry' defined in class path resource [com/hbomax/ml/mlsvc/config/MeterRegistryConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.micrometer.core.instrument.MeterRegistry]: Factory method 'meterRegistry' threw exception; nested exception is io.micrometer.core.instrument.config.validate.ValidationException: datadog.apiKey was 'null' but it is required
2022-02-05 05:07:56.504 INFO 7897 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-02-05 05:07:56.520 WARN 7897 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2022-02-05 05:07:56.541 INFO 7897 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Here's my application.yaml
:
management:
info:
git:
mode: full
metrics:
distribution:
percentiles:
http:
server:
requests: 0.5, 0.95, 0.99
percentiles-histogram:
http:
server:
requests: true
sla:
http:
server:
requests: 200ms, 400ms, 600ms
export:
datadog:
step: 30s
enabled: true
api-key: xxxxxxx
tags:
application: ${spring.application.name}
env: ${spring.profiles}
Can someone help me understand what is the issue? I tried searching around but din't get any solution. I tried replacing api-key
with apiKey
(I know it's silly) but no success.
Any help folks?
Solution
You are using Spring Boot's configuration properties in application.yml
but you are also making your own DatadogMeterRegistry
that doesn't use those configuration properties, and therefore it will not have the required API key configuration.
You can delete the MeterRegistryConfig
class entirely and instead use the DatadogMeterRegistry
that Spring Boot will auto-configure from configuration properties because you have the micrometer-registry-datadog
dependency on your classpath. See this section of the Spring Boot documentation.
Answered By - Tommy Ludwig
Answer Checked By - Marie Seifert (JavaFixing Admin)