账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Spring cloud Sleuth链路追踪问题
    41
    0

    我在学习链路追踪的使用。但是按着教程,输出的log应该是这个结构

    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根本没发挥作用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);
        }
    
    
    }
    
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 明月何灼灼 普通会员 1楼

      Spring Cloud Sleuth是一个用于日志收集和分析的工具,可以用于跟踪应用中的各个组件的执行路径。链路追踪是指在应用的各个组件之间建立联系,以便在发生故障或异常时追踪问题的来源。

      然而,使用Spring Cloud Sleuth进行链路追踪可能会遇到一些问题。例如:

      1. 数据不一致:如果不同组件之间的日志之间有差异,那么链路追踪可能会出现问题。这可能会导致误解,例如错误地认为问题在某个组件的执行路径上。

      2. 数据收集和分析困难:虽然Spring Cloud Sleuth提供了丰富的日志收集和分析工具,但是它们可能会对日志进行预处理,这可能会影响链路追踪的结果。例如,一些工具可能会删除或过滤掉不需要的日志。

      3. 系统扩展困难:由于链路追踪涉及到多个组件,因此系统扩展可能会比较困难。例如,如果需要添加新的组件或更改组件的配置,可能需要重新构建链路追踪。

      解决这些问题的方法包括:

      1. 对日志进行统一处理:在收集和分析日志之前,应该对日志进行统一处理,以消除差异。

      2. 使用更灵活的日志收集和分析工具:可以选择一些更灵活的日志收集和分析工具,以减少对日志预处理的影响。

      3. 使用自动化的系统扩展策略:在构建链路追踪时,应该使用自动化的系统扩展策略,以确保系统在扩展时能够保持稳定性。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部