-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
RestClient doesn't open a scope for the processing of the request #33397
Comments
@KayWu, I reviewed the restClient exchange call and see that observability is opened there just in a different way. Reviewing the code gives an idea that observability is managed in both places in similar manner just implemented differently. Did you find any specific use case that you could explain for better understanding of your issue? |
Hi @prkksh , DefaultRestClient starts the observation, but not activate the scope in the current thread, while RestTemplate does both things. spring-framework/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java Lines 892 to 904 in 2eff5cb
spring-framework/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java Lines 533 to 544 in 2eff5cb
When observation.openScope() is called, it activates the observation in the current thread, making any code executed later in the same thread aware of this observation. If a new observation is created, the existing observation will be treated as the parent observation. However, if an observation is started but not activated with openScope(), subsequent code execution will not be aware of this observation. I have implemented a ClientHttpRequestInterceptor, which performs some operations that create new observations. Since these operations are executed sequentially, the observations should also be linked together in sequence. This works fine with RestTemplate, but it doesn't work with RestClient because RestClient does not activate the scope, causing these observations to be independent rather than linked. |
PR for this |
RestTemplate opens the scope when handling requests, whereas RestClient does not.
This will cause the custom ClientHttpRequestInterceptor for RestClient to be unable to access the currently active scope within the intercept method.
spring-framework/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java
Line 896 in 2eff5cb
spring-framework/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java
Line 541 in 2eff5cb
The text was updated successfully, but these errors were encountered: