diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfiguration.java index 138b05ad79..6c6fc6ea46 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/newrelic/NewRelicMetricsExportAutoConfiguration.java @@ -17,12 +17,14 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic; import io.micrometer.core.instrument.Clock; +import io.micrometer.core.ipc.http.HttpUrlConnectionSender; +import io.micrometer.newrelic.ClientProviderType; import io.micrometer.newrelic.NewRelicClientProvider; import io.micrometer.newrelic.NewRelicConfig; +import io.micrometer.newrelic.NewRelicInsightsAgentClientProvider; +import io.micrometer.newrelic.NewRelicInsightsApiClientProvider; import io.micrometer.newrelic.NewRelicMeterRegistry; -import io.micrometer.newrelic.NewRelicMeterRegistry.Builder; -import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; @@ -67,13 +69,23 @@ public class NewRelicMetricsExportAutoConfiguration { return new NewRelicPropertiesConfigAdapter(this.properties); } + @Bean + @ConditionalOnMissingBean + public NewRelicClientProvider newRelicClientProvider(NewRelicConfig newRelicConfig) { + if (newRelicConfig.clientProviderType() == ClientProviderType.INSIGHTS_AGENT) { + return new NewRelicInsightsAgentClientProvider(newRelicConfig); + } + return new NewRelicInsightsApiClientProvider(newRelicConfig, + new HttpUrlConnectionSender(this.properties.getConnectTimeout(), this.properties.getReadTimeout())); + + } + @Bean @ConditionalOnMissingBean public NewRelicMeterRegistry newRelicMeterRegistry(NewRelicConfig newRelicConfig, Clock clock, - ObjectProvider newRelicClientProvider) { - Builder builder = NewRelicMeterRegistry.builder(newRelicConfig).clock(clock); - newRelicClientProvider.ifUnique(builder::clientProvider); - return builder.build(); + NewRelicClientProvider newRelicClientProvider) { + return NewRelicMeterRegistry.builder(newRelicConfig).clock(clock).clientProvider(newRelicClientProvider) + .build(); } }