Improve Application Insights (App Insights) integration for Azure Function v4. Automatically discard cruft telemetry emitted by Functions runtime. Add your own telemetry processors.
$ dotnet add package AzureFunctions.Better.ApplicationInsights:rotating_light: The customisation supports in-process Functions only. Isolated Functions are not supported.
Beginning 10 November 2026, the in-process model for .NET apps in Azure Functions will no longer be supported. Migrate to the isolated worked model.
Automatically discards redundant telemetry items such as Functions execution traces and duplicate exceptions. Allows you to register your own telemetry processor(s) that will be invoked on every telemetry item type.
More detailed documentation is available on GitHub.
In your Startup class add the below snippet:
var appInsightsOptions = new CustomApplicationInsightsOptionsBuilder(
"{ApplicationName}",
{TypeFromEntryAssembly})
.Build();
builder.Services
.AddCustomApplicationInsights(appInsightsOptions);
Where
{ApplicationName} used to set Application Insights' Cloud role name (optional). When not provided, the default behaviour is preserved (the Cloud role name will be set to the Function App's name){TypeFromEntryAssembly} typically would be typeof(Startup). When {ApplicationName} is provided, I read the Assembly Informational Version of the entry assembly to set Application Insights' Application version (I use unknown as a fallback). When {ApplicationName} is not provided, Application version will not be present on the telemetry itemsAdditionally you can discard health requests and Service Bus trigger traces using application settings:
{
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"ApplicationInsights:DiscardServiceBusTrigger": true,
"ApplicationInsights:HealthCheckFunctionName": "HealthFunction" // The name of the Function, not the route
}
}
You can also add telemetry initializers and telemetry processors:
public override void Configure(IFunctionsHostBuilder builder)
{
var appInsightsOptions = new CustomApplicationInsightsOptionsBuilder(
"customv4inprocess", // Will be used as Cloud role name
typeof(Startup)) // Assembly Informational Version will be used as Application version
.Build();
builder.Services
// Telemetry processors are supported on all telemetry item types
.AddApplicationInsightsTelemetryProcessor<CustomHttpDependencyFilter>()
.AddSingleton<ITelemetryInitializer, TelemetryCounterInitializer>()
/*
* When adding an instance of a telemetry initializer, you need to provide the service Type otherwise
* your initializer will not be used.
*
* <code>
* // Do not use:
* .AddSingleton(new TelemetryCounterInstanceInitializer("NiceValue"))
* </code>
*/
.AddSingleton<ITelemetryInitializer>(new TelemetryCounterInstanceInitializer("NiceValue"))
.AddCustomApplicationInsights(appInsightsOptions);
}
Setting the cloud role name breaks the Function's Monitor blade.
Release notes can be found on GitHub.
Leave feedback by opening an issue on GitHub.