在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/云計(jì)算/ Spring cloud Sleuth鏈路追蹤問題

Spring cloud Sleuth鏈路追蹤問題

我在學(xué)習(xí)鏈路追蹤的使用。但是按著教程,輸出的log應(yīng)該是這個(gè)結(jié)構(gòu)

2016-06-15 16:55:56.334  INFO [sleuth-sample,44462edc42f2ae73,44462edc42f2ae73,false] 13978 --- [nio-8080-exec-1] com.example.SleuthSampleApplication      : calling home

而我只能得到:
2016-06-15 16:55:56.334  INFO 13978 --- [nio-8080-exec-1] com.example.SleuthSampleApplication      : calling home

就是說明sleuth根本沒發(fā)揮作用traceid spanid都沒有,
pom如下

<groupId>com.sleuth</groupId>
    <artifactId>example</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>example</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


入口程序:

package com.sleuth.example;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
//import org.springframework.cloud.sleuth.sampler.AlwaysSampler;

import java.util.logging.Level;
import java.util.logging.Logger;

@SpringBootApplication
@RestController
public class ExampleApplication {

    private static final Logger LOG = Logger.getLogger(ExampleApplication.class.getName());

    @Autowired
    private RestTemplate restTemplate;

    public static void main(String[] args) {

        SpringApplication.run(ExampleApplication.class, args);
    }

    @Bean
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    @RequestMapping("/")
    public String home() {
        LOG.log(Level.INFO, "YOU CALLED HOME");

        return "hello world";
    }

    @RequestMapping("/callhome")
    public String callHome() {
        LOG.log(Level.INFO, "calling home");
        return restTemplate.getForObject("http://localhost:9411", String.class);
    }


}
回答
編輯回答
傻丟丟

已解決。。。沒有引入cloud dependency

2017年11月19日 01:31