I'm using the spring-cloud-stream-binder-kafka library to handle messages exchanged in the microservices environment and I notice a problem with micrometer.observation after migration from the spring-boot 3.0.8 to the spring-boot 3.0.9. The problem is that before migration to the new version of spring-boot observation in the DefaultContextSnapshot was:
DefaultContextSnapshot{micrometer.observation={name=spring.kafka.listener(null), error=null, context=name='spring.kafka.listener', contextualName='null', error='null', lowCardinalityKeyValues=[spring.kafka.listener.id='KafkaConsumerDestination{consumerDestinationName='imports', partitions=0, dlqName='null'}.container-0'], highCardinalityKeyValues=[], map=[class io.micrometer.tracing.handler.TracingObservationHandler$TracingContext='TracingContext{span=034454cb4028249c/12383094dbb9d45f}', class io.micrometer.core.instrument.LongTaskTimer$Sample='SampleImpl{duration(seconds)=0.037845493, duration(nanos)=3.7845493E7, startTimeNanos=875018915299938}', class io.micrometer.core.instrument.Timer$Sample='io.micrometer.core.instrument.Timer$Sample@304a6057'], parentObservation=null}}
but after migration is:
DefaultContextSnapshot{micrometer.observation=io.micrometer.observation.NoopObservation@2b82b510}
I get DefaultContextSnapshot to be printed as follows:
final ContextSnapshotFactory SNAPSHOT_FACTORY = ContextSnapshotFactory.builder()
.contextRegistry(ContextRegistry.getInstance())
.clearMissing(false)
.captureKeyPredicate(key -> true)
.build();
final ContextSnapshot context = SNAPSHOT_FACTORY.captureAll();
System.out.println("Context snapshot: " + context);
Comment From: wilkinsona
This sounds quite similar to https://github.com/spring-projects/spring-boot/issues/36592. Does the problem remain if you downgrade to Micrometer 1.10.8?
Comment From: maslailleron
I checked and it is a problem with the micrometer library version 1.0.9. After downgrading the micrometer lib to the version 1.0.8 and using spring-boot 3.0.9 the problem doesn't occur.
Thanks !
Comment From: scottfrederick
@maslailleron Thanks for following up and letting us know.
Comment From: jonatan-ivanov
Updating this issue with the results of investigating this in Micrometer: https://github.com/micrometer-metrics/micrometer/issues/4002 if anyone bumps into it:
TL;DR: An issue was fixed in Micrometer/Reactor that kept scopes open even if they should have been closed. This issue was fixed in Micrometer 1.10.9 and now users see the intended behavior of Spring Cloud Stream (closing the scope before executing the user-provided function instead of keeping the scope open). So in Micrometer 1.10.9 and Spring Cloud Stream this works as intended and if one wants to change this behavior they should open a new issue for Spring Cloud Stream and request this feature.