Okay, looks like the answer - you can't.
In the end, I simply removed the "Microsoft.ApplicationInsights.Profiler.AspNetCore".
And waiting for the "https://github.com/Azure/azuremonitor-opentelemetry-profiler-net" to be out of pre-release.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
We migrated our project to OpenTelemetery from application Insight.
Of course, AppInsight is our Exporter now.
However, I don't want to lose the "Service Profiler". So I installed ONLY "Microsoft.ApplicationInsights.Profiler.AspNetCore".
For that, I just added the "services.AddServiceProfiler();" before the OpenTelemetryBuilder is initialized.
Code looks like this:
public static IServiceCollection AddOneHubLoggingAndTelemetry(this IServiceCollection services, IConfiguration configuration)
{
var appInsight = configuration.GetApplicationInsightsOptions();
services.AddLogging(loggerBuilder =>
{
loggerBuilder
.Configure(c => c.ActivityTrackingOptions = ActivityTrackingOptions.TraceId |
ActivityTrackingOptions.SpanId |
ActivityTrackingOptions.TraceFlags |
ActivityTrackingOptions.Tags |
ActivityTrackingOptions.ParentId);
loggerBuilder.AddOpenTelemetry(opt =>
{
opt.IncludeScopes = true;
opt.IncludeFormattedMessage = true;
opt.ParseStateValues = true;
});
});
// Initializae Profiler
services.AddSingleton<ITelemetryInitializer, AppInsightCloudRoleTelemetryInitializer>();
services.AddServiceProfiler();
services.AddOpenTelemetry()
.UseAzureMonitor(c =>
{
c.ConnectionString = appInsight.ConnectionString;
c.SamplingRatio = appInsight.SamplingPercent / 100.0f;
})
.ConfigureResource(r =>
r.AddService(appInsight.ServiceName, serviceVersion: configuration.GetVersion(), serviceInstanceId: Environment.MachineName))
.WithMetrics(m => {
m.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation()
.AddAspNetCoreInstrumentation();
})
.WithTracing(t => {
t.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation();
})
.WithLogging(l => ...);
return service;
}
Now I have both, BUT, looks like AppInsight adding logs and duplicate the one that OpenTelemetry is sending.
Moreover, I am not able to filtrate the logs with "appsettings.json":
"Logging": {
"LogLevel": {
"Default": "None",
"Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information",
"Microsoft.IdentityModel.LoggingExtensions.IdentityLoggerAdapter": "Warning",
},
"ApplicationInsights": {
"LogLevel": {
"Default": "None"
}
}
},
It simply doesn't work anymore.
How can I get rid of traces/logs of ApplicationInsight and use it only for Profiling, and how to filter the OpenTelemetry logs?
Thank you.
Okay, looks like the answer - you can't.
In the end, I simply removed the "Microsoft.ApplicationInsights.Profiler.AspNetCore".
And waiting for the "https://github.com/Azure/azuremonitor-opentelemetry-profiler-net" to be out of pre-release.