You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-Use Rougamo-based logging attribute to captures method exception details, parameters, and BotSharp-specific context.
-This attribute can be used across all BotSharp plugins for consistent function logging.
PR Type
Enhancement
Description
Add Rougamo-based exception logging attribute for BotSharp functions
Captures method exceptions with context details and parameters
Provides consistent logging across all BotSharp plugins
Extracts conversation, agent, and function metadata automatically
Diagram Walkthrough
flowchart LR
A["Method Exception"] --> B["FnExceptionLogAttribute"]
B --> C["Extract Logger"]
B --> D["Extract Function Context"]
C --> E["Log Error Details"]
D --> E
E --> F["Structured Log Output"]
Loading
File Walkthrough
Relevant files
Enhancement
FnExceptionLogAttribute.cs
Add comprehensive function exception logging attribute
Here are some key observations to aid the review process:
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 Security concerns
Sensitive information exposure: Serializing and logging method arguments (including RoleDialogModel content and arbitrary objects via JsonSerializer) can leak PII or secrets into logs. Add redaction, opt-in fields, maximum length truncation, and type-based exclusions.
The code references types like ILogger, ILoggerFactory, RoleDialogModel, and JsonSerializer without visible using directives. Ensure required namespaces are imported to avoid build errors.
Reflection-based logger/service provider retrieval may be brittle and costly. Consider caching results or supporting DI via constructor to avoid reflection on every exception path.
Argument serialization may log sensitive data (e.g., RoleDialogModel content). Provide redaction/whitelisting or size limits to prevent leaking PII and overly large logs.
Logging full method arguments (including RoleDialogModel.Content) by default risks leaking PII/secrets and can serialize large/complex objects, causing performance issues. Make argument logging opt-in with redaction/truncation and type filters (e.g., skip streams/byte arrays), and allow whitelisting of safe fields instead of serializing entire objects. Provide configuration to cap sizes and mask known sensitive keys (token, password, content), and only log user message content when explicitly enabled.
publicclassFnExceptionLogAttribute:AsyncMoAttribute{privatereadonlybool_logArguments;publicFnExceptionLogAttribute(boollogArguments=true)// Logging is ON by default{_logArguments=logArguments;}privatestringGetArgumentSummary(objectarg){if(argisRoleDialogModelmessage){// Logs full content, which can be PIIreturn$"RoleDialogModel(Role: {message.Role}, Content: {message.Content})";}// Serializes any other object to JSON, risking secret leaksreturnJsonSerializer.Serialize(arg);}}
After:
publicclassFnExceptionLogAttribute:AsyncMoAttribute{privatereadonlybool_logArguments;publicFnExceptionLogAttribute(boollogArguments=false)// Logging is OFF by default{_logArguments=logArguments;}privatestringGetArgumentSummary(objectarg){if(argisStream)return"[omitted stream]";if(argisRoleDialogModelmessage){// Content is redacted by defaultreturn$"RoleDialogModel(Role: {message.Role}, Content: [redacted])";}// Use a safe serializer that redacts sensitive keys and truncates long valuesreturnSafeJsonSerializer.Serialize(arg);}}
Suggestion importance[1-10]: 9
__
Why: This suggestion addresses a critical security and performance flaw where logging is enabled by default, potentially exposing PII and sensitive data from arguments like RoleDialogModel.Content.
High
Security
Configure JSON serialization safely
Using JsonSerializer without proper configuration can cause circular reference exceptions or expose sensitive data. Add serialization options to prevent these issues and limit output size for logging.
Why: This suggestion prevents potential JsonException due to circular references by correctly configuring the serializer, significantly improving the robustness of the argument logging feature.
Medium
General
Check properties for logger instances
The reflection search should also check properties in addition to fields, as many classes expose loggers through properties rather than fields. This ensures broader compatibility with different logging patterns.
Why: The suggestion correctly identifies that the logger discovery mechanism is incomplete by only searching for fields; extending the search to properties makes the attribute more robust and widely applicable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
-Use Rougamo-based logging attribute to captures method exception details, parameters, and BotSharp-specific context.
-This attribute can be used across all BotSharp plugins for consistent function logging.
PR Type
Enhancement
Description
Add Rougamo-based exception logging attribute for BotSharp functions
Captures method exceptions with context details and parameters
Provides consistent logging across all BotSharp plugins
Extracts conversation, agent, and function metadata automatically
Diagram Walkthrough
File Walkthrough
FnExceptionLogAttribute.cs
Add comprehensive function exception logging attributesrc/Infrastructure/BotSharp.Core/Infrastructures/LogAttributes/FnExceptionLogAttribute.cs