-
Notifications
You must be signed in to change notification settings - Fork 950
.NET: Add LoggingAgent wrapper for ILogger-based observability #2701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: rogerbarreto <[email protected]>
…ling Co-authored-by: rogerbarreto <[email protected]>
Co-authored-by: rogerbarreto <[email protected]>
|
@copilot Formatting failing with the following: |
Co-authored-by: rogerbarreto <[email protected]>
There was a problem hiding this 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 introduces a LoggingAgent wrapper class that provides ILogger-based observability for AI agent operations, following the same decorator pattern as OpenTelemetryAgent. The implementation enables comprehensive logging of agent interactions with configurable detail levels and graceful error handling.
Key Changes:
- Implements
LoggingAgentas aDelegatingAIAgentwith configurable JSON serialization and multi-level logging (Debug/Trace/Error) - Adds
UseLoggingextension method toAIAgentBuilderwith automatic NullLoggerFactory detection for performance optimization - Provides comprehensive test coverage with 18 new unit tests covering all scenarios
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/LoggingAgent.cs | New sealed class implementing agent operation logging with LoggerMessage source generation, supporting Debug (invocations/completions), Trace (sensitive data), and Error (failures) levels |
| dotnet/src/Microsoft.Agents.AI/AIAgentBuilderExtensions.cs | Adds UseLogging extension method with service provider resolution, NullLoggerFactory optimization, and optional configuration callback |
| dotnet/src/Microsoft.Agents.AI/Microsoft.Agents.AI.csproj | Adds Microsoft.Extensions.Logging.Abstractions package reference |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/LoggingAgentTests.cs | Comprehensive unit tests for LoggingAgent covering constructor validation, property delegation, logging behavior at different levels, and error/cancellation scenarios |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/LoggingAIAgentBuilderExtensionsTests.cs | Unit tests for UseLogging extension method covering null validation, logger factory resolution, configuration callbacks, builder chaining, and NullLoggerFactory optimization |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/Microsoft.Agents.AI.UnitTests.csproj | Adds Microsoft.Extensions.Logging package reference for testing |
* Initial plan * Add LoggingAgent class and UseLogging extension method Co-authored-by: rogerbarreto <[email protected]> * Add unit tests for LoggingAgent and fix JSON serialization error handling Co-authored-by: rogerbarreto <[email protected]> * Add comments explaining unreachable code in test async iterators Co-authored-by: rogerbarreto <[email protected]> * Fix file encoding - add UTF-8 BOM to all C# files Co-authored-by: rogerbarreto <[email protected]> * Address Format issues * Addres format * Break up extensions in dedicated files * Adjust class names * Add xmldoc info --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: rogerbarreto <[email protected]>
Implementation Complete for LoggingAgent ✅
LoggingAgentclass extendingDelegatingAIAgentsimilar toOpenTelemetryAgentAIAgentandILoggerRunAsyncmethod with loggingRunStreamingAsyncmethod with loggingAIAgentBuilderExtensions.UseLoggingextension methodILoggerFactoryparameterLoggingAgentRunAsynclogging behaviorRunStreamingAsynclogging behaviorUseLoggingbuilder extensionSummary
Successfully implemented LoggingAgent wrapper following the OpenTelemetryAgent pattern. The implementation provides:
All existing tests continue to pass, ensuring no breaking changes were introduced.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.