How to get the full SQL query in Application Insights - azure

I just watched the video https://www.youtube.com/watch?v=TV1u6UoBRwk and saw the section on End to End transactions.
I've used that to track down a SQL query that is taking 1.8 mins.
The query is truncated (probably because EF is generating a super long query).
Is there any way to get the full query from Application Insights?

By default, SQL Collection is set to off. We need to enable it in the Azure Portal.
To get the full SQL Query, we need to enable the SQL Commands in our deployed App Service => Application Insights.
Add the below line of code in Program.cs file, if it is .NET Core Applications.
builder.Services.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((module, o) => { module.EnableSqlCommandTextInstrumentation = true; });
If it is .NET Framework Application, add the below line in TelemetryModules section in ApplicationInsights.config file (which is generated when we add Application Insights in Visual Studio.
<Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">,
<EnableSqlCommandTextInstrumentation>true</EnableSqlCommandTextInstrumentation>
</Add>
References taken from MSDoc and GitHub.

Related

How to view errors for WebApp in Azure portal and what configuration it is required

I am working on the ASP.Net MVC 4.8 application. It does have Logs file log4net and it was deployed in on-premises. Now it has been migrated to Azure. Now I am trying to find out some errors and other logs information however I am not able to find where to go and look for the logfile. I have two interest, 1 check the error messages and any log information.
If I need to make some changes what would be the easiest and straightforward way to capture logs and view them in Azure portal. As you can see in the picture below unter Monitoring there are many ways are given to see the logs but I am not sure where to go.
The app service will create an application insights of the same name.
This application Insights will contain all the logs regarding the web app along with performance data and other telemetry data too.
You can view logs live under live metrics tab in application insights of the same name as web app .
Here I have deployed a simple mvc app which logs using Ilogger (typical boilerplate app which visual studio provides ) . IT will log once I refresh the page.
Refer these MS DOCS on application insights

how to port app insights configuration from azure to config file

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.

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

Azure Web Application Insights "Servers" Data is Empty

I have a MVC 5 web app hosted on Azure using Application Insights. App Insights was installed via a NugGet package in VS 2015 and the Key is set correctly. I have included the JS portion in the bottom of my page template. I am receiving ALL App Insight data EXCEPT the "Servers" section, which displays lower level perfmon data (Process CPU, Avail, Memory, Process IO Rate, etc).
The ApplicationInsights.config file appears to contain the necessary module:
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
Here is a screenshot from the Portal:
I am running this on the B1 App Service Plan level. I cannot find any information that could indicate this information is not available at this tier.
In the Performance Counters section of the "Install Application Insights Status Monitor to monitor website performance" article they sneak in a "Not for Azure web apps" comment.
I believe they are making a distinction between Performance Telemetry, which you can get for web apps, and Server Performance Counters, which you cannot.
Take a look here. This is a custom solution, not from AI team, but it does the right thing - the account of the application pool on the box should have access to Performance Monitor to be able to read Performance Counter values and report them to AI.

Why do I need to configure connection strings for WebJobs in Azure Management Portal rather than in the App.config of my WebJob?

I created a scheduled Azure WebJob by right clicking on my WebApp project and adding a New Azure web project. I set the the AzureWebJobsDashboard and AzureWebJobsStorage connection strings in the App.config of the WebJob project. I left the default code in the .cs files alone for now. Next, I published from Visual Studio (2013 Update 4 by the way) to an Azure website. It created the WebJob and I can run it from the Azure Management site or Visual Studio and it is successful. I can see the output logs where I expect them to be. However, the Azure WebJob Details page shows the following warnings/errors:
Make sure that you are setting a connection string named
AzureWebJobsDashboard in your Microsoft Azure Website configuration by
using the following format
DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY
pointing to the Microsoft Azure Storage account where the Microsoft
Azure WebJobs Runtime logs are stored.
The configuration is not properly set for the Microsoft Azure WebJobs
Dashboard. In your Microsoft Azure Website configuration you must set
a connection string named AzureWebJobsDashboard by using the following
format DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY
pointing to the Microsoft Azure Storage account where the Microsoft
Azure WebJobs Runtime logs are stored.
It also provides a link that was to http://azure.microsoft.com/blog/2013/07/17/windows-azure-web-sites-how-application-strings-and-connection-strings-work/ which doesn't explain why I am getting the error message.
Now, to get this warning/error to go away, I go add the same AzureWebJobsDashboard connection string in the configure page in the Azure Management site.
So, I'm trying to figure out if I did something wrong or if this is just a kink in the WebJobs that Microsoft hasn't fixed yet. I would really like to be able to have this in the App.config rather than have to remember to set it up in each website we spawn up for different environments.
Thank you very much for your time and help.
The dashboard doesn't have access to your web job's app.config file and even if it did, you might have multiple webjobs so it wouldn't know which connection string to pick. That is why you need to set the connection string in the portal.
However, you don't have to set it in app.config for the web job if you set them in the portal. The WebJobs SDK knows how to read them from there.
I had to manually add authorization headers:
For get the value anfter "Basic " I used this code:
var byteArray = Encoding.ASCII.GetBytes("<user>:<password>");
var base64 = Convert.ToBase64String(byteArray);
Ithink is a Azure Scheduler UI bug

Resources