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
chris
2,9083 gold badges27 silver badges26 bronze badges
-
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.MartinDotNet– MartinDotNet2025年06月11日 23:02:11 +00:00Commented Jun 11, 2025 at 23:02
-
Thanks, I updated the question to an example which does send metricschris– chris2025年06月11日 23:27:24 +00:00Commented 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.MartinDotNet– MartinDotNet2025年06月12日 11:21:18 +00:00Commented 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.chris– chris2025年06月13日 14:51:53 +00:00Commented Jun 13, 2025 at 14:51
default