jakartaee / rest

Jakarta RESTful Web Services
Other
361 stars 117 forks source link

Context propagation for async client #668

Open pavolloffay opened 6 years ago

pavolloffay commented 6 years ago

A JAX-RS provider can depend on context propagation. This context is propagated betewen threads via thread locals. An example use of such context can be found in tracing integration.

Parent tracing context e.g. one which represents server request has to be available in client filter when creating an outbound request in order to wire them together. At the moment this is typically done by wrapping executor service into something like https://github.com/opentracing-contrib/java-concurrent#configuration. In JAX-RS this is needed because client filter can be invoked in a different thread.

https://github.com/eclipse-ee4j/jaxrs-api/issues/596 introduces SPI to automatically register client features which is great but we still need a reliable way to propagate context to features.

The discussion started in https://github.com/eclipse-ee4j/jaxrs-api/issues/596#issuecomment-424017545

FroMage commented 5 years ago

That sounds related to MP-Concurrency which provides context propagation, based in part on what RESTEasy does with Reactive Contexts, where contexts are propagated automatically to RxJava pipelines for server endpoints.

Client context propagation should also be supported, I agree.

pavolloffay commented 5 years ago

Is jax-rs going to use mp-concurrency? My main request here is to make sure that context is propagated to providers e.g. filters/interceptors. That is the place where tracing integration needs access to the context.

arjantijms commented 5 years ago

My guess (but I don't know), is that it would use ee-concurrency.

pavolloffay commented 5 years ago

https://github.com/eclipse-ee4j/concurrency-api this one?

FroMage commented 5 years ago

Is jax-rs going to use mp-concurrency?

I can't answer that, but RESTEasy already does use a similar context propagation and that currently extends to filters/interceptors. When MP-Concurrency is out, RESTEasy will support it.

EE-Concurrency does not support context propagation ATM. I don't know if it plans to.