Skip to content
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

SB 3.2 - Use Reactor Context-Propagation property #464

Open
nmck257 opened this issue Dec 15, 2023 · 6 comments
Open

SB 3.2 - Use Reactor Context-Propagation property #464

nmck257 opened this issue Dec 15, 2023 · 6 comments
Labels
boot-3.2 good first issue Good for newcomers recipe Recipe requested

Comments

@nmck257
Copy link
Collaborator

nmck257 commented Dec 15, 2023

What problem are you trying to solve?

Use this shiny new property: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes#properties
...as a replacement for calling Hooks.enableAutomaticContextPropagation(); before booting the app, as mentioned in this blog post: https://spring.io/blog/2023/03/30/context-propagation-with-project-reactor-3-unified-bridging-between-reactive#automatic-context-propagation

What precondition(s) should be checked before applying this recipe?

Probably UsesType for Hooks and SpringApplication

Describe the situation before applying the recipe

@SpringBootApplication
public class MyApp{

    public static void main(final String[] args) {
        Hooks.enableAutomaticContextPropagation();
        SpringApplication.run(MyApp.class, args);
    }
}

Describe the situation after applying the recipe

@SpringBootApplication
public class MyApp{

    public static void main(final String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
}

...combined with a spring property addition:

spring:
  reactor:
    context-propagation: auto

Have you considered any alternatives or workarounds?

Any additional context

Are you interested in contributing this recipe to OpenRewrite?

Maybe eventually; eager contributors are welcome to grab it first

@nmck257 nmck257 added the recipe Recipe requested label Dec 15, 2023
@timtebeek timtebeek added good first issue Good for newcomers boot-3.2 labels Dec 15, 2023
@timtebeek
Copy link
Contributor

Seems like a good first issue indeed ; we can have a JavaIsoVisitor return null from visitMethodInvocation when Hooks.enableAutomaticContextPropagation() is found in a @SpringBootApplication main method. Then call doAfterVisit(new AddSpringProperty("spring.reactor.context-propagation", "true", null, null).getVisitor()) to add the property and done. Couple tests and we should be good. Anyone welcome to pick this up!

@nmck257
Copy link
Collaborator Author

nmck257 commented Dec 15, 2023

I think it might have to be a ScanningRecipe, such that it can make the choice to adjust a property file while visiting a java file, but still feels within the realm of a first issue

@Shiroo77
Copy link

Hello, My name is prem and I would like to work on this issue. Is it still active ?

@timtebeek
Copy link
Contributor

Hi! Yes sure; if you open up a draft pull request with the tests I'll assign the issue to you.

@Shiroo77
Copy link

We need to replace the use of Hooks.enableAutomaticContextPropagation() with the spring.reactor.context-propagation property as a part of Spring Boot 3.2 ! I've been searching the entire project to locate the file or code snippet where Hooks.enableAutomaticContextPropagation() is used, but I haven't been successful so far. Could you please provide some guidance on where I should be looking or any specific classes or configurations.

@nmck257
Copy link
Collaborator Author

nmck257 commented Jan 27, 2024

@Shiroo77
The original issue description shows what I believe to be the most common pattern: calling the Hooks... method within main before calling SpringApplication::run. I'm not aware of any common patterns where the method would appear somewhere else; I suspect it may not work properly if applied late in the spring app lifecycle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
boot-3.2 good first issue Good for newcomers recipe Recipe requested
Projects
Status: Recipes Wanted
Development

No branches or pull requests

3 participants