Skip to content

Fix observationConvention propagation to child chains (#5882)#5886

Open
redinside-dev wants to merge 1 commit intospring-projects:mainfrom
redinside-dev:fix/5882-observation-convention-propagation
Open

Fix observationConvention propagation to child chains (#5882)#5886
redinside-dev wants to merge 1 commit intospring-projects:mainfrom
redinside-dev:fix/5882-observation-convention-propagation

Conversation

@redinside-dev
Copy link
Copy Markdown

Summary

Fixes #5882 - The Advisor executed after ToolCallAdvisor lacks the custom observation convention about 'spring.ai.advisor' span.

Problem

In DefaultAroundAdvisorChain.copyAdvisorsAfter(), when creating child chains for advisors that come after a certain advisor, the observationConvention from the parent chain was not being passed to the child chain builder. This caused subsequent advisors in the chain to lose the custom observation convention.

Solution

Pass this.observationConvention to the builder in copyAdvisorsAfter():

return DefaultAroundAdvisorChain.builder(this.getObservationRegistry())
    .observationConvention(this.observationConvention)  // <-- Added this line
    .pushAll(remainingStreamAdvisors)
    .build();

Changes

  1. DefaultAroundAdvisorChain.java: Added .observationConvention(this.observationConvention) to the builder chain in copyAdvisorsAfter()
  2. DefaultAroundAdvisorChainTests.java: Added 3 tests to verify observation convention preservation:
    • whenCopyingChainWithCustomObservationConventionThenConventionIsPreserved
    • whenCopyingChainWithDefaultObservationConventionThenDefaultIsPreserved
    • whenCopyingStreamChainThenObservationConventionIsPreserved

Testing

All existing tests pass, plus the 3 new tests verify the fix.

…dAdvisorChain

Fixes spring-projects#5882 - The Advisor executed after ToolCallAdvisor lacks the custom
observation convention about 'spring.ai.advisor' span.

The copyAdvisorsAfter() method now passes the parent chain's observationConvention
to the child chain builder, ensuring custom observation conventions are inherited
by child chains.

Added tests to verify:
- Custom observation convention is preserved when copying call chains
- Default observation convention is preserved when copying call chains
- Custom observation convention is preserved when copying stream chains
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The Advisor executed after ToolCallAdvisor lacks the custom observation convention about "spring.ai.advisor" span.

2 participants