Observations not working properly in streaming mode
Author: cijaaimeeCreated May 7, 2026Updated Sep 25, 2026
Labelsstatus: waiting-for-triage
Bug description When using ChatClient's streaming mode, observations are broken in two different ways:
- Observations are stopped in reverse order
- Tool calling observations have
nullparent Environment Spring AI 2.0.0-M5.
Steps to reproduce Sample code to see how it breaks:
@Bean
fun observationRegistryCustomizer() =
ObservationRegistryCustomizer<ObservationRegistry> {
it.observationConfig().observationHandler(LoggingObservationHandler())
}
class LoggingObservationHandler : ObservationHandler<Observation.Context> {
override fun supportsContext(context: Observation.Context) = true
private val logger = LoggerFactory.getLogger(javaClass)
override fun onStart(context: Observation.Context) {
logger.info(
"start ${context.name ?: context.javaClass.name} with parent ${context.parentObservation?.contextView?.name ?: context.parentObservation?.contextView?.javaClass?.name}")
super.onStart(context)
}
override fun onStop(context: Observation.Context) {
logger.info("stop ${context.name ?: context.javaClass.name}")
}
}You'll see something like this:
start spring.ai.chat.client with parent <something>
start spring.ai.advisor with parent spring.ai.chat.client
start gen_ai.client.operation with parent spring.ai.advisor
start spring.ai.tool with parent null
stop spring.ai.tool
start gen_ai.client.operation with parent gen_ai.client.operation
stop gen_ai.client.operation
stop gen_ai.client.operation
stop spring.ai.chat.client
stop spring.ai.advisorNotice how (1) spring.ai.tool has no parent, and (2) observations are stopped in reverse order
Expected behavior With the example above, we should be seeing this:
start spring.ai.chat.client with parent <something>
start spring.ai.advisor with parent spring.ai.chat.client
start gen_ai.client.operation with parent spring.ai.advisor
stop gen_ai.client.operation
start spring.ai.tool with parent spring.ai.advisor
stop spring.ai.tool
start gen_ai.client.operation with parent gen_ai.client.operation
stop gen_ai.client.operation
stop spring.ai.advisor
stop spring.ai.chat.clientSource: spring-projects/spring-ai