Skip to content
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: Monitor & Troubleshoot the Semantic Kernel C# SDK using the KernelFunction #9666

Open
markbartolocodit opened this issue Nov 12, 2024 · 4 comments
Assignees
Labels
.NET Issue or Pull requests regarding .NET code question Further information is requested

Comments

@markbartolocodit
Copy link

.Net: Observability

We are using the Semantic Kernel C# SDK, but having some troubles identifying the possibilities to monitor & troubleshoot this solution.

We are using a KernelFunction using OpenAI and within that, the Azure OpenAI is throwing 429's.

Nevertheless, it seems that this is captured within the code of the Semantic Kernel & we cannot distinguish the issues when we get back the result from the kernel.

So we have a few questions:

  • Are we missing a functionality in that regard?
  • If Yes, where?
  • If No, is this something considered in the roadmap?

Thanks for the feedback!

@moonbox3 moonbox3 added .NET Issue or Pull requests regarding .NET code triage labels Nov 12, 2024
@moonbox3 moonbox3 changed the title Monitor & Troubleshoot the Semantic Kernel C# SDK using the KernelFunction .Net: Monitor & Troubleshoot the Semantic Kernel C# SDK using the KernelFunction Nov 12, 2024
@markwallace-microsoft markwallace-microsoft self-assigned this Nov 12, 2024
@markwallace-microsoft markwallace-microsoft added question Further information is requested and removed triage labels Nov 12, 2024
@markwallace-microsoft markwallace-microsoft moved this to Sprint: In Review in Semantic Kernel Nov 12, 2024
@markwallace-microsoft
Copy link
Member

Hi @markbartolocodit
what exception are you seeing? Also can you provide some sample code and a stack trace for the issue. Thanks!

@markbartolocodit
Copy link
Author

Semantic Kernel is being initialised in an ASP.NET Core App as folllows:

 var kernel = Kernel.CreateBuilder()
        .AddAzureOpenAIChatCompletion(
          myConfig.KernelMemory.DefaultOverrides.ChatModelDeployment,
          myConfig.KernelMemory.Services.OpenAIService.Endpoint,
          myConfig.KernelMemory.Services.OpenAIService.ApiKey
        )
        .Build();

The code that is using the semantic kernel in a Controller is the following:

Microsoft.SemanticKernel.Kernel kernel;
...
KernelFunction? myFunction = kernel.CreateFunctionFromPrompt(finalPrompt);
FunctionResult? result = await myFunction.InvokeAsync(kernel, arguments).ConfigureAwait(false); 

The exception is occuring in myFunction.InvokeAsync

In AppInsights I'm seeing:
Image

There is no way to interfere to see any exception happening from within the Kernel.

The main goal would be for the 429 to bubble up in the myFunction.InvokeAsync.

@markwallace-microsoft
Copy link
Member

Hi @markbartolocodit
I created a unit test to check this behaviour, take a look here: https://github.com/microsoft/semantic-kernel/pull/9772/files

Based on this you should be able to catch a HttpOperationException. Let me know if this doesn't work for you.

@dmytrostruk
Copy link
Member

@markbartolocodit If you have ASP.NET Core app, you are invoking Kernel in Controller and you don't see an exception, make sure that you don't have global filter/middleware in your app that intercepts the exception automatically. If you want to catch 429 exceptions in controller, you need to make sure that global exception handling doesn't include 429 error.

github-merge-queue bot pushed a commit that referenced this issue Nov 20, 2024
### Motivation and Context

Issue #9666 

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.NET Issue or Pull requests regarding .NET code question Further information is requested
Projects
Status: Sprint: In Review
Development

No branches or pull requests

4 participants