I have developed .NetCore Web Job and enable the application insights. But currently the web job is running continuously and generates excess of service bus dependency calls into Azure Application Insights. So, I want to disable to service bus dependency calls to send to application insights.
Functions.cs
[NoAutomaticTrigger]
public async Task ProcessMessagesFromServiceBusQueue()
{
QueueRuntimeInfo queueInfo = null;
while (true)
{
try
{
queueInfo = await _serviceBusManagementClient.GetQueueRuntimeInfoAsync(queueName);
var count= queueInfo.MessageCountDetails.ActiveMessageCount > 0;
}
catch (ServiceBusTimeoutException)
{
}
}
}
I have tried to enable Adaptive Sampling by using below code. But still it generates excess of dependency calls.
s.Configure<TelemetryConfiguration>((o) =>
{
o.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
// Alternately, the following configures adaptive sampling with 2 items per second, and also excludes DependencyTelemetry from being subject to sampling.
o.TelemetryProcessorChainBuilder.UseAdaptiveSampling(maxTelemetryItemsPerSecond: 1, excludedTypes: "Trace;Exception");
});
Also, tried with this code to remove all dependency calls. But it is not working as expected.
private static IConfiguration GetConfiguration(ServiceCollection services)
{
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
// build config
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
services.AddApplicationInsightsTelemetry(configuration);
var dependencyTrackingService = services.FirstOrDefault<ServiceDescriptor>(t => t.ImplementationType == typeof(DependencyTrackingTelemetryModule));
if (dependencyTrackingService != null)
{
services.Remove(dependencyTrackingService);
}
return configuration;
}
So, can anyone suggest how to disable for automatically collecting the service bus dependency calls from .NetCore Web Job.