Skip to content

.Net: Create a classifiable Kernel Function logger #6011

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

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public async Task<FunctionResult> InvokeAsync(
Verify.NotNull(kernel);

using var activity = s_activitySource.StartActivity(this.Name);
ILogger logger = kernel.LoggerFactory.CreateLogger(this.Name) ?? NullLogger.Instance;
ILogger logger = kernel.LoggerFactory.CreateLogger($"{this.GetType()}.{this.Name}") ?? NullLogger.Instance;
Copy link
Member

Choose a reason for hiding this comment

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

  1. This means that the implementation detail of the internal derived type's name will end up showing up in logging. That name could easily change. Is this desirable?
  2. We don't need to allocate a new string on each invocation. It can be cached once and then used on each access. That also avoids the duplication between InvokeAsync and InvokeStreamingAsync.

Copy link
Member

Choose a reason for hiding this comment

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

  1. This means that the implementation detail of the internal derived type's name will end up showing up in logging. That name could easily change. Is this desirable?

I think we want to avoid creating logger with name based on function name, because in this case the number of different loggers created will be equal to number of different functions users execute.

Having Microsoft.SemanticKernel.KernelFunction logger name and specific logs like this._logger.LogInformation("Start function execution: {PluginName}-{FunctionName}", this.PluginName, this.Name"); should be enough, and it will be possible to filter logs by FunctionName property in monitoring tool.


// Ensure arguments are initialized.
arguments ??= [];
Expand Down Expand Up @@ -283,7 +283,7 @@ public async IAsyncEnumerable<TResult> InvokeStreamingAsync<TResult>(
Verify.NotNull(kernel);

using var activity = s_activitySource.StartActivity(this.Name);
ILogger logger = kernel.LoggerFactory.CreateLogger(this.Name) ?? NullLogger.Instance;
ILogger logger = kernel.LoggerFactory.CreateLogger($"{this.GetType()}.{this.Name}") ?? NullLogger.Instance;

arguments ??= [];
logger.LogFunctionStreamingInvoking(this.Name);
Expand Down
Loading