1 Star 0 Fork 20

孟繁森/trace-log-spring-boot-starter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

trace-log-spring-boot-starter

介绍

trace-log-spring-boot-starter (traceLog)一个简单易用的java分布式链路跟踪日志组件,

支持百亿级别, 日志从搜集到查询, 不用去文件中翻阅日志方便快捷, 支持查询一个调用链的日志,

支持链路追踪, 查看调用链耗时情况, 在分布式系统中也可以查询关联日志, 能够帮助快速定位问题,

简单易用,没有代码入侵, 查询界面友好,高效,方便,

只要你是java系统,不要做任何项目改造,接入直接使用,

日志不落本地磁盘,无需关心日志占用应用服务器磁盘问题,觉得项目好用帮忙点个星星, 您的star是我们前进的动力

目前进度:1.0版本完成

一.系统介绍

1、无入侵的分布式日志系统,基于elk搜集日志,采用Skywalking设置链路ID,方便查询关联日志

2、基于elasticsearch作为查询引擎

3、高吞吐,查询效率高

4、支持redis实时日志、es历史日志查询

5、Skywalking 6.0.0-beta 支持跟踪如下中间件的日志

![https://github.com/apache/skywalking/blob/master/docs/en/setup/service-agent/java-agent/Supported-list.md](Skywalking 6.0.0-beta 支持的组件)

HTTP Server

  • Tomcat 7
  • Tomcat 8
  • Tomcat 9
  • Spring Boot Web 4.x
  • Spring MVC 3.x, 4.x 5.x with servlet 3.x
  • Nutz Web Framework 1.x
  • Struts2 MVC 2.3.x -> 2.5.x
  • Resin 3 (Optional¹)
  • Resin 4 (Optional¹)
  • Jetty Server 9
  • Spring WebFlux 5.x
  • Undertow 1.3.0.Final -> 2.0.27.Final
  • RESTEasy 3.1.0.Final -> 3.7.0.Final
  • Play Framework 2.6.x -> 2.8.x
  • Light4J Microservices Framework 1.6.x -> 2.x
  • Netty SocketIO 1.x

HTTP Client

  • Feign 9.x
  • Netflix Spring Cloud Feign 1.1.x -> 2.x
  • Okhttp 3.x
  • Apache httpcomponent HttpClient 2.0 -> 3.1, 4.2, 4.3
  • Spring RestTemplete 4.x
  • Jetty Client 9
  • Apache httpcomponent AsyncClient 4.x
  • HTTP Gateway
  • Spring Cloud Gateway 2.1.x.RELEASE (Optional²) JDBC
  • Mysql Driver 5.x, 6.x, 8.x
  • Oracle Driver (Optional¹)
  • H2 Driver 1.3.x -> 1.4.x
  • Sharding-JDBC 1.5.x
  • ShardingSphere 3.0.0, 4.0.0-RC1
  • PostgreSQL Driver 8.x, 9.x, 42.x
  • Mariadb Driver 2.x, 1.8

RPC Frameworks

  • Dubbo 2.5.4 -> 2.6.0
  • Dubbox 2.8.4
  • Apache Dubbo 2.7.0
  • Motan 0.2.x -> 1.1.0
  • gRPC 1.x
  • Apache ServiceComb Java Chassis 0.1 -> 0.5,1.x
  • SOFARPC 5.4.0
  • Armeria 0.63.0 -> 0.98.0
  • Apache Avro 1.7.0 - 1.8.x
  • Finagle 6.25.0 -> 20.1.0

MQ

  • RocketMQ 4.x

  • Kafka 0.11.0.0 -> 1.0

  • ActiveMQ 5.10.0 -> 5.15.4

  • RabbitMQ 5.x

  • Pulsar 2.2.x -> 2.4.x

    NoSQL

  • Redis

  • Jedis 2.x

  • Redisson Easy Java Redis client 3.5.2+

  • Lettuce 5.x

  • MongoDB Java Driver 2.13-2.14, 3.4.0-3.11.1

  • Memcached Client

  • Spymemcached 2.x

  • Xmemcached 2.x

Elasticsearch

  • transport-client 5.2.x-5.6.x
  • transport-client 6.7.1-6.8.4
  • rest-high-level-client 6.7.1-6.8.4
  • rest-high-level-client 7.0.0-7.5.2
  • Solr
  • SolrJ 7.x
  • Cassandra 3.x
  • cassandra-java-driver 3.7.0-3.7.2

Service Discovery

  • Netflix Eureka
  • Distributed Coordination
  • Zookeeper 3.4.x (Optional² & Except 3.4.4)

Spring Ecosystem

  • Spring Bean annotations(@Bean, @Service, @Component, @Repository) 3.x and 4.x (Optional²)
  • Spring Core Async SuccessCallback/FailureCallback/ListenableFutureCallback 4.x
  • Spring Transaction 4.x and 5.x (Optional²)
  • Hystrix: Latency and Fault Tolerance for Distributed Systems 1.4.20 -> 1.5.12

Scheduler

  • Elastic Job 2.x OpenTracing community supported
  • Canal: Alibaba mysql database binlog incremental subscription & consumer components 1.0.25 -> 1.1.2

JSON

  • GSON 2.8.x (Optional²)
  • Vert.x Ecosystem
  • Vert.x Eventbus 3.2+
  • Vert.x Web 3.x Thread Schedule Framework
  • Spring @Async 4.x and 5.x

Cache

  • Ehcache 2.x

Kotlin

  • Coroutine 1.0.1 -> 1.3.x (Optional²)

软件架构

软件架构说明

1、 log-spring-boot-starter 客户端starter,收集链路日志,通过 log-spring-boot-netty 发送日志给 log-spring-boot-core

2、 log-spring-boot-core 日志核心组件,将收集到的日志异步存入redis 和 es

3、log-spring-boot-netty 网络通信组件,starter 和 core 基于netty进行通信

软件技术栈

1、spring boot

2、skywalking

3、redis

4、es

5、netty

7、kafka

安装教程

  1. xxxx
  2. xxxx
  3. xxxx

使用说明

  1. 安装部署skywalking

linux或者Windows都行 ,下面为Linux

cd /home/data/app/
wget  https://mirror.bit.edu.cn/apache/skywalking/6.6.0/apache-skywalking-apm-es7-6.6.0.tar.gz
tar -xzvf apache-skywalking-apm-es7-6.6.0.tar.gz

2、服务端

2.1 、 application.properties 新增配置

# netty 服务端端口
ddfeiyu.netty.server.port=8082

## 日志redis队列 (注意redis集群模式和单机模式可任意配置一项。如果全部配置,则采用集群ip ,下面实例则为redis集群模式)
# redis集群模式
ddfeiyu.redis.cluster.nodes=10.10.10.1:7001,10.10.10.2:7001,10.10.10.3:7001
ddfeiyu.redis.cluster.max-redirects=5

#redis单机模式
ddfeiyu.redis.host=192.168.0.125
ddfeiyu.redis.port=6379
ddfeiyu.redis.password=
ddfeiyu.redis.database=0
#连接超时时间
ddfeiyu.redis.timeout=6000
#连接池最大连接数,pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。默认值8
ddfeiyu.redis.jedis.pool.max-active=1000
#连接池最大阻塞等待时间(使用负值没有限制),# 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时
ddfeiyu.redis.jedis.pool.max-wait=1000
#连接池中的最大空闲连接,默认值8
ddfeiyu.redis.jedis.pool.max-idle=8
#连接池中的最小空闲连接,默认值0
ddfeiyu.redis.jedis.pool.min-idle=8
  1. 客户端

项目引入例子 ,参考 log-spring-boot-demo

3.1、修改skywalking的agent.config配置 目录: C:\apache-skywalking-apm-6.6.0\apache-skywalking-apm-bin\agent\config\agent.config

collector.backend_service=10.19.93.169:11800

修改collector.backend_service 为skywalking 服务端ip

3.2、VM参数加入如下参数

-javaagent:C:\apache-skywalking-apm-6.6.0\apache-skywalking-apm-bin\agent\skywalking-agent.jar -Dskywalking.agent.service_name=log-demo

3.3、引入依赖

<dependency>
            <groupId>com.ddfeiyu</groupId>
            <artifactId>log-spring-boot-starter</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

3.4 、 application.properties 新增配置

# 显示在全链路日志中的app名称,可根据项目定义
spring.application.name=log-app-demo


## 日志redis队列 (注意redis集群模式和单机模式可任意配置一项。如果全部配置,则采用集群ip ,下面实例则为redis集群模式)
# redis集群模式
ddfeiyu.redis.cluster.nodes=10.10.10.1:7001,10.10.10.2:7001,10.10.10.3:7001
ddfeiyu.redis.cluster.max-redirects=5

#redis单机模式
ddfeiyu.redis.host=192.168.0.125
ddfeiyu.redis.port=6379
ddfeiyu.redis.password=
ddfeiyu.redis.database=0
#连接超时时间
ddfeiyu.redis.timeout=6000
#连接池最大连接数,pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。默认值8
ddfeiyu.redis.jedis.pool.max-active=1000
#连接池最大阻塞等待时间(使用负值没有限制),# 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时
ddfeiyu.redis.jedis.pool.max-wait=1000
#连接池中的最大空闲连接,默认值8
ddfeiyu.redis.jedis.pool.max-idle=8
#连接池中的最小空闲连接,默认值0
ddfeiyu.redis.jedis.pool.min-idle=8

3.5 、打日志:需要打日志的类和方法分别打上如下注解

类上加注解

@EnableTraceLog

方法上加注解

@TraceLog(description = "第一个日志demo")

@Trace

示例如下:

@EnableTraceLog
public class LogController {


    @TraceLog(description = "第一个日志demo")
    @Trace
    @GetMapping("/log")
    public String log(){
        String traceId = TraceContext.traceId();
        log.info("trcaeId: [ {} ]", traceId);
        return traceId;
    }

3.6 、查询全链路日志

我们已经知道链路tarceId,并且日志已经在redis队列中了,那么怎么查询到全链路日志呢, 参考示例

1、下面例子简单模拟获取全链路日志

        @GetMapping("/print")
       public List<String> print(@RequestParam(name = "traceId") String traceId){
           log.info("trcaeId: [ {} ]", traceId);
           List<String> traceLogList = new ArrayList<>();
           String traceLog = "";
           while ((traceLog = redisQueueUtil.dequeue(traceId)) != null){
               log.info("trcaeId: [ {} ], traceLog: [ {} ]", traceId , traceLog);
               traceLogList.add(traceLog);
           }
           return traceLogList;
       }
       

2、其它方式:服务端也可通过websocket方式将日志推送给前端等等

演示

3.1、启动 log-spring-boot-core

3.2 启动 log-spring-boot-demo

3.3. 产生日志

http://localhost:8080/log/log

返回一个tarceId

3.4 查询链路日志

http://localhost:8080/log/print?traceId=549.36.15908961313010001

日志格式:

{
    "app":"log-app-demo",
    "arguments":"[UserDto(userId=方法带注解)]",
    "clazzName":"com.ddfeiyu.service.UserServiceImpl",
    "description":"打上日志TraceLog注解的日志",
    "elapsedTime":0,
    "errorMsg":"",
    "host":"169.254.141.95",
    "logTime":"2020-05-31 11:35:33.369",
    "methodName":"sayHelloWithAnnotation",
    "parameterTypes":"[class com.ddfeiyu.dto.UserDto]",
    "status":"成功",
    "traceId":"549.36.15908961313010001"
}
日志格式说明
{
    "app":"log-app-demo", 应用名称
    "arguments":"[UserDto(userId=方法带注解)]", 方法入参
    "clazzName":"com.ddfeiyu.service.UserServiceImpl", 类名
    "description":"打上日志TraceLog注解的日志", 日志描叙
    "elapsedTime":0,   方法耗时
    "errorMsg":"",     异常消息
    "host":"169.254.141.95",   应用ip
    "logTime":"2020-05-31 11:35:33.369",   日志时间
    "methodName":"sayHelloWithAnnotation", 方法名称
    "parameterTypes":"[class com.ddfeiyu.dto.UserDto]",    入参参数类型
    "status":"成功",  方法执行状态
    "traceId":"549.36.15908961313010001" 链路跟踪id
}

版本计划

1.0 版本(已实现)

    a、增加全链路追踪功能
    b、日志写入redis队列

2.0版本,

    a、优化日志抓取写入,采用高性能无锁队列Disruptor处理日志 https://www.cnblogs.com/aheizi/p/6879931.html
    b、日志写入es做历史日志归档和查询

3.0版本

    a、编写前端页面,提供日志索引管理、日志查询、日志队列管理功能 
    b、抓取链路中db sql,写入日志

6.联系交流

 QQ群: 816929140

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

码云特技

  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. 码云官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解码云上的优秀开源项目
  4. GVP 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
  5. 码云官方提供的使用手册 https://gitee.com/help
  6. 码云封面人物是一档用来展示码云会员风采的栏目 https://gitee.com/gitee-stars/
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

trace-log-spring-boot-starter一个简单易用的java分布式链路跟踪日志组件 一.系统介绍 1、无入侵的分布式日志系统,基于elk搜集日志,采用Skywalking设置链路ID,方便查询关联日志 2、基于elasticsearch作为查询引擎 3、高吞吐,查询效率高 4、支持redis实时日志、es历史日志查询 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/mengfansen/trace-log-spring-boot-starter.git
git@gitee.com:mengfansen/trace-log-spring-boot-starter.git
mengfansen
trace-log-spring-boot-starter
trace-log-spring-boot-starter
master

搜索帮助