-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why ContextExecutorService#wrap is deprecated? #295
Comments
There are a few configurable items there and your application needs to make informed decisions. Specifically, the deprecated method used the global |
the library doesn't make it easy to shoot oneself in the foot, but encourage clients to play with loaded gun. Actually, when client wants simply pass context to task from executor service, the library encounters him to implement Then developer digs into library code, scans SO and finds There's no obvious answer. No. Obvious answer is
Considering all above, my proposal is modify ContextExecutorService#wrap(ExecutorService) to use default snapshot builder and clean up deprecation |
IIRC the deprecation came from @rstoyanchev's suggestion in #105 (comment) and I agree. This API is not for simply wrapping tasks but for wrapping an entire
It actually does matter quite a lot, that's why the configuration is there. A real life fundamental problem in context propagation in reactive applications has dictated the API to evolve in this direction. This should also be of interest as it seems your application is going to run Java's Stream API on a shared executor. One task might have a value and another might not. This can lead to leakages and for instance show unexpected identifiers in unrelated work units. Ignorance of this aspect is something that we specifically want to prevent. As to the loaded gun analogy - correct, you decided to work with a complicated scenario, better understand the considerations. The context-propagation library is a low-level detail mostly meant for use in library code, not necessarily by end users. Regarding the other enumerated points, I agree. Not on the clearing missing values though. @michaldo please refrain from opening PRs until the discussion is settled. Unless @rstoyanchev changed his opinion, I'd leave the API as is. |
Let's start with this: I never want use low-level API in business code. Please answer here or here https://stackoverflow.com/questions/78746378/spring-boot-3-micrometer-tracing-in-mdc/78765658#78765658 About "clearing missing". I don't know 100% what should be default: true or false. Clearing missing may be important in real life reactive applications. From my perspective, reactive is outdated by virtual threads. For virtual threads clearing missing issue does not exists. It means considering clearing missing is dead end and I'm happy with any choice about default value. Finally, I think that one PR is worth more than thousand words I never hesistate clarify discussion with PR |
Thanks for raising this. I can see how it's not very obvious what to do, but as @chemicL pointed out, there are important choices to understand. The global That said, I think there is room for improvement. We could add an alternative wrap method that is a more friendly place to start: public static ExecutorService wrap(ExecutorService service, ContextSnapshotFactory snapshotFactory) {
return new ContextExecutorService<>(service, snapshotFactory::captureAll);
} This should make it more obvious what you need to provide, and the choices you need to consider. We can also update the Javadoc of the other Also a good time to use this opportunity to review the Javadoc on |
Friendly alternative would be for me something like
Because what I really want is pass high level |
The context-propagation library is at a lower level, and has no knowledge of ContextExecutorService.wrap(executorService, Observation.SNAPSHOT_FACTORY); |
Good idea, but maybe better:
|
As developer, I would like parallelize my code and observe subtasks (https://stackoverflow.com/questions/78746378/spring-boot-3-micrometer-tracing-in-mdc/78765658#78765658 https://stackoverflow.com/questions/78889603/traceid-propagation-to-virtual-thread). I found solution with `ContextExecutorService`, but according to discussion micrometer-metrics/context-propagation#295, ContextExecutorService is low level API, which should not be used by application code. `Observation` is enough high level to be used by application code.
@michaldo the As @rstoyanchev suggested, I added a PR to improve the API to be more intuitive (accepts a |
I'm courious the following: As I understand this discussion, default method |
The mechanism in reactor-core is specifically designed for reactive chains where Threads are reused to perform unrelated tasks from different chains. That's why the For instance in one layer a Actually you touched on a very important aspect for which this flag exists. The previous default when this flag was not there was to not clear any values for missing keys in a provided context. That led to leaks. Fixing that "sane default" impact was quite an undertaking on both Reactor and Micrometer teams :) Since context-propagation is agnostic of where it's going to be used it can not come up with a default as each case will be different. In case of Virtual Threads it might not play a role whether you clear missing values, while for wrapping a I think with the improvements suggested by @rstoyanchev that were added via #305 we can now close this issue. Having in mind the above explanation, I don't feel providing an easier way to propagate generic contexts would be helpful. The risks are more concerning. |
I would like to parallelize IO task and I would like pass current observation to tasks. I found solution here: https://stackoverflow.com/a/78765658/2365727
There are 2 signatures of method ContextExecutorService.wrap(). One simple, intuitive and works for me and second is more complex but allows deeper customization.
Up to these point everything is perfect. Library allows simplified usage with default settings and powerful usage with full customization.
But default usage is deprecated. Why?
The text was updated successfully, but these errors were encountered: