目前在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. [Ubuntu]“ubuntu.sh: 113: ubuntu.sh:Syntax error: "(" unexpected ”报错解决方法

    原因:有可能是兼容性问题 解决方法: 1.sudo dpkg-reconfigure dash   2.在弹出的窗口选择no

  2. webpack前端构建工具学习总结(四)之自动化生成项目中的html页面

    接续上文:webpack前端构建工具学习总结(三)之webpack.config.js配置文件 插件的介绍文档:https://www.npmjs.com/package/html-webpack-p ...

  3. (十)mybatis之配置(mybatis-config.xml)

    配置  可以从前篇的文章中知道(https://www.cnblogs.com/NYfor2018/p/9093472.html ),要使用mybatis需要以下配置: 1.  mybatis-con ...

  4. win10 多桌面 win+tab | ctrl+win+左右箭头

    win10 多桌面 win+tab | ctrl+win+左右箭头

  5. Mac下搜索神兵利器Alfred 3.1.1最新和谐版

    http://bbs.feng.com/read-htm-tid-9891194.html 相比Windows而言Mac自带的Spotlight搜索已经非常强大了,尤其是Mac OS Yosemite ...

  6. ubuntu 18.* 重启网卡

    systemctl UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active waiting A ...

  7. 【译】Swift 字符串速查表

    [译]Swift 字符串速查表 2015-12-18 10:32 编辑: suiling 分类:Swift 来源:CocoaChina翻译活动 10 5585 Swift字符串 招聘信息: iOS高级 ...

  8. [LUOGU] P1049 装箱问题

    题目描述 有一个箱子容量为V(正整数,0<=V<=20000),同时有n个物品(0<n<=30,每个物品有一个体积(正整数). 要求n个物品中,任取若干个装入箱内,使箱子的剩余 ...

  9. centOS下jenkins

    转:centos7搭建jenkins小记 转自:https://segmentfault.com/a/1190000007086764 安装java环境 1.查看服务器版本 centos7,继续. c ...

  10. (7)zabbix资产清单inventory管理

    概述 监控的设备越来越多,有时候搞不清楚哪台服务器是什么配置,大多公司有自己的资产清单,要去专门的系统查询显得多少有点麻烦.为此,zabbix专门设置了设备资产管理功能. 我们创建或编辑主机的时候,可 ...