Introduces NullObservation by marcingrzejszczak · Pull Request #3831 · micrometer-metrics/micrometer (original) (raw)

@marcingrzejszczak mentioned this pull request

May 11, 2023

[sonatype-lift[bot]](/apps/sonatype-lift)

jonatan-ivanov

@marcingrzejszczak

…om Reactor and non-Reactor projects are different

with this change we're introducing the NullScope and NullObservation concepts. We always create a scope but we may create a null scope that does nothing except for working on scopes.

@marcingrzejszczak

@marcingrzejszczak

chemicL

@marcingrzejszczak

@izeye izeye mentioned this pull request

Jun 26, 2023

izeye added a commit to izeye/micrometer that referenced this pull request

Jun 26, 2023

@izeye

shakuzen pushed a commit that referenced this pull request

Jun 27, 2023

@izeye

shakuzen added a commit to shakuzen/micrometer that referenced this pull request

Mar 6, 2026

@shakuzen

getEnclosingScope() was added in 1.10.6 (PR micrometer-metrics#3731) so that ObservationThreadLocalAccessor.restore(Observation) could obtain the observation's enclosing scope and call makeCurrent() before setValue().

In 1.10.x (PR micrometer-metrics#3831, NullObservation) the restore logic was changed to use the registry's current scope and getPreviousObservationScope() instead. Since then, getEnclosingScope() has not been used by any production code; the only remaining callers are tests in ObservationThreadLocalAccessorTests.

Deprecating the method is a first step toward removing it and the lastScope field in SimpleObservation, which will reduce per-observation overhead (ConcurrentHashMap field and scope bookkeeping on open/close).

shakuzen added a commit to shakuzen/micrometer that referenced this pull request

Mar 6, 2026

@shakuzen

makeCurrent() was added in 1.10.6 (PR micrometer-metrics#3731) so that ObservationThreadLocalAccessor.restore(Observation) could re-apply an observation's scope when restoring: it called value.getEnclosingScope() then enclosingScope.makeCurrent() before setValue(value).

In 1.10.x (PR micrometer-metrics#3831, NullObservation) the restore logic was changed to use the registry's current scope and closeCurrentScope() instead. Since then, makeCurrent() has not been used by any production code; the only remaining caller is the test CurrentObservationTest.nestedScopes_makeCurrent().

Deprecating the method aligns with the getEnclosingScope() deprecation and allows future removal of the scope-rebuild logic in SimpleScope that exists only to support makeCurrent().

shakuzen added a commit to shakuzen/micrometer that referenced this pull request

Mar 6, 2026

@shakuzen

Scope.reset() was used by ObservationThreadLocalAccessor until 1.10.x (PR micrometer-metrics#3831, NullObservation). That flow called reset() to clear thread locals before making another scope current. After micrometer-metrics#3831, OTLA uses closeCurrentScope() with scope.close() instead, so Scope.reset() is no longer used by any production code; the only remaining caller is ObservationValidatorTests.scopeResetAfterStopShouldBeValid().

ObservationHandler.onScopeReset(Context) is only invoked when Scope.reset() or Scope.makeCurrent() runs. Both are now deprecated and unused in production, so the callback is deprecated as well. Handlers should use onScopeClosed for cleanup when a scope is closed.

Deprecating these aligns with deprecating getEnclosingScope() and Scope.makeCurrent() and allows future removal of the reset/makeCurrent-related code paths.

jonatan-ivanov pushed a commit that referenced this pull request

Mar 9, 2026

@shakuzen

getEnclosingScope() was added in 1.10.6 (PR #3731) so that ObservationThreadLocalAccessor.restore(Observation) could obtain the observation's enclosing scope and call makeCurrent() before setValue().

In 1.10.x (PR #3831, NullObservation) the restore logic was changed to use the registry's current scope and getPreviousObservationScope() instead. Since then, getEnclosingScope() has not been used by any production code; the only remaining callers are tests in ObservationThreadLocalAccessorTests.

Deprecating the method is a first step toward removing it and the lastScope field in SimpleObservation, which will reduce per-observation overhead (ConcurrentHashMap field and scope bookkeeping on open/close).

makeCurrent() was added in 1.10.6 (PR #3731) so that ObservationThreadLocalAccessor.restore(Observation) could re-apply an observation's scope when restoring: it called value.getEnclosingScope() then enclosingScope.makeCurrent() before setValue(value).

In 1.10.x (PR #3831, NullObservation) the restore logic was changed to use the registry's current scope and closeCurrentScope() instead. Since then, makeCurrent() has not been used by any production code; the only remaining caller is the test CurrentObservationTest.nestedScopes_makeCurrent().

Deprecating the method aligns with the getEnclosingScope() deprecation and allows future removal of the scope-rebuild logic in SimpleScope that exists only to support makeCurrent().

Scope.reset() was used by ObservationThreadLocalAccessor until 1.10.x (PR #3831, NullObservation). That flow called reset() to clear thread locals before making another scope current. After #3831, OTLA uses closeCurrentScope() with scope.close() instead, so Scope.reset() is no longer used by any production code; the only remaining caller is ObservationValidatorTests.scopeResetAfterStopShouldBeValid().

ObservationHandler.onScopeReset(Context) is only invoked when Scope.reset() or Scope.makeCurrent() runs. Both are now deprecated and unused in production, so the callback is deprecated as well. Handlers should use onScopeClosed for cleanup when a scope is closed.

Deprecating these aligns with deprecating getEnclosingScope() and Scope.makeCurrent() and allows future removal of the reset/makeCurrent-related code paths.

etrandafir93 pushed a commit to etrandafir93/micrometer that referenced this pull request

Mar 21, 2026

@shakuzen @etrandafir93

getEnclosingScope() was added in 1.10.6 (PR micrometer-metrics#3731) so that ObservationThreadLocalAccessor.restore(Observation) could obtain the observation's enclosing scope and call makeCurrent() before setValue().

In 1.10.x (PR micrometer-metrics#3831, NullObservation) the restore logic was changed to use the registry's current scope and getPreviousObservationScope() instead. Since then, getEnclosingScope() has not been used by any production code; the only remaining callers are tests in ObservationThreadLocalAccessorTests.

Deprecating the method is a first step toward removing it and the lastScope field in SimpleObservation, which will reduce per-observation overhead (ConcurrentHashMap field and scope bookkeeping on open/close).

makeCurrent() was added in 1.10.6 (PR micrometer-metrics#3731) so that ObservationThreadLocalAccessor.restore(Observation) could re-apply an observation's scope when restoring: it called value.getEnclosingScope() then enclosingScope.makeCurrent() before setValue(value).

In 1.10.x (PR micrometer-metrics#3831, NullObservation) the restore logic was changed to use the registry's current scope and closeCurrentScope() instead. Since then, makeCurrent() has not been used by any production code; the only remaining caller is the test CurrentObservationTest.nestedScopes_makeCurrent().

Deprecating the method aligns with the getEnclosingScope() deprecation and allows future removal of the scope-rebuild logic in SimpleScope that exists only to support makeCurrent().

Scope.reset() was used by ObservationThreadLocalAccessor until 1.10.x (PR micrometer-metrics#3831, NullObservation). That flow called reset() to clear thread locals before making another scope current. After micrometer-metrics#3831, OTLA uses closeCurrentScope() with scope.close() instead, so Scope.reset() is no longer used by any production code; the only remaining caller is ObservationValidatorTests.scopeResetAfterStopShouldBeValid().

ObservationHandler.onScopeReset(Context) is only invoked when Scope.reset() or Scope.makeCurrent() runs. Both are now deprecated and unused in production, so the callback is deprecated as well. Handlers should use onScopeClosed for cleanup when a scope is closed.

Deprecating these aligns with deprecating getEnclosingScope() and Scope.makeCurrent() and allows future removal of the reset/makeCurrent-related code paths.

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 }})