java-okhttp icon indicating copy to clipboard operation
java-okhttp copied to clipboard

Clarification on "multiple async requests simultaneously" deficiency in TracingInterceptor

Open william-tran opened this issue 5 years ago • 3 comments

When using TracingInterceptor:

when doing multiple async requests simultaneously, parent spans created before invoking the client are not properly inferred.

Does this effect auto-instrumentation projects like java-specialagent and the new opentelemetry-java-instrumentation? Specialagent appends the TracingInterceptor to the return value whenever OkHttpClient.interceptors() and OkHttpClient.networkInterceptors() are called. The OTel project instruments at the OkHttpClient(OkHttpClient.Builder) constructor by adding its own TracingInterceptor to the Builder.

william-tran avatar Aug 11 '20 13:08 william-tran

Does this effect auto-instrumentation projects like java-specialagent and the new opentelemetry-java-instrumentation?

Could you please clarify? If you want to use just the agents then raise the issue there. I don't know if they use this instrumentation or not.

pavolloffay avatar Aug 12 '20 09:08 pavolloffay

As I described above, those agent projects do use this instrumentation or something that looks like it. But I should rephrase my question. Let's say I'm a contributor to those projects and I notice your note "when doing multiple async requests simultaneously..." and I think "well it looks like we have a problem". I'm trying to understand why there is a problem, the mechanism behind it, and how you came about your conclusion. The way these agents work and the way the OKHttp API works make it difficult to use TracingCallFactory in a way that's transparent to the application code, and its not obvious to my why using TracingInterceptor could be a problem in multiple async requests, assuming the span context correctly propagates from the caller thread to the executor thread.

william-tran avatar Aug 21 '20 12:08 william-tran

I don't exactly remember why, but the brave documents the same problem https://github.com/openzipkin/brave/tree/master/instrumentation/okhttp3#tracinginterceptor

Maybe this test could help you understand the problem https://github.com/opentracing-contrib/java-okhttp/blob/master/opentracing-okhttp3/src/test/java/io/opentracing/contrib/okhttp3/TracingInterceptorTest.java#L20

pavolloffay avatar Aug 21 '20 15:08 pavolloffay