Hi,
In case you want to keep Microsoft.ApplicationInsights.Profiler.AspNetCore for the profiler, you can stop it from sending logs/traces so that OpenTelemetry is the only one doing that.
Right now, your duplication happens because that package drags in the full Application Insights SDK, which automatically registers its own ILoggerProvider and telemetry modules.
You can try the following:
- Disable the AI Logging Provider
Add this right after services.AddServiceProfiler(); to remove the logging provider the SDK registers:
services.Configure<TelemetryConfiguration>(config =>
{
// Remove the Application Insights logging provider
config.DefaultTelemetrySink.TelemetryProcessorChainBuilder = null;
});
services.AddLogging(loggingBuilder =>
{
// Remove AI provider from the logging pipeline
loggingBuilder.ClearProviders(); // optional if you only want OTel
loggingBuilder.AddOpenTelemetry();
});
This ensures the AI SDK doesn't push logs through its pipeline.
- Disable AI Telemetry Modules You Don’t Want
You can disable everything except the profiler:
services.Configure<TelemetryConfiguration>((config) =>
{
// Keep profiler, remove everything else
foreach (var module in config.TelemetryModules
.Where(m => !(m is Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule))
.ToList())
{
config.TelemetryModules.Remove(module);
}
// Remove all processors except profiler ones
foreach (var processor in config.DefaultTelemetrySink.TelemetryProcessors
.Where(p => p.GetType().Name != "ServiceProfilerTelemetryProcessor")
.ToList())
{
config.DefaultTelemetrySink.TelemetryProcessors.Remove(processor);
}
});
This effectively neuters AI’s auto-collection while leaving the profiler pipeline intact.
- Filtering Logs in
appsettings.json
Once AI’s own logging provider is gone, your log filtering applies only to OpenTelemetry:
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Microsoft": "Warning"
}
}
Hope this works out for you.