Giter Site home page Giter Site logo

i36lib / autotrace4j Goto Github PK

View Code? Open in Web Editor NEW

This project forked from artlibs/autotrace4j

0.0 0.0 0.0 100 KB

基于ByteBuddy,参考sky walking实现的轻量级、无侵入的日志自动串联跟踪Java Agent

License: Apache License 2.0

Java 99.92% Makefile 0.08%

autotrace4j's Introduction

Auto Trace for Java

Run Tests Maven Central Release License: Apache 2.0

autotrace4j是一个基于ByteBuddy编写的轻量级日志跟踪工具,其基本逻辑是在各个上下文当中通过代码增强关键节点来传递trace id,最后在日志输出时注入到输出结果当中,以实现日志的跟踪串联。

​ 我们借鉴了SkyWalking的实现原理,使用ByteBuddy在各个上下文环节进行关键点增强来传递Trace ID。

易使用

​ 基于Agent的方式来使用该工具,对业务代码无侵入。

轻量级

​ 只依赖ByteBuddy,且增加的增强代码只是往Thread Local当中写入字符串或读出字符串,没有做额外事项,不会增加性能开销。

Startup

autotrace4j的使用非常简单,只需从release中下载最新的agent jar包,在启动脚本中以agent方式运行:

$ java -javaagent=/dir/to/autotrace4j.jar=com.your-domain.biz1.pkg1,com.your-domain.biz2.pkg2 -jar YourJar.jar  # 省略其他无关参数

关于org.slf4j.MDC

可通过slf4j的MDC获取当前上下文的TraceID:

  • 当通过 MDC.get("X-Ato-Span-Id")时返回当前上下文的 SpanId
  • 当通过 MDC.get("X-Ato-P-Span-Id")时返回当前上下文的 ParentSpanId
  • 当通过 MDC.get("X-Ato-Trace-Id")时返回当前上下文的 TraceId

Supported Context

1、Thread

​ 针对Thread进行了增强,在创建线程时支持自动Trace跟踪:

  • java.lang.Thread

2、Thread Pool

​ 基于如下包作为基础的线程池均支持自动Trace跟踪:

  • java.util.concurrent.ThreadPoolExecutor
  • java.util.concurrent.ForkJoinPool
  • java.util.concurrent.ScheduledThreadPoolExecutor

3、Http Client

​ 基于如下几个Client的HTTP请求客户端在发送请求时都会自动将当前上下文的TraceId设置到请求头:

  • OkHttp3:com.squareup.okhttp3:okhttp
  • JDK Http Client:jdk:sun.net.www.http.HttpClient
  • ApacheHttpClient:org.apache.httpcomponents:httpclient

4、Http Servlet

​ 我们支持了HTTP Filter和HTTP Servlet来从请求头当中接收TraceId并设置到当前上下文:

  • javax.servlet.Filter
  • javax.servlet.http.HttpServlet

5、MessageQunue

​ 目前支持阿里云ONS和RocketMQ在生产和消费时带上TraceId:

  • RocektMQ:Producer & Consumer
  • Aliyun ONS:Producer & Consumer
  • Kafka:comming soon....

6、Scheduled Task

​ 已支持XXL Job和Spring的Scheduled定时任务在产生时生成TraceId:

  • XxlJob Handler:com.handler.com.xxl.job.core.IJobHandler
  • Spring Schedule Task:org.springframework.scheduling.annotation.Scheduled

7、Logging

​ 目前支持在logback中输出日志时注入trace id进行输出:

  • logback:ch.qos.logback:logback-core

Contribute

欢迎贡献你的代码,一起完善autotrace4j库!

autotrace4j's People

Contributors

i36lib avatar supervate avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.