Merge branch '1.2.x'
This commit is contained in:
@@ -43,7 +43,7 @@ import org.springframework.core.env.PropertySource;
|
||||
public class TraceEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
|
||||
private static final String PROPERTY_SOURCE_NAME = "defaultProperties";
|
||||
public static final String SPRING_AOP_PROXY_TARGET_CLASS = "spring.aop.proxyTargetClass";
|
||||
private static final String SPRING_AOP_PROXY_TARGET_CLASS = "spring.aop.proxyTargetClass";
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||
@@ -51,8 +51,10 @@ public class TraceEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
// This doesn't work with all logging systems but it's a useful default so you see
|
||||
// traces in logs without having to configure it.
|
||||
map.put("logging.pattern.level",
|
||||
"%5p [${spring.zipkin.service.name:${spring.application.name:-}},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]");
|
||||
if (Boolean.parseBoolean(environment.getProperty("spring.sleuth.enabled", "true"))) {
|
||||
map.put("logging.pattern.level",
|
||||
"%5p [${spring.zipkin.service.name:${spring.application.name:-}},%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]");
|
||||
}
|
||||
// TODO: Remove this in 2.0.x. For compatibility we always set to true
|
||||
if (!environment.containsProperty(SPRING_AOP_PROXY_TARGET_CLASS)) {
|
||||
map.put(SPRING_AOP_PROXY_TARGET_CLASS, "true");
|
||||
|
||||
@@ -17,26 +17,49 @@ package org.springframework.cloud.sleuth.autoconfig;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.assertions.SleuthAssertions;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = TraceAutoConfigurationWithDisabledSleuthTests.Config.class)
|
||||
@TestPropertySource(properties = "spring.sleuth.enabled=false")
|
||||
@SpringBootTest(classes = TraceAutoConfigurationWithDisabledSleuthTests.Config.class,
|
||||
properties = "spring.sleuth.enabled=false",
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@ActiveProfiles("disabled")
|
||||
public class TraceAutoConfigurationWithDisabledSleuthTests {
|
||||
|
||||
@Test
|
||||
public void shouldStartContext(){
|
||||
private static final Log log = LogFactory.getLog(TraceAutoConfigurationWithDisabledSleuthTests.class);
|
||||
|
||||
@Rule public OutputCapture capture = new OutputCapture();
|
||||
@Autowired(required = false) Tracer tracer;
|
||||
|
||||
@Test
|
||||
public void shouldStartContext() {
|
||||
SleuthAssertions.then(this.tracer).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotContainAnyTracingInfoInTheLogs() {
|
||||
log.info("hello");
|
||||
|
||||
SleuthAssertions.then(this.capture.toString()).doesNotContain("[foo");
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
static class Config {
|
||||
@Bean
|
||||
public FactoryBean<SecureRandom> secureRandom() {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
spring:
|
||||
application:
|
||||
name: foo
|
||||
sleuth:
|
||||
enabled: false
|
||||
Reference in New Issue
Block a user