Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions spring-cloud-sleuth-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<packaging>jar</packaging>
<name>Spring Cloud Sleuth Core</name>
<description>Spring Cloud Sleuth Core</description>
<properties>
<spring-security-oauth2.version>2.2.0.RELEASE</spring-security-oauth2.version>
</properties>

<parent>
<groupId>org.springframework.cloud</groupId>
Expand Down Expand Up @@ -131,7 +134,7 @@
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.2.0.RELEASE</version>
<version>${spring-security-oauth2.version}</version>
<optional>true</optional>
</dependency>
<dependency>
Expand Down Expand Up @@ -286,20 +289,28 @@
<artifactId>brave-instrumentation-grpc</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-metrics-micrometer</artifactId>
<exclusions>
<exclusion>
<groupId>io.micrometer</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shakuzen reminds me.. we probably should have had this set to "provided" scope in upstream anyway

<artifactId>micrometer-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Instrumentation of Lettuce -->
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<optional>true</optional>
</dependency>

<!-- For Instrumentation of Quartz -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@
import brave.propagation.Propagation;
import brave.propagation.ThreadLocalCurrentTraceContext;
import brave.sampler.Sampler;
import io.micrometer.core.instrument.MeterRegistry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import zipkin2.Span;
import zipkin2.reporter.InMemoryReporterMetrics;
import zipkin2.reporter.Reporter;
import zipkin2.reporter.ReporterMetrics;
import zipkin2.reporter.metrics.micrometer.MicrometerReporterMetrics;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.sleuth.DefaultSpanNamer;
Expand Down Expand Up @@ -198,12 +203,6 @@ CurrentTraceContext.Builder sleuthCurrentTraceContextBuilder() {
return ThreadLocalCurrentTraceContext.newBuilder();
}

@Bean
@ConditionalOnMissingBean
ReporterMetrics sleuthReporterMetrics() {
return new InMemoryReporterMetrics();
}

@Bean
@ConditionalOnMissingBean
Reporter<zipkin2.Span> noOpSpanReporter() {
Expand Down Expand Up @@ -283,4 +282,40 @@ public String toString() {

}

@Configuration
@ConditionalOnMissingClass("io.micrometer.core.instrument.MeterRegistry")
static class TraceMetricsNoOpConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be

Suggested change
static class TraceMetricsNoOpConfiguration {
static class TraceMetricsInMemoryConfiguration {

if no-op is desired, that would be different and cheaper.


@Bean
@ConditionalOnMissingBean
ReporterMetrics sleuthReporterMetrics() {
return new InMemoryReporterMetrics();
}

}

@Configuration
@ConditionalOnClass(MeterRegistry.class)
static class TraceMetricsMicrometerConfiguration {

@Configuration
@ConditionalOnMissingBean(ReporterMetrics.class)
static class NoReporterMetricsConfiguration {

@Bean
@ConditionalOnBean(MeterRegistry.class)
ReporterMetrics sleuthMicrometerReporterMetrics(MeterRegistry meterRegistry) {
return MicrometerReporterMetrics.create(meterRegistry);
}

@Bean
@ConditionalOnMissingBean(MeterRegistry.class)
ReporterMetrics sleuthReporterMetrics() {
return new InMemoryReporterMetrics();
}

}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2013-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.sleuth.autoconfig;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.assertj.core.api.BDDAssertions;
import org.junit.Test;
import zipkin2.reporter.InMemoryReporterMetrics;
import zipkin2.reporter.ReporterMetrics;
import zipkin2.reporter.metrics.micrometer.MicrometerReporterMetrics;

import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

public class TraceAutoConfigurationTests {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(TraceAutoConfiguration.class));

@Test
public void should_apply_micrometer_reporter_metrics_when_meter_registry_bean_present() {
this.contextRunner.withUserConfiguration(WithMeterRegistry.class)
.run((context) -> {
ReporterMetrics bean = context.getBean(ReporterMetrics.class);

BDDAssertions.then(bean)
.isInstanceOf(MicrometerReporterMetrics.class);
});
}

@Test
public void should_apply_in_memory_metrics_when_meter_registry_bean_missing() {
this.contextRunner.run((context) -> {
ReporterMetrics bean = context.getBean(ReporterMetrics.class);

BDDAssertions.then(bean).isInstanceOf(InMemoryReporterMetrics.class);
});
}

@Test
public void should_apply_in_memory_metrics_when_meter_registry_class_missing() {
this.contextRunner.withClassLoader(new FilteredClassLoader(MeterRegistry.class))
.run((context) -> {
ReporterMetrics bean = context.getBean(ReporterMetrics.class);

BDDAssertions.then(bean).isInstanceOf(InMemoryReporterMetrics.class);
});
}

@Configuration
static class WithMeterRegistry {

@Bean
MeterRegistry meterRegistry() {
return new SimpleMeterRegistry();
}

}

}