Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application Insights AddApplicationInsightsTelemetry method crashes if http client factory with AddStandardResilienceHandler is registered first #2902

Open
Markz878 opened this issue Oct 3, 2024 · 1 comment
Labels

Comments

@Markz878
Copy link

Markz878 commented Oct 3, 2024

When an Asp.Net Core app registers an IHttpClientFactory with the AddStandardResilienceHandler method, and Application insights is added with the AddApplicationInsightsTelemetry method after that, the AI method throws an exception silently, which prevents AI from working.

The exception occurs at line 307 inside the AddCommonTelemetryModules method's first line, the exception that is thrown is an System.InvalidOperationException: 'This service descriptor is keyed. Your service provider may not support keyed services.'

Repro:

  1. Create a new .NET 8 Web Api
  2. Add packages "Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" and "Microsoft.Extensions.Http.Resilience" Version="8.9.1"
  3. Add these lines after the first builder line:
builder.Services.AddHttpClient("MyClient").AddStandardResilienceHandler();
builder.Services.AddApplicationInsightsTelemetry();
  1. Run the app with Just My Code disabled.

Very strange bug, spent a whole day trying to figure out why our AI did not get any telemetry. I then just tried putting the AddApplicationInsightsTelemetry method at the top and it started working.

Could that keyd services check be removed or fixed (since Asp.Net Core 8 DI obviously supports keyd services)?

@Markz878 Markz878 added the bug label Oct 3, 2024
@ctolkien
Copy link

Related: #2879

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants