Skip to content

Commit

Permalink
Prevent NPE when micrometer is disabled
Browse files Browse the repository at this point in the history
Fixes: quarkusio#25099
(cherry picked from commit 037b780)
  • Loading branch information
geoand authored and gsmet committed May 18, 2022
1 parent 1b4086d commit f485a52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public boolean getAsBoolean() {

MicrometerConfig mConfig;

/**
* config objects are beans, but they are not unremoveable by default
*/
@BuildStep
UnremovableBeanBuildItem mpConfigAsBean() {
return UnremovableBeanBuildItem.beanTypes(MicrometerConfig.class);
}

@BuildStep(onlyIf = MicrometerEnabled.class)
FeatureBuildItem feature() {
return new FeatureBuildItem(Feature.MICROMETER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.Timer;
import io.quarkus.arc.Arc;
import io.quarkus.micrometer.runtime.config.MicrometerConfig;

/**
* This is initialized via ServiceFactory (static/non-CDI initialization)
Expand All @@ -35,6 +36,10 @@ public class RestClientMetricsListener implements RestClientListener {

@Override
public void onNewClient(Class<?> serviceInterface, RestClientBuilder builder) {
MicrometerConfig micrometerConfig = Arc.container().instance(MicrometerConfig.class).get();
if (!micrometerConfig.enabled) {
return;
}
if (prepClientMetrics()) {
// This must run AFTER the OpenTelmetry client request filter
builder.register(this.clientRequestFilter, Priorities.HEADER_DECORATOR + 1);
Expand Down

0 comments on commit f485a52

Please sign in to comment.