-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Description
When adding ApplicationInsights to an ASP.NET core web app's IServiceCollection via AddApplicationInsightsTelemetry() and adding a call to ConfigureOptions<ConfigureApplicationInsightsServiceOptions>() to configure ApplicationInsightsServiceOptions, we are experiencing a deadlock.
Sample code
Program.cs:
services.ConfigureOptions<ConfigureApplicationInsightsServiceOptions>();
services.AddApplicationInsightsTelemetry();ConfigureApplicationInsightsServiceOptions.cs:
public class ConfigureApplicationInsightsServiceOptions : IConfigureOptions<ApplicationInsightsServiceOptions>
{
public ConfigureApplicationInsightsServiceOptions(
SecretClient secretClient)
{
SecretClient = secretClient;
}
public SecretClient SecretClient { get; }
public void Configure(ApplicationInsightsServiceOptions options)
{
KeyVaultSecret secret = SecretClient.GetSecret("appinsights");
options.ConnectionString = secret.Value;
}
}Reproduction Steps
- Call
ConfigureOptions<ConfigureApplicationInsightsServiceOptions>()on theIServiceCollectionas shown in the description - Call
AddApplicationInsightsTelemetry()on theIServiceCollectionas shown in the description
Or see here: https://github.com/jonathan-vogel-siemens/IssueRepro88390
Expected behavior
ConfigureApplicationInsightsServiceOptions.Configure should be invoked when the WebApplicationBuilder is building
Actual behavior
Deadlock. See running tasks here:
Somehow it is blocking at
Line 84 in 7575716
| lock (callSite) |
Regression?
Seems like it is a regression. A similar method (yielding the same deadlock) is documented here, from 2021: https://www.uveta.io/categories/blog/unclutter-startup-cs/#Application-Insights
Known Workarounds
No response
Configuration
- .NET 6.0
- Windows
- x64
- Plain ASP.NET Razor Web App
Other information
No response
