Add Scope closing validation to ObservationValidator by seonghyeoklee · Pull Request #7253 · micrometer-metrics/micrometer (original) (raw)
approved these changes Mar 11, 2026
Add two new opt-in validation capabilities for TestObservationRegistry:
SCOPES_SHOULD_BE_CLOSED_IN_REVERSE_ORDER_OF_OPENING: Validates that scopes are closed in LIFO order. If scope A is opened then scope B, scope B must be closed before scope A.
SCOPES_SHOULD_BE_OPENED_AND_CLOSED_ON_THE_SAME_THREAD: Validates that a scope is closed on the same thread it was opened on.
Both validations are opt-in via the TestObservationRegistryBuilder to avoid breaking existing tests in reactive contexts where scope handling may follow different patterns.
Closes micrometer-metricsgh-6329
Signed-off-by: seonghyeoklee dltjdgur327@gmail.com
- Change @SInCE to 1.17.0 for new builder methods
- Add @author Seonghyeok Lee to ObservationValidator
- Fix error message string concatenation
- Rename globalScopeStack to scopedContexts
- Track openingThreadIds only when SAME_THREAD capability is enabled
- Add tests for multiple scope open/close exercising the Deque
Signed-off-by: seonghyeoklee dltjdgur327@gmail.com
etrandafir93 pushed a commit to etrandafir93/micrometer that referenced this pull request
Add two new opt-in validation capabilities for TestObservationRegistry:
SCOPES_SHOULD_BE_CLOSED_IN_REVERSE_ORDER_OF_OPENING: Validates that scopes are closed in LIFO order. If scope A is opened then scope B, scope B must be closed before scope A.
SCOPES_SHOULD_BE_OPENED_AND_CLOSED_ON_THE_SAME_THREAD: Validates that a scope is closed on the same thread it was opened on.
Both validations are opt-in via the TestObservationRegistryBuilder to avoid breaking existing tests in reactive contexts where scope handling may follow different patterns.
Closes micrometer-metricsgh-6329
Signed-off-by: seonghyeoklee dltjdgur327@gmail.com Co-authored-by: Jonatan Ivanov jonatan.ivanov@gmail.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})