Skip to content

Conversation

ThomasVitale
Copy link
Contributor

  • Add possibility to provide a custom AdvisorObservationConvention to the ChatClient for customizing the conventions for advisor spans and metrics.
  • Add ChatClientResponse to ChatClientObservationContext for achiving full visibility into both request and response.

* Add possibility to provide a custom AdvisorObservationConvention to the ChatClient for customizing the conventions for advisor spans and metrics.
* Add ChatClientResponse to ChatClientObservationContext for achiving full visibility into both request and response.

Signed-off-by: Thomas Vitale <[email protected]>
@ThomasVitale ThomasVitale force-pushed the gh-missing-observations-chat-client branch from e53bac4 to 0f61161 Compare September 9, 2025 20:45
@markpollack markpollack self-assigned this Sep 11, 2025
@markpollack
Copy link
Member

@jonatan-ivanov could you review this?

Comment on lines +85 to +93
@Nullable
public ChatClientResponse getChatClientResponse() {
return this.chatClientResponse;
}

public void setChatClientResponse(@Nullable ChatClientResponse chatClientResponse) {
this.chatClientResponse = chatClientResponse;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work in the streaming (Reactor) scenario.
Maybe we should fix that first in a separate PR (along with the logging use-case), I have a PoC for that: main...jonatan-ivanov:spring-ai:promt-on-span

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both the ChatClient and Advisor observation contexts don't get the response populated at the moment, for the reactive scenarios.

I didn't to that here since I don't feel comfortable making changes via the reactor context propagation.

So it would be great if it could be added in a separate PR, thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ChatClientResponse was already part of the AdvisorObservationContext, but it was never populated. In this PR, I made a change to populate it in non-streaming scenarios.

And for consistency, I've done the same for ChatClientObservationContext.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this? #4417
The interesting part is small, see: DefaultChatClient and ChatClientObservationContext. This PR could depend on this and we can also re-use this in the prompt/completion on spans scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing! I checked the PR and looks good to me. The only comment I left is about the ChatClientObservationContext: #4417 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you agree with that comment, I would suggest having that PR build on this one, adding support for the reactive scenario and completion logs.

@ilayaperumalg ilayaperumalg modified the milestones: 1.1.0.M2, 1.1.0.M3 Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants