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
Introducing ContextSnapshotFactory #105
Conversation
context-propagation/src/main/java/io/micrometer/context/ContextSnapshotFactory.java
Outdated
Show resolved
Hide resolved
context-propagation/src/main/java/io/micrometer/context/DefaultContextSnapshot.java
Outdated
Show resolved
Hide resolved
🛠 Lift Auto-fixSome of the Lift findings in this PR can be automatically fixed. You can download and apply these changes in your local project directory of your branch to review the suggestions before committing.1 # Download the patch
curl https://lift.sonatype.com/api/patch/github.com/micrometer-metrics/context-propagation/105.diff -o lift-autofixes.diff
# Apply the patch with git
git apply lift-autofixes.diff
# Review the changes
git diff Want it all in a single command? Open a terminal in your project's directory and copy and paste the following command: curl https://lift.sonatype.com/api/patch/github.com/micrometer-metrics/context-propagation/105.diff | git apply Once you're satisfied, commit and push your changes in your project. Footnotes |
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.
Maybe we can take the opportunity to streamline the API a little.
For a start, I think we can collect a keyPredicate
in the builder, in effect expecting the factory to be pre-configured with it rather than having them passed in. Capturing tends to be a lot more fixed and inclusive, so I expect this should be just fine.
Then for the methods:
ContextSnapshot capture(Object... contexts);
ContextSnapshot captureFromContext(Object... contexts);
<C> ContextSnapshot.Scope setThreadLocalsFrom(Object sourceContext, String... keys);
For setThreadLocalsFrom
if the keys
is empty, set all.
@rstoyanchev thanks for the suggestion. I applied the change to the draft, let me know your thoughts. Keep in mind the |
context-propagation/src/main/java/io/micrometer/context/ContextSnapshotFactory.java
Outdated
Show resolved
Hide resolved
context-propagation/src/main/java/io/micrometer/context/DefaultContextSnapshotFactory.java
Outdated
Show resolved
Hide resolved
context-propagation/src/main/java/io/micrometer/context/ContextSnapshotFactory.java
Outdated
Show resolved
Hide resolved
context-propagation/src/main/java/io/micrometer/context/ContextSnapshotFactory.java
Outdated
Show resolved
Hide resolved
One more thing, I see the |
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.
Thanks for applying the changes.
I think there may be some further opportunity to consolidate logic across the setThreadLocals
methods, but to minimize moving parts, we can keep it at that for now, and try another pass after the PR is in.
Some minor code ordering comments below.
context-propagation/src/main/java/io/micrometer/context/DefaultContextSnapshotFactory.java
Show resolved
Hide resolved
context-propagation/src/main/java/io/micrometer/context/DefaultContextSnapshot.java
Show resolved
Hide resolved
context-propagation/src/main/java/io/micrometer/context/DefaultContextSnapshotFactory.java
Outdated
Show resolved
Hide resolved
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. Some minor suggestions below.
context-propagation/src/main/java/io/micrometer/context/ContextExecutorService.java
Outdated
Show resolved
Hide resolved
context-propagation/src/main/java/io/micrometer/context/ContextScheduledExecutorService.java
Outdated
Show resolved
Hide resolved
context-propagation/src/main/java/io/micrometer/context/ContextSnapshotFactory.java
Outdated
Show resolved
Hide resolved
…tSnapshotFactory.java Co-authored-by: Rossen Stoyanchev <rstoyanchev@users.noreply.github.com>
This change is mainly allowing clearing ThreadLocals upon scope enter.
There are however more changes to the API: