I came across this MSDN article on configuring AppInsights sampling for various types of apps.
However I could not find a way to configure it for azure webjobs.
When it comes to configuring appinsights for the WebJob it would look something like this (MSDN):
static async Task Main()
{
var builder = new HostBuilder();
builder.UseEnvironment(EnvironmentName.Development);
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddAzureStorage();
});
builder.ConfigureLogging((context, b) =>
{
b.AddConsole();
// If the key exists in settings, use it to enable Application Insights.
string instrumentationKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"];
if (!string.IsNullOrEmpty(instrumentationKey))
{
b.AddApplicationInsightsWebJobs(o => o.InstrumentationKey = instrumentationKey);
}
});
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}
The relevant code is:
b.AddApplicationInsightsWebJobs(o => o.InstrumentationKey = instrumentationKey);
The options itself is as follows:
Any help is much appreciated. Thank you!
Simplest way is to set the SamplingSettings
property to null
:
.ConfigureLogging((loggingContext, builder) =>
{
builder.AddConsole();
builder.AddApplicationInsightsWebJobs(o =>
{
o.SamplingSettings = null;
});
})
This prevents the AdaptiveSamplingTelemetryProcessor
being added to the list of telemetry processors.
You can inspect whether adaptive sampling is active or not by taking a look at the TelemetryClient.TelemetryConfiguration.TelemetryProcessors
property to see whether it contains an entry of type AdaptiveSamplingTelemetryProcessor
or not.