0

I have a .net 6 web app and is deployed to an azure app service. I wanted to configure app insights for it. The app insight is deployed and is enabled when you check the Application Insights menu under Settings of app service.

I am following the below link

Application Insights for ASP.NET Core applications

The instruction I am stuck at it Go to Project > Add Application Insights Telemetry.

I use my Visual studio with my organization id and the deployment is happening to client tenant. The id is only used for accessing client azure portal subscription and nothing else. When I go to the suggested menu option (as above) I get a pop up which has my org id and the subscription and resources under it. How do I perform this step without adding the account I use to access client azure portal?

Lucky
  • 81
  • 6
  • You need to have and Application Insights Instance created and Add the Instrumentation key in the `appsettings.json` file. Are you able to access the Resources from the Portal? – Harshitha Jun 21 '23 at 12:09
  • `menu option (as above)` can you please share the screenshot for this ? – Harshitha Jun 21 '23 at 12:12
  • The instrumentation key and connection string are present in azure app service Configuration under Settings. Names are: APPINSIGHTS_INSTRUMENTATIONKEY and APPLICATIONINSIGHTS_CONNECTION_STRING – Lucky Jun 21 '23 at 12:14
  • You can call the InstrumentationKey directly from the ApplicationInsights.Just add the `AddApplicationInsightsTelemetry` in your code. – Harshitha Jun 21 '23 at 12:17
  • It is Connect to Azure Application Insights dialog box. I right click my web app project from solution explorer and click on Add->Application Insights Telemetry. Select Azure Application Insights -> Click Next. Here I get my account logged in on top right and option to add microsoft account. With the logged in account it shows list of subscriptions (my organization) and all app insight instances. – Lucky Jun 21 '23 at 12:17
  • Instead add the AppInsights for SDK for Local [Image](https://i.stack.imgur.com/sInUO.png) – Harshitha Jun 21 '23 at 12:19
  • Application Insights will be Configured without asking for any account if local is selected.[Image](https://i.stack.imgur.com/6mlg5.png). You can check the telemetry by simply running the App locally. – Harshitha Jun 21 '23 at 12:22
  • `builder.Services.AddApplicationInsightsTelemetry();` this line of code will be added in the `Program.cs` or `Startup.cs` file based on your version. – Harshitha Jun 21 '23 at 12:24
  • What will be the best way as I will have to handle it for multiple environments. – Lucky Jun 21 '23 at 12:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/254176/discussion-between-harshitha-and-lucky). – Harshitha Jun 21 '23 at 12:24

1 Answers1

1

How do I perform this step without adding the account I use to access client azure portal?

To configure Application Insights without providing the Azure account, you need to select the Application Insights Sdk (Local).

enter image description here

It clearly says that this dependency is used to track and monitor the Performance of the WebApp without connecting to an instance in Azure.

enter image description here

I see service dependencies json file along with local version created in my web app project

Yes, serviceDependencies.json, gets added when we add the Local SDK.we do not configure anything in the created file.

enter image description here

If you are using the latest .NET Core 6 or later version, the below line of code gets added in the Program.cs file.

builder.Services.AddApplicationInsightsTelemetry();
  • As you are using .NET 5, I don`t see any code added.

  • In Startup.cs file, Add the below line under ConfigureServices.

services.AddApplicationInsightsTelemetry();
  • In appsettings.json file add the configuration same as mentioned in this Link.

Output:

enter image description here

Harshitha
  • 3,784
  • 2
  • 4
  • 9
  • 1
    Thank you so much for the discussion and support! – Lucky Jun 22 '23 at 07:34
  • Apologies to rekindle this thread (if required I will post this as a question) Will this set up automatically capture logs from NLog in Application Insight or additional set up will be required? – Lucky Jun 23 '23 at 12:16
  • You need to change few configuration within this Application. – Harshitha Jun 23 '23 at 12:21
  • Hello Harshitha, I have a strange issue which I am unable to understand. My app insight set up is fine however I am seeing one issue in my console "Failed to initialize AppInsights JS SDK: Cannot load Application Insights SDK, no instrumentation key was provided. r.warnToConsole @ Logging.ts:206". Can you please suggest? – Lucky Jun 28 '23 at 12:16
  • Sure,I think you have posted new question.Will check and let you know. – Harshitha Jun 28 '23 at 12:17