how to port app insights configuration from azure to config file - azure

We enabled application insights via azure portal some time ago. Everything worked great and we want to log bit extra custom information. So we will have to include appInsight SDK and create TelemetryClient and RequestTelemetry in our code now.
Ideally, we would like to enable the exact same setting as we enabled in azure portal (e.g. enable profiling, recommended collection level, sql command and disable Snapshot debugger).
However, when I look at the appinsight config file, I realised that this file is way more complicated than what azure portal offers.
Is there a way to convert what we enabled on azure portal to the config file?
Or if I delete this config file (just add the custom field in our c# RequestTelemetry instance), will appInsights use settings from azure portal automatically?

If you are using Asp.Net Application, installing SDK by default will generate the full ApplicationInsights.Config file for you, which would do same level of monitoring as Recommended level.
https://learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net
And follow this to get full SQL Text:
https://learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net-dependencies#advanced-sql-tracking-to-get-full-sql-query
If you are using Asp.Net Core Application, installing SDK by default will automatically configure everything in code (there is no ai.config in asp.net core apps).
https://learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core
You dont need to do anything additional to get full SQL Text in Asp.Net Core apps.
SnapShotCollector is not enabled by default, so you dont need to do anything to disable it.
Profiler: https://learn.microsoft.com/en-us/azure/azure-monitor/app/profiler#enable-profiler-manually-or-with-azure-resource-manager

For application insights, maybe you know that there is 2 ways to apply Application Insights to your .NET web applications(For details, please refer to here).
Build time: add application insights sdk
Run time: via azure portal without adding sdk to your project.
And the screenshot below shows the difference of them(you can ignore the Note section about build-time and run-time in this article, this gives users confusion and an issue is tracking that):
And for your issues, I suggest you'd better use both of them: adding sdk and also enable/disable profiler / snapshot debugger / sql command via azure portal.
I did some tracing about sql command before, without enable from azure portal, you cannot get a details sql command info from application insights with just adding sdk. Not make some changes via config file.
And there're also described in docs like below, take profiler for example:
In the profiler doc, it says: Follow these steps even if you've included the App Insights SDK in your application at build time.
And also, it would be more difficult to change appinsight config file to meet your need, there is even no official doc about these for apply profiler / sql command via config file.
I just found a blog about how to configure snapshot debugger via appinsight config file, you can take a look and try it at your side.

Related

No data for my application insights live metrics with .NET Core 3.1

I'm trying to setup Application Insights on my ASP.NET Core 3.1 web application but without success...
I installed the version 2.16 of "Microsoft.ApplicationInsights.AspNetCore", then add the following line in the startup.cs file:
services.AddApplicationInsightsTelemetry(_configuration);
Moreover, I added the following section in the appSettings:
"ApplicationInsights": {
"InstrumentationKey": "XXX"
}
When I launch this with Visual Studio, I can see data in Live metrics, however, as soon as I deploy this in the production server with IIS, it just display that the application is off. I tried to put the connection string instead, without luck.
I'm suspecting a proxy issue, however, I have no way to be sure of this and it seems unlikely because I'm using the proxy as well on my local machine where it works.
I put the log level of the application on "Information" and I see nothing related to Application Inisights. I even tried to enable the developer mode, it didn't change anything.
The main issue is that I have no error anywhere, so I don't even know what to search :-)
I have encountered the same situation as you, but I'm not sure if we are facing the same error because of no error message.
I have my own ASP.NET Core 3.1 web application and I did the same configuration in my project, and when run it by vs in local environment, azure application insights can show live metrics, when have deployed in azure app service, it shows 'your app is offline'.
In my scenario, it's result from web app instance creation. When I creating an app service, it will create new application insights as default. Like the screenshot below, and of course the new one has different instrumentation key from the key in 'appSetting.json', it caused that when I look into application sights configured in the project, I can't see live metrics but I can see in the application sights that has the same name with app service.
And when creating app service with new application insights, the configuration tab in web app will display some keys like below, and they won't exist if didn't create new insights.
Upon this situation, I tried to modify these two keys with the value of insights that is used in project, and then live metrics worked.
Priority for obtaining the insights configuration may lead to my problem, because there are several ways to set connection.

Application Insights stop working after deployed to Azure

I set up Application Insights on my asp.net core (2.2) app. I can see data in Azure portal when I run my application locally. However, once I deploy it to App Service in Azure, Application Insights stop working - there is no data flow at all. Are there any additional steps I am missing?
Adding to Stuart's comments- > If you edited ApplicationInsights.config, kindly check the configuration of TelemetryInitializers and TelemetryProcessors. An incorrectly-named type or parameter can cause the SDK to send no data.
Also, in the Application Insights portal, open Diagnostic Search. Data usually appears here first. Refresh to see if it helps.
If feasible, you may restart the app and check to see if that helps.

Run Azure Log Analytics query against Application Insights instances

I'm using the Azure Log Analytics .NET SDK to execute queries.
The NuGet package I'm using for this SDK is Microsoft.Azure.OperationalInsights.
Querying against a normal Workspace is fine.
Now I want to query against an Application Insights resource, like you can do in the portal via the 'Analytics' button on an Application Insights blade. For this I need a WorkspaceId, that I cannot find on the resource.
Is there a way to run these queries via the OperationalInsights SDK or do I need to create my own wrapper around the Application Insights API? That seems to add extra authentication via the token, which I'd rather not need (I already have access to Log Analytics).
Found out that you can query across workspaces and even across apps.
For apps, use app(appName) like so:
app('AppInsightsName').requests
For a different workspace, use this:
workspace("workspaceId").request

How to Enable Azure Diagnostics in Cloud Services

I want to enable azure diagnostics for my azure cloud service but I'm a little bit confused.
I read the article : https://learn.microsoft.com/en-us/azure/cloud-services/cloud-services-dotnet-diagnostics. I found also that I can enable azure diagnostics in the cloud service properties page by checking "Enable Diagnostics" in the Configuration tab of the cloud service. Also I can go more advanced by clicking the Configure button that shows up when you enable diagnostics.
The cause of my confusion is why in the article says you need to download the WadConfig.xsd file and configure everything and then upload an xml file while you can do the same thing (not sure the same thing) in the cloud service properties configuration?
It seems that Azure SDK 2.5 and later allow us to enable diagnostics and configure diagnostics configuration in UI by right-clicking on the Role and selecting Properties. But developers using Azure SDK 2.4 and previous versions can not manage diagnostic configuration in Visual Studio .
For detailed information, please read this blog.

No data on Application Insights

I have Application Insights SKD on a ASP.NET application, but i can't see data on Azure Portal, I have followed the official documentation for troubleshoot and the connectivity with dc.services.visualstudio.com seems to be fine but i can't connect to f5.services.visualstudio.com, but f5.services.visualstudio.com seems not used anymore, I can't access it inside and outside of my network.
The account have access to Performance Logs too, and I uninstalled the SCOM Monitoring Agent to prevent problems, but still no data!
Check that assemblies are included in your project
Check you have last SDK version of Application Insights installed
Check ApplicationInsights.config file exists in the root of application and instrumentation key is presented
If you resolve InstrumentationKey from web.config or from another place, debug your application and ensure the InstrumentationKey is really resolved
Check your telemetries are collecting using the Visual Studio Diagnostics Hub (developer mode must be set to TRUE - by default)
Try to send more telemetries or change the flush interval to 0
First place where you can check your telemetries is Azure Portal - Diagnostic Search blade
Try to check quotas on Azure Portal

Resources