Fix issue where AppInsights SDK doesn't load/configure correctly due to keyed services being registered in DI #594
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
A bug report came in, where logs/telemetry wasn't being shipped to AppInsights.
Upon inspecting the
IServiceCollection
registrations after callingAddApplicationInsightsTelemetry
, we discovered that everything until (and including) these lines of registrations succeeded:https://github.com/microsoft/ApplicationInsights-dotnet/blob/4626e3632323b741a2bd56d3d529c283cf7626c9/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs#L134
However the
TelemetryClient
itself was never registered in DI. In the code linked above, if there is an exception, it is (relatively silently) swallowed and registered on the event source for AppInsights.We traced the event source in a local test app:
dotnet trace collect --providers Microsoft-ApplicationInsights-AspNetCore -- ./bin/Debug/net8.0/Altinn.App
Which could be loaded into PerfView
We see this error:
Which means that AppInsights thinks that our DI container (Scrutor) doesn't support keyed services. I think that's right? Since there is an open issue on that: khellang/Scrutor#209
This PR replaces keyed services by just injecting multiple services, and introducing a second marker interface to distinguish between them instead.
Other options:
Related Issue(s)
Verification
Documentation