azure-functions-host: Azure AD authentication for Application Insights is not working in Azure Function
I am getting the below error when I am trying to use Azure AD authentication for Application Insights in my Azure Function.
Microsoft.ApplicationInsights: The provided tokenCredential must inherit Azure.Core.TokenCredential (Parameter 'tokenCredential').
I am getting this error both in my local machine and also in my azure portal as a Functions runtime error.
Investigative information
- Timestamp: 2023-05-04T08:00:00Z
- Function App version: 4
- Function App name: func-tpgcp-mail-dev-eu
- Region: North Europe
Repro steps
Here is the code that I wrote in my Startup.Configure:
var managedIdentityCredential = new ManagedIdentityCredential();
services.Configure<TelemetryConfiguration>(config => config.SetAzureTokenCredential(managedIdentityCredential));
services.AddApplicationInsightsTelemetryWorkerService();
Expected behavior
The function app can use its managed identity to authenticate and sends telemetry data to application insights.
Actual behavior
As I said in the description I am getting an error that says ManagedIdentityCredential
is not inherited from the TokenCredential
class.
Known workarounds
Nothing came to my mind.
Related information
After some investigation, I realized that ReflectionCredentialEnvelope
uses reflection to load the TokenCredential
type and then uses the type to check if the passed credential object inherits from that type or not. Then I took a look at the loaded modules in the application on my local machine and saw that the Azure.Core.dll
is loaded twice with different versions:
Also here are all packages that I used in my app function:
<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.31.0" />
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.13.1" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.16.0" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.33.0" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="4.2.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="3.2.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.9.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.1.2" />
<PackageReference Include="Microsoft.Graph" Version="5.8.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.53.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />
</ItemGroup>
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 2
- Comments: 16 (3 by maintainers)
@RohitRanjanMS: Any updates on this?
Here’s the PR to support ManagedIdentity and ClientSecret credential. I will check if we can support DefaultAzureCredential and VisualStudioCredential as well.
Hello Team,
Thank you so much for your help.
Can you please help us on it
@RohitRanjanMS any update on this ?
Please expect this to be available around 3rd week of Jan
Hi Team,
Could you please provide ETA to complete this? we opened the case: 2309120030002783 for this issue.