Skip to content

Issue while AddApplicationInsightsTelemetry along with KeyedInstances in IServiceCollection #2949

Open
@mavsankar

Description

  • List of NuGet packages and version that you are using: 2.22.0
  • Runtime version: net8.0
  • Hosting environment: Any

Describe the bug

When there are KeyedSingleton Registrations to IServiceCollection, the method AddApplicationInsightsTelemetry doesn't work if it is called after calling services.AddKeyedSingleton method.

More Info:

This is happening because here, the code is checking only for ImplementationType and ImplementationInstance.

Image

Instead, I think it should also check for KeyedImplementationType & KeyedImplementationInstance

To Reproduce

Simply run this web application to reproduce the issue. Please note the below two lines in the program.cs

Image

https://github.com/mavsankar/AppInsightsSdk-KeyedInstance-Repro

Workaround

Always use the AddApplicationInsightsTelemetry method before registering any keyed instances

We will close this issue if:

  • The repro project you share with us is complex. We can't investigate custom projects, so don't point us to such, please.
  • If we will not be able to repro the behavior you're reporting

For Immediate Support

For immediate support relating to the Application Insights .NET SDK we encourage you to file an Azure Support Request with Microsoft Azure instead of filing a GitHub Issue in this repository.
You can do so by going online to the Azure portal and submitting a support request. Access to subscription management and billing support is included with your Microsoft Azure subscription, and technical support is provided through one of the Azure Support Plans. For step-by-step guidance for the Azure portal, see How to create an Azure support request. Alternatively, you can create and manage your support tickets programmatically using the Azure Support ticket REST API

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions