Using context-propagation with a no-op Observation corrupts the current Observation (original) (raw)

Describe the bug
After upgrade to Spring Boot 4, application log is full of these warnings (abridged):

2026-02-15T15:23:03.414+01:00  WARN 4561 --- [           main] i.m.o.c.ObservationThreadLocalAccessor   : There is no current scope in thread local. This situation should not happen
2026-02-15T15:23:03.414+01:00  WARN 4561 --- [           main] i.m.o.c.ObservationThreadLocalAccessor   : Observation <...> to which we're restoring is not the same as the one set as this scope's parent observation <null>. Most likely a manually created Observation has a scope opened that was never closed. This may lead to thread polluting and memory leaks.

Environment
I have created a minimal Spring Boot application that demonstrates the issue:
https://github.com/podlesh/micrometer-log-spam

In particular, the following is necessary for issue to appear:

To Reproduce
Clone the demo repository and run the app

Expected behavior
No such warning should happen.

Additional context
After some digging and code analysis, I have concluded that the replacement of null values by "noop" ones breaks compatibility with https://github.com/micrometer-metrics/context-propagation/blob/main/context-propagation/src/main/java/io/micrometer/context/DefaultContextSnapshotFactory.java