目前在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. Web开发者应掌握的12个Firebug技巧

    来源: 廖煜嵘 相信很多从事Web开发工作的开发者都听说和使用过Firebug,但可能大部分人还不知道,其实它是一个在网页设计方面功能相当强大的编辑器,它 可以对HTML.DOM.CSS.HTTP和J ...

  2. iOS Category 添加属性实现原理 - 关联对象

    iOS Category 添加属性实现原理 - 关联对象 RunTime为Category动态关联对象 使用RunTime给系统的类添加属性,首先需要了解对象与属性的关系.对象一开始初始化的时候其属性 ...

  3. java+spring 执行器

    A 通过MethodInvokingJobDetailFactoryBean类实现 spring配置文件里增加执行器配置 <bean id="ammoDue" class=& ...

  4. sourceTree配置bitbucket

    1. 为github增加账号信息 选择添加远程库 选择添加一个账号 输入用户名: 按照提示输入密码 选择bitbuchet为默认 选中搜索克隆

  5. java 读取文件转换成字符串

    public String readFromFile(File src) { try { BufferedReader bufferedReader = new BufferedReader(new ...

  6. Objective-C中的命名前缀说明

    http://www.cnblogs.com/dhui69/p/6410134.html __kindof __kindof 这修饰符还是很实用的,解决了一个长期以来的小痛点,拿原来的 UITable ...

  7. 47.Number of Islands(岛的数量)

    Level:   Medium 题目描述: Given a 2d grid map of '1's (land) and '0's (water), count the number of islan ...

  8. input提示文字;placeholder字体修改

    在很多网站上我们都看到input输入框显示提示文字,让我们一起来看看如果在input输入框中显示提示文字.我们只需要在<input>标签里添加:placeholder="提示文字 ...

  9. python之for (循环)

    格式: for 循环 for i in s: print(i) # for 关键字 # i 变量 # in 关键字 # s 可迭代对象 int - bool pass和- # for a in &qu ...

  10. Greenplum/Deepgreen(集群/分布式)安装文档

    Deepgreen分布式安装文档 环境准备 1.安装VMware虚拟机软件,然后在VMware安装三台Linux虚拟机(使用centos7版本) 2.使用的虚拟机如下: 192.168.136.155 ...