SpringBoot of micro link tracking service log

SpringBoot of micro link tracking service log

Brief introduction

Any problems in the micro-services, the business problem or program out, are ultimately view the log, we generally use ELKthe relevant log collection tools, multi-service, the business is also somewhat difficult to troubleshoot the problem, determine the approximate time targeting only relevant log . log-trace-spring-boot-starterAddress multiple issues service call log, it can be a complete chain of calls to be integrated into a complete and orderly log.

Support components:

  • zuul call
  • feign call
  • restTemplate call

Log output formats:

2019-11-14 14:22:07.796  INFO [log-trace-service-a-demo,ac8ffaaed5f343da,log-trace-zuul-demo,,] 88948 --- [nio-8081-exec-7] c.p.l.t.service.a.demo.TestController    : controller test2 执行 ac8ffaaed5f343da
2019-11-14 14:23:15.569  INFO [log-trace-service-a-demo,04cf5392dc5c4881,log-trace-zuul-demo,,] 88948 --- [nio-8081-exec-9] c.p.l.t.service.a.demo.TestController    : controller test2 执行 04cf5392dc5c4881
2019-11-14 14:24:44.183  INFO [log-trace-service-a-demo,86b5c555ce4f4451,log-trace-zuul-demo,,] 88948 --- [nio-8081-exec-1] c.p.l.t.service.a.demo.TestController    : controller test2 执行 86b5c555ce4f4451

We can 86b5c555ce4f4451make all the log information on the query link id.

log-trace-service-a-demoFor the current application.
log-trace-zuul-demoUpstream applications.

Of course, these parameters can be customized based on business.

Use function

Add dependent

ps: the actual release version, use the latest version of
the latest version:

Looking for a new version

<dependency>
  <groupId>com.purgeteam</groupId>
  <artifactId>log-trace-spring-boot-starter</artifactId>
  <version>0.1.0.RELEASE</version>
</dependency>

ps: Please based SpirngBoot2.1.xversion

Configuration Application

In this example three sub-service microstructure.

  1. log-trace-zuul-demo Acting as a gateway function
  2. log-trace-service-a-demo A acts as a service
  3. log-trace-service-b-demo B acts as a service

Calls for the link:

log-trace-zuul-demo -> log-trace-service-a-demo TestController#test -> log-trace-service-b-demo TestController#test

Access Gateway Address: http://127.0.0.1:8000/a/test

Gateway log is as follows:

2019-11-14 14:27:37.434 DEBUG [33b07a9c5f324375,this] 89996 --- [nio-8000-exec-1] c.p.l.t.s.i.zuul.TracePreZuulFilter      : zuul traceid 33b07a9c5f324375

A gateway forwarded to the service

A service log is as follows:

2019-11-14 14:27:37.476  INFO [log-trace-service-a-demo,33b07a9c5f324375,log-trace-zuul-demo,,] 88948 --- [nio-8081-exec-5] c.p.l.t.service.a.demo.TestController    : controller test2 执行 33b07a9c5f324375

A service call to service B

B service log is as follows:

2019-11-14 14:27:37.478  INFO [log-trace-service-b-demo,33b07a9c5f324375,log-trace-service-a-demo,,] 88952 --- [nio-8082-exec-3] c.p.l.t.servcie.b.demo.TestController    : header traceId 33b07a9c5f324375
2019-11-14 14:27:37.478  INFO [log-trace-service-b-demo,33b07a9c5f324375,log-trace-service-a-demo,,] 88952 --- [nio-8082-exec-3] c.p.l.t.servcie.b.demo.TestController    : controller test 执行 33b07a9c5f324375
2019-11-14 14:27:37.478  INFO [log-trace-service-b-demo,33b07a9c5f324375,log-trace-service-a-demo,,] 88952 --- [nio-8082-exec-3] c.p.l.trace.servcie.b.demo.TestService   : test 方法执行 33b07a9c5f324375
2019-11-14 14:27:37.478  INFO [log-trace-service-b-demo,33b07a9c5f324375,log-trace-service-a-demo,,] 88952 --- [nio-8082-exec-3] c.p.l.trace.servcie.b.demo.TestService   : test1 方法执行 33b07a9c5f324375

This can be queried in accordance with a third-party log id platform.

Such as ELKby 33b07a9c5f324375id check out all the links related calls.

Configuring the output format

Currently supports the above parameters:

X-B3-ParentName 上游服务名称
X-B3-TraceId 为一个请求分配的ID号,用来标识一条请求链路。

By application.propertiesconfiguring.

spring.trace.log.format=X-B3-TraceId,X-B3-ParentName


`spring.trace.log.format` 配置参数顺序将影响日志输出格式。

不配置将按照默认格式输出。

Log output is as follows:

2019-11-14 14:27:37.434 DEBUG [33b07a9c5f324375,this] 89996 --- [nio-8000-exec-1] c.p.l.t.s.i.zuul.TracePreZuulFilter      : zuul traceid 33b07a9c5f324375

to sum up

Currently achieve consistent log function, follow-up support to customize the output such as output in accordance with the landing staff id, easy to track user behavior.
Facilitate subsequent support frame Dubboand the like.

Sample Code Address: log-the trace-Spring-Boot

On GitHub:
Purgeyao welcome attention

qq exchange group: 812321371micro-channel exchange group:MercyYao

Micro-channel public number:

Micro-channel public number two-dimensional code

Guess you like

Origin www.cnblogs.com/Purgeyao/p/11872141.html