0

I have a Blazor server application using Semantic Kernel and OTel. I'd like to send Semantic Kernel metrics to Application Insights. Here's my code:

AppContext.SetSwitch("Microsoft.SemanticKernel.Experimental.GenAI.EnableOTelDiagnosticsSensitive", true);
services.AddOpenTelemetry()
 .UseAzureMonitor(options =>
 {
 options.ConnectionString = appInsightsConnectionString;
 })
 .WithTracing(builder =>
 builder
 .AddSource(Telemetry.SourceName)
 .AddSource("Microsoft.SemanticKernel*")
 .SetResourceBuilder(Telemetry.ResourceBuilder)
 )
 .WithMetrics(builder => builder
 .AddMeter("Microsoft.SemanticKernel*")
 .SetResourceBuilder(Telemetry.ResourceBuilder));
services
 .AddScoped<Kernel>()
 .AddAzureOpenAIChatCompletion(deploymentName, endpoint, apiKey);

Then in my application I inject a IChatCompletionService and make a call with chatCompletionService.GetStreamingChatMessageContentsAsync(chatHistory). I see traces in Application Insights for Semantic Kernel but no metrics.

What am I missing?

Edit: If I follow this example in the documentation I do receive metrics:

using var meterProvider = Sdk.CreateMeterProviderBuilder()
 .SetResourceBuilder(resourceBuilder)
 .AddMeter("Microsoft.SemanticKernel*")
 .AddConsoleExporter()
 .Build();
asked May 30, 2025 at 19:33
4
  • I'm not aware of any metrics that Semantic Kernel is registering. I'm also unsure if the AzureMonitor exports supports metrics. If both of those things are true then your configuration does appear to be correct. Commented Jun 11, 2025 at 23:02
  • Thanks, I updated the question to an example which does send metrics Commented Jun 11, 2025 at 23:27
  • I'm glad you're now getting them, but I have no idea why adding a meter that sends to the console would enable sending to AzureMonitor. Commented Jun 12, 2025 at 11:21
  • I wasn't clear. I have no metrics at all, whether I try sending them to AzureMonitor or the Console, in the initial version. If I run the documentation example version I receive metrics both in AzureMonitor and the Console, when I modify their example to send it to AzureMonitor also. So in my version metrics do not work but in the documentation example they do work. Commented Jun 13, 2025 at 14:51

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.