目前在zipkin brave已经提供功能在我们使用logback或log4j等时可以在日志信息中将traceId和spanId等信息打印到运行日志,这样可能对我们通过日志查看解决问题有比较大的帮助。
  
  示例:
  
  pom.xml中添加zipkin相关jar
  
  <dependency>
  
   <groupId>io.zipkin.brave</groupId>
  
   <artifactId>brave-instrumentation-spring-web</artifactId>
  
   <version>5.4.3</version>
  
   </dependency>
  
  <dependency>
  
  <groupId>io.zipkin.brave</groupId>
  
  <artifactId>brave</artifactId>
  
  <version>5.4.3</version>
  
  </dependency>
  
  <dependency>
  
  <groupId>io.zipkin.brave</groupId>
  
  <artifactId>brave-context-slf4j</artifactId>
  
  <version>5.4.3</version>
  
  </dependency>
  
   <dependency>
  
   <groupId>io.zipkin.brave</groupId>
  
   <artifactId>brave-instrumentation-spring-webmvc</artifactId>
  
   <version>5.4.3</version>
  
   </dependency>
  
  注入zip相关bean:
  
  Configuration
  
  @Import({
  
  TracingClientHttpRequestInterceptor.class,
  
  SpanCustomizingAsyncHandlerInterceptor.class
  
  })
  
  public class TracingConfiguration extends WebMvcConfigurerAdapter {
  
  @Bean
  
  public DelegatingTracingFilter getDelegatingTracingFilter() {
  
  return new DelegatingTracingFilter();
  
  }
  
  @Bean
  
  Sender sender() {
  
   return OkHttpSender.create("http://127.0.0.1:9411/api/v2/spans");
  
  }
  
  @Bean
  
  AsyncReporter<Span> spanReporter() {
  
   return AsyncReporter.create(sender());
  
  }
  
  @Bean
  
  Tracing tracing(@Value("${zipkin.service:brave-webmvc-example}") String serviceName) {
  
   return Tracing.newBuilder(www.michenggw.com/)
  
  .localServiceName(serviceName)
  
  .propagationFactory(ExtraFieldPropagation.newFactory(B3Propagation.FACTORY, "user-name"))
  
  .spanReporter(spanReporter(www.huarenyl.cn)).currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
  
  //添加日志相关的处理器
  
  .addScopeDecorator(MDCScopeDecorator.create(www.meiwanyule.cn)).build()).build();
  
  }
  
  @Bean
  
  HttpTracing httpTracing(www.hjshidpt.com Tracing tracing) {
  
   return HttpTracing.create(tracing);
  
  }
  
  @Autowired
  
  TracingClientHttpRequestInterceptor clientInterceptor;
  
  @Bean
  
  public RestTemplate restTemplate() {
  
   RestTemplate restTemplate = new RestTemplate();
  
   List<ClientHttpRequestInterceptor> interceptors =new ArrayList<>(restTemplate.getInterceptors());
  
   interceptors.add(clientInterceptor);
  
   restTemplate.setInterceptors(interceptors);
  
   return restTemplate;
  
  }
  
  @Autowired
  
  SpanCustomizingAsyncHandlerInterceptor serverInterceptor;
  
  @Override
  
  public void addInterceptors(www.dasheng178.com/ InterceptorRegistry registry) {
  
   registry.addInterceptor(serverInterceptor);
  
  }
  
  }
  
  运行日志:
  
  @RequestMapping("start"www.ysyl157.com)
  
  public String start(HttpServletRequest request1,HttpServletResponse response1) throws InterruptedException, IOException {
  
  logger.info("start");
  
  String data = restTemplate.getForObject("http://localhost:9090/foo", String.class);
  
  return data;
  
  }
  
  logback.xml相关配置:
  
  主要添加这个打印格式:
  
  <property name="CONSOLE_LOG_PATTERN" value=www.furggw.com"%d [%X{traceId}/%X{spanId}] [%thread] %-5level %logger{36} - %msg%n"/>
  
  logback.xml示例:
  
  <?xml version="1.0" encoding="UTF-8"?>
  
  <configuration>
  
  <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
  
  <springProperty scope="context" name="springAppName" source="spring.application.name"/>
  
  <!-- Example for logging into the build folder of your project -->
  
  <property name="LOG_FILE" value="logs\\${springAppName}.log"/>​
  
  <!-- You can override this to have a custom pattern -->
  
  <property name="CONSOLE_LOG_PATTERN" value="%d [%X{traceId}/%X{spanId}] [%thread] %-5level %logger{36} - %msg%n"/>
  
  <!-- Appender to log to console -->
  
  <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
  
  <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
  
  <!-- Minimum logging level to be presented in the console logs-->
  
  <level>INFO</level>
  
  </filter>
  
  <encoder>
  
  <pattern>${CONSOLE_LOG_PATTERN}</pattern>
  
  <charset>utf8</charset>
  
  </encoder>
  
  </appender>
  
  <!-- Appender to log to file -->​
  
  <appender name="flatfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
  
  <file>${LOG_FILE}</file>
  
  <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  
  <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.gz</fileNamePattern>
  
  <maxHistory>7</maxHistory>
  
  </rollingPolicy>
  
  <encoder>
  
  <pattern>${CONSOLE_LOG_PATTERN}</pattern>
  
  <charset>utf8</charset>
  
  </encoder>
  
  </appender>
  
  <root level="INFO">
  
  <appender-ref ref="console"/>
  
  <!-- uncomment this to have also JSON logs -->
  
  <appender-ref ref="flatfile"/>
  
  </root>
  
  </configuration>
  
  日志打印信息:

ZipKin原理学习--zipkin支持日志打印追踪信息的更多相关文章

  1. python学习(五)--打印错误信息

    from urllib import request #打印错误信息 except Exceptionlist = [ "http://www.baidu11.com/", &qu ...

  2. python日志,支持彩色打印和文件大小切片写入和写入mongodb

    1.项目中使用了自定义的ColorHandler和MongoHandler,使用了内置的RotatingFileHandler和三方库的ConcurrentRotatingFileHandler. 支 ...

  3. grp/从Zipkin到Jaeger,Uber的分布式追踪之道tchannel--zipkin with mysql in docker-compose

    GRPC----http://www.cnblogs.com/ghj1976/p/4587736.html https://blog.csdn.net/fei33423/article/details ...

  4. 自定义springboot - starter 实现日志打印,并支持动态可插拔

    1. starter 命名规则: springboot项目有很多专一功能的starter组件,命名都是spring-boot-starter-xx,如spring-boot-starter-loggi ...

  5. python(36):python日志打印,保存,logging模块学习

    1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message') logging.info('This is info messa ...

  6. springboot学习4使用日志:logback

    springboot学习4使用日志:logback 一.基本知识说明 SpringBoot默认使用logback作为日志框架 ,所以引入起步依赖后就可以直接使用logback,不需要其他依赖. Spr ...

  7. SpringBoot系列之集成logback实现日志打印(篇二)

    SpringBoot系列之集成logback实现日志打印(篇二) 基于上篇博客SpringBoot系列之集成logback实现日志打印(篇一)之后,再写一篇博客进行补充 logback是一款开源的日志 ...

  8. 基于AOP和HashMap原理学习,开发Mysql分库分表路由组件!

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 什么?Java 面试就像造火箭 单纯了! 以前我也一直想 Java 面试就好好面试呗 ...

  9. java日志打印使用指南

    一.简介 日志打印是java代码开发中不可缺少的重要一步. 日志可以排查问题,可以搜集数据 二.常用日志框架 比较常用的日志框架就是logback, 一些老项目会使用log4j,他们用的都是slf4j ...

随机推荐

  1. Android 6.0 运行时权限处理完全解析 (摘抄)

    转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/50709663: 本文出自:[张鸿洋的博客] 一.概述 随着Android 6. ...

  2. Javafinal方法

    class Animal{     public final void eat(){         System.out.println("吃");     } } class ...

  3. svn merge当主干修改后合并分支

    例如版本r1的主干创建分支r2,在r2上修改后得到r3,r1之后也修改得到r4,现在合并分支到主干上: 如果r3的修改和r4有冲突会提示出现冲突,因此不用担心主干合并后会被分支操作覆盖,因为这并不是简 ...

  4. 自学Spring Boot

    简介: Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配 ...

  5. 自己太水了—HDOJ_2212

    Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every d ...

  6. Python 解压序列、可迭代对象并赋值给多个变量

    Python数据结构和类型 1.1 解压序列赋值给多个变量 现在有一个包含N个元素的元组或者是序列,怎样将它里面的值解压后同时赋值给N个变量? 解决思路:先通过简单的解压赋值给多个变量,前提是变量的数 ...

  7. websphere7.0异常:SRVE0255E: 尚未定义要处理 /wcm 的 Web 组/虚拟主机

    websphere7.0错误:SRVE0255E: 尚未定义要处理 /wcm 的 Web 组/虚拟主机. SRVE0255E: 尚未定义要处理 /wcm 的 Web 组/虚拟主机.SRVE0255E: ...

  8. shell脚本,怎么实现每次新开一个shell都输出一个提示语?

    [root@localhost wyb]# cat test.sh echo -e "\033[32mhello,This is wangyuebo's shell\033[0m" ...

  9. swift-通知的基本使用

    swift-通知的基本使用   //通知的使用 1.发通知.(以这条通知为例,通知名字:nickNameNotification 通知参数:title) NSNotificationCenter.de ...

  10. 拖拽大图轮播pc 移动兼容

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...