Skip to content

Conversation

chemicL
Copy link
Collaborator

@chemicL chemicL commented Feb 9, 2023

Recent change to ContextSnapshot#setThreadLocals() method allows to clear ThreadLocal values not present in the snapshot.

The associated change to ContextSnapshot.setAllThreadLocalsFrom(sourceContext) should be on par with ContextSnapshot.captureAll(...) followed by ContextSnapshot#setThreadLocals() but avoiding the temporary snapshot container.

Unfortunately, the method clears existing ThreadLocal values that are not present in the sourceContext object and creates a mismatch in the vocabulary.

The previous behaviour is restored for that static method.

Instead, two new static methods are introduced:

  • ContextSnapshot.setThreadLocals(Object)
  • ContextSnapshot.setThreadLocals(Object, ContextRegistry)

that allow to skip the temporary container and clear ThreadLocal values not present in the sourceContext provided and set only the present ones.

@sonatype-lift
Copy link

sonatype-lift bot commented Feb 9, 2023

🛠 Lift Auto-fix

Some 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/73.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/73.diff | git apply

Once you're satisfied, commit and push your changes in your project.

Footnotes

  1. You can preview the patch by opening the patch URL in the browser.

chemicL pushed a commit to reactor/reactor-core that referenced this pull request Feb 10, 2023
Recent change to `ContextSnapshot#setThreadLocals()` method
allows to clear `ThreadLocal` values not present in the snapshot.

The associated change to `ContextSnapshot.setAllThreadLocalsFrom(sourceContext)`
should be on par with `ContextSnapshot.captureAll(...)` followed by
`ContextSnapshot#setThreadLocals()` but avoiding the temporary snapshot container.

Unfortunately, the method clears existing `ThreadLocal` values that
are not present in the sourceContext object and creates a mismatch in the vocabulary.

The previous behaviour is restored for that static method.

Instead, two new static methods are introduced:

- `ContextSnapshot.setThreadLocals(Object)`
- `ContextSnapshot.setThreadLocals(Object, ContextRegistry)`

that allow to skip the temporary container and clear `ThreadLocal`
values not present in the sourceContext provided and set only the
present ones.
@chemicL chemicL force-pushed the unify-vocabulary-fix-setallthreadlocalsfrom branch from 18e0306 to aacbb3c Compare February 10, 2023 00:39
@chemicL chemicL changed the title Unifying ContextSnapshot vocabulary and fixing setAllThreadLocalsFrom [HOLD] Unifying ContextSnapshot vocabulary and fixing setAllThreadLocalsFrom Feb 13, 2023
@chemicL
Copy link
Collaborator Author

chemicL commented Feb 13, 2023

Putting on hold. #74 reverts the previous functionality. This PR should serve as basis for a unification of the API and brining the choice to clear ThreadLocal values that are not present in a source context object vs only setting present values and ignoring others. Both scenarios have their place in application usage patterns and the API should allow an informed interaction.

@jonatan-ivanov jonatan-ivanov marked this pull request as draft February 13, 2023 18:37
@jonatan-ivanov jonatan-ivanov added the bug A general bug label Feb 13, 2023
@jonatan-ivanov jonatan-ivanov added this to the 1.0.3 milestone Feb 13, 2023
@jonatan-ivanov jonatan-ivanov modified the milestones: 1.0.3, 1.0.x Mar 10, 2023
@chemicL
Copy link
Collaborator Author

chemicL commented May 26, 2023

Closing this one in favour of #105.

@chemicL chemicL closed this May 26, 2023
@chemicL chemicL removed this from the 1.0.x milestone Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants