-
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
ThreadLocalAccessor API capable of working in scoped scenarios #103
Conversation
This change introduces two new methods: setValue(), and restore(). The first one can be called when entering a scope without a value defined, while the second one allows clearing the ThreadLocal value upon closing a scope when no surrounding ThreadLocal value was captured. This opens the possibility to effectively clear ThreadLocal values if they are missing in the intended scope (either coming from a ContextSnapshot or a Context object, acted upon by the ContextAccessor).
…Value in test classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, but I'm thinking we should keep reset()
. See comment under reset()
.
context-propagation/src/main/java/io/micrometer/context/ThreadLocalAccessor.java
Outdated
Show resolved
Hide resolved
context-propagation/src/main/java/io/micrometer/context/ThreadLocalAccessor.java
Show resolved
Hide resolved
context-propagation/src/main/java/io/micrometer/context/ThreadLocalAccessor.java
Show resolved
Hide resolved
@rstoyanchev regarding the recent comments, to gather the feedback in one place: With the suggestion to keep Let's assume
There is never a need for 3 methods. However, A is obvious: just implement With B: Ignore Thus, my suggestion is to get rid of The end API for writing to ThreadLocal would be the following:
|
@chemicL, I like the direction, more optimal for both basic and scope-aware style usage. Effectively, The only thing I don't like is that Perhaps introducing a new setValue(nonNullValue)
restore(nonNullValue)
reset(boolean) |
After a further discussion offline, we'll stick with a design more explicit about scope awareness. After all that's how those methods are used, and the contract would make that more clear, as the PR is currently with
|
This change introduces two new methods:
setValue()
, andrestore()
.The first one can be called when entering a scope without a value defined,
while the second one allows clearing the
ThreadLocal
value upon closing a scopewhen no surrounding
ThreadLocal
value was captured. This opens the possibilityto effectively clear
ThreadLocal
values if they are missing in the intendedscope (either coming from a
ContextSnapshot
or a Context object, acted upon bythe
ContextAccessor
).This PR supersedes #100.