alibaba / transmittable-thread-local

📌 a missing Java std lib(simple & 0-dependency) for framework/middleware, provide an enhanced InheritableThreadLocal that transmits values between threads even using thread pooling components.
https://github.com/alibaba/transmittable-thread-local
Apache License 2.0
7.59k stars 1.69k forks source link

Error when pinpoint integrate TtlAgent | pinpoint集成TtlAgent报错 #158

Closed nepoch closed 4 years ago

nepoch commented 4 years ago

Use version:


Error when added TtlAgent.premain (agentArgs, inst); to the startup class of pinpoint. And finally found out:

I tried changing the source code to return null instead of{}, and the program runs normally.


Is there any special purpose for the transform implementation of the TtlTransformer class to return EMPTY_BYTE_ARRAY = {}? Is there any other impact of changing to returning null here?



使用版本


pinpoint的启动类中加入了TtlAgent.premain(agentArgs, inst);后报错,最后排查到:

我试了改源码成返回null而不是{},程序运行正常。


TtlTransformer类的transform实现返回EMPTY_BYTE_ARRAY = {}是有什么特殊用意吗?这里改成返回null会不会有什么其他影响?

oldratlee commented 4 years ago

TtlTransformer类的transform实现返回EMPTY_BYTE_ARRAY = {}』的原因参见 https://github.com/alibaba/transmittable-thread-local/pull/68#issuecomment-232903425

用 empty array 来自代码质量改进的一个pull request #56 你可以从commit log( 4a5b292719a99414d9b46394544dc370bc27653f )里查到。

我看持续集成多jdk版本都是通过的,就接纳了这个pr。 https://github.com/alibaba/transmittable-thread-local/pull/68#issuecomment-232882555

即 使用 empty array 而不是 null,是因为 优的代码实践,且 功能是OK的(JDK Agent有效支持)。


从你提供的问题来看,使用pinpoint,并不能,像使用JDK Agent一样,有效支持empty array的返回。

我改一下,发一个新版本。 @nepoch

oldratlee commented 4 years ago

已发布了 v2.11.1https://github.com/alibaba/transmittable-thread-local/releases/tag/v2.11.1


@nepoch 使用新版本测试一下,是不是 OK了? ❤️

nepoch commented 4 years ago

已发布了 v2.11.1https://github.com/alibaba/transmittable-thread-local/releases/tag/v2.11.1

@nepoch 使用新版本测试一下,是不是 OK了? ❤️

@oldratlee 更新后测试正常,谢谢啦。

hoverwinter commented 4 years ago

@nepoch pinpoint已经支持了异步上下文透传,你们的使用场景方便告诉一下么?

为了传递业务上的 ThreadLocal 而非 tracing 的 threadlocal 么?

nepoch commented 4 years ago

@nepoch pinpoint已经支持了异步上下文透传,你们的使用场景方便告诉一下么?

为了传递业务上的 ThreadLocal 而非 tracing 的 threadlocal 么?

嗯嗯,有一些业务数据的传递。而且在线程池场景下也要拿到业务数据。我测试了pinpoint1.8.1版本,在使用线程池情况下也拿不到trx_id,所以直接集成了TTL。

superbool commented 4 years ago

@nepoch pinpoint已经支持了异步上下文透传,你们的使用场景方便告诉一下么?

为了传递业务上的 ThreadLocal 而非 tracing 的 threadlocal 么?

@hoverwinter 我们想在日志中记录每个请求的trace_id来实现日志全链路查询等功能,但pinpoint采样后,有些请求的trx_id没有,以及跨线程也会断掉。

所以我们就想在Pinpoint中集成transmittable-thread-local,来实现跨线程的日志全链路追踪。

不知道您有什么其他好的建议没