-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
.Net: Improve logging for function calls processor and kernel function #9495
base: main
Are you sure you want to change the base?
Conversation
@@ -23,45 +23,46 @@ internal static partial class KernelFunctionLogMessages | |||
[LoggerMessage( | |||
EventId = 0, | |||
Level = LogLevel.Information, | |||
Message = "Function {FunctionName} invoking.")] | |||
Message = "Function {PluginName}-{FunctionName} invoking.")] |
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.
If PluginName
is null, will the message become "Function -{FuctionName} invoking" or "Function Null-{FunctionName} invoking"?
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.
If the plugin name is not provided and the function name is Function1, the log message will be: "Function (null) - Function1 invoking."
The message template can be slightly changed to better communicate that no plugin is provided. The log entry message would be: "Function(PluginName:(null), Name:Function1) invoking." if the plugin name is null.
If neither of the messages looks right, the source generated methods that produces logs above:
[LoggerMessage(
EventId = 0,
Level = LogLevel.Information,
Message = "Function {PluginName}-{FunctionName} invoking.")]
public static partial void LogFunctionInvoking(
this ILogger logger,
string? pluginName,
string functionName);
can be replaced by two actions and one method to handle the null plugin names:
/// <summary>
/// Action to log invocation of a <see cref="KernelFunction"/>.
/// </summary>
private static readonly Action<ILogger, string, string, Exception?> s_logPluginFunctionInvocation =
LoggerMessage.Define<string, string>(
logLevel: LogLevel.Information,
eventId: 0,
formatString: "Function {PluginName}-{FunctionName} invoking.",
options: new LogDefineOptions { SkipEnabledCheck = true });
/// <summary>
/// Action to log invocation of a <see cref="KernelFunction"/>.
/// </summary>
private static readonly Action<ILogger, string, Exception?> s_logFunctionInvocation =
LoggerMessage.Define<string>(
logLevel: LogLevel.Information,
eventId: 0,
formatString: "Function {FunctionName} invoking.",
options: new LogDefineOptions { SkipEnabledCheck = true });
/// <summary>
/// Logs invocation of a <see cref="KernelFunction"/>.
/// </summary>
public static void LogFunctionInvoking(this ILogger logger, string? pluginName, string functionName)
{
if (logger.IsEnabled(LogLevel.Information))
{
if (!string.IsNullOrEmpty(pluginName))
{
s_logPluginFunctionInvocation(logger, pluginName!, functionName, null);
}
else
{
s_logFunctionInvocation(logger, functionName, null);
}
}
}
logLevel: LogLevel.Trace, // Sensitive data, logging as trace, disabled by default | ||
eventId: 0, | ||
"Function arguments: {Arguments}"); | ||
"Function {PluginName}-{FunctionName} arguments: {Arguments}"); |
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.
same question as above, also in a couple other places.
Motivation, Context and Description
This PR improves the existing logging functionality in both
FunctionCallsProcessor
andKernelFunction
by logging additional contextual information, such as function details, function choice behavior configuration, and function call details, to simplify troubleshooting.