侦探不传播痕迹Id

时间:2018-06-09 10:30:58

标签: java spring spring-boot spring-cloud-sleuth

我在Spring启动应用程序中使用Spring cloud Sleuth。

的build.gradle

buildscript {
    ext {
        springBootVersion = '2.0.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/milestone" }
}


ext {
    springCloudVersion = 'Finchley.M8'
}

dependencies {
    compile('org.springframework.cloud:spring-cloud-sleuth-core')
    compile('org.springframework.cloud:spring-cloud-sleuth-zipkin')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.cloud:spring-cloud-starter-config')
    runtime('mysql:mysql-connector-java')
}
dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

HomeController.java

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@RestController
public class HomeController {

    @Bean
    public RestTemplate template() {
        return new RestTemplate();
    }
    @Autowired
    private RestTemplate template;

    @Autowired
    private LanguageService languageService;

    private static final Logger LOG = LoggerFactory.getLogger(HomeController.class);

    @GetMapping(value="/{Id}")
    public Language getDetails(@PathVariable("Id") Integer Id) {

        LOG.info("Getting Details..");
        Language language = languageService.getLanguage(Id);
        SubLang SubLang = template.getForObject("http://localhost:8081/"+Id, SubLang.class);
        language.setSubLang(SubLang);

        return language;
    }

}

现在,当我点击浏览器发送请求时,我想获得微服务中应该相同的跟踪ID。

以下是当前微服务的日志。

INFO [HomeCont,b2a07f3e8f053b21,b2a07f3e8f053b21,false][0;39m [35m8524[0;39m

以下是http://localhost:8081/微服务的日志。

INFO [HomeLang,32b435aef0698cd6,32b435aef0698cd6,false] 10176

根据这个概念,b2a07f3e8f053b21应该与微服务中的Trace Id相同。

我在这里缺少什么?

0 个答案:

没有答案