Skip to content

Conversation

@threddy
Copy link
Contributor

@threddy threddy commented Jan 9, 2026

Why?
Existing clean up logic does not work as expected because:
It attempts to cleanup invocation_input and invocation_output attributes, but for invoke_agent spans SK uses input_messages and output_messages
Deserialization fails because it expects a list of strings but actually it is a list of objects of type MessageContent.

What?
Try to filter input_messages and output_messages attributes in addition to existing.
First try to deserialize into a list of objects.

Testing

Without fix
image

Zooming in on input_messages and output_messages
image
image

With fix
image

@threddy threddy requested a review from a team as a code owner January 9, 2026 00:03
Copilot AI review requested due to automatic review settings January 9, 2026 00:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in the observability cleanup logic for auto-instrumented spans from Semantic Kernel. The existing cleanup attempted to filter invocation_input and invocation_output attributes but failed because: (1) SK actually uses input_messages and output_messages attributes for invoke_agent spans, and (2) deserialization expected a list of strings but received a list of MessageContent objects.

Key Changes:

  • Enhanced deserialization to handle JSON arrays of MessageContent objects directly, with fallback to string array format
  • Added filtering support for gen_ai.input.messages and gen_ai.output.messages attributes
  • Refactored code to reduce duplication by introducing a helper overload

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Observability/Extensions/SemanticKernel/Utils/SemanticKernelSpanProcessorHelper.cs Refactored filtering logic to support additional message attribute keys (input_messages, output_messages) and fixed deserialization to handle JSON arrays of objects directly
src/Tests/Microsoft.Agents.A365.Observability.Extension.Tests/SemanticKernelSpanProcessorHelperTests.cs Added test verifying the new deserialization logic correctly handles JSON arrays of MessageContent objects

@threddy threddy changed the title [Observability] Clean up input and output messages from auto-instrumented spans [Observability] Clean up input and output messages from auto-instrumented invoke_agent spans Jan 9, 2026
Copy link

@nikhilNava nikhilNava left a comment

Choose a reason for hiding this comment

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

The ask from the agents activity page team is they want human readable text.
From the images we only require value of the content field e.g "Hello! Before I can ....."

@threddy
Copy link
Contributor Author

threddy commented Jan 9, 2026

The ask from the agents activity page team is they want human readable text. From the images we only require value of the content field e.g "Hello! Before I can ....."

Updated to handle nested content. See new "after fix" screenshot in PR descritpion

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.

3 participants