microsoft / microsoft/ApplicationInsights-dotnet
Client-side tracking with /v2/track fails with 401 Unauthorized if local authentication is disabled
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 613
- Forks
- 301
- PR merge metrics
- No merged PRs in 30d
Description
- List of NuGet packages and version that you are using: Microsoft.ApplicationInsights.AspNetCore (v2.22.0), Azure.Identity (v1.12.0)
- Runtime version (e.g. net461, net48, netcoreapp2.1, netcoreapp3.1, etc. You can find this information from the
*.csprojfile): net8.0 - Hosting environment (e.g. Azure Web App, App Service on Linux, Windows, Ubuntu, etc.): Azure Web App, App Service on Linux, Windows via the .NET CLI locally
Describe the bug
If you disable local authentication for your AI resource, as it's recommended, then client-side tracking with /v2/track requests fail with HTTP 401 Unauthorized. This is after using SetAzureTokenCredential to configure a Service Principal, and using JavaScriptSnippet.FullScript.
Server-side tracking, as well as the Live Metrics control channel work (the latter is important because it shows the Service Principal working).
Enabling local authentication gets rid of this error.
I'd expect client-side tracking to work with local auth disabled too. The https://github.com/microsoft/ApplicationInsights-dotnet/issues/2795 issue hints on this having been the case at one point.
To Reproduce
This is a minimal MVC web app, generated with the VS template:
You can reproduce the issue by configuring an AI connection string in the appsettings.json file, configuring a Service Principal's details in Program, and running the app.
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure using the minimal MVC app, its appsettings.json configuration, Program service-principal setup, JavaScriptSnippet.FullScript, and the /v2/track endpoint. Compare the behavior with issue 2795 and verify that client-side tracking succeeds when local authentication is disabled, while server-side tracking and Live Metrics continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, javascript
- Domain
- authentication, backend, observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100