Run Azure Log Analytics query against Application Insights instances - azure

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

Related

Azure services overview

I have many services on the azure plateform .instead of going on azure portal always and checking which services are running i want main parameters of azure services on my dashboard like pipelines successfully ran in data factory,storage used in data lake.so is there any api which can do or fetch this data?
Almost all the Azure resources have REST API exposed to get their status and key metric/attributes, so you need to write some script or code to pull these and display in your UI(may be simple javascript based). For example to get the pipeline run details, refer this

Dashboards on custom application using application insights

We have a lot of applications that throws custom logs to application insights. I would like to make a dashboard where I can see if each application is running or throwing exceptions etc. I have tried looking around in log analytics and it does not seem to have a connector to Application insights. Can anyone provide with some information to start on? Should I use Monitor, Log Analytics or Sentinel for this task and how do you get started with custom application insights logs.
Application Insights is part of Azure Monitor. When creating a new App Insights resource you can now choose to store everything in an Azure Log Analytics Workspace, see the docs. Or you can migrate your existing resource to a workspace backed resource.
Then you can use workbooks to visualize data using interactive workbooks. These workbooks are also available to classic App Insights resources however.
There is also the possibilty to query an App Insights resource in any Log Analytics Workspace by using the app expression like this:
app("name-of-your-ai-resource").requests
| order by timestamp desc
| project timestamp, url, resultCode
and use those results for visualizations.
Finally you can also use the rich capabilities of Power Bi to create interactive reposts, see the docs

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.

Azure PaaS for Storing Centralized Log Data for Microservices

If we deploy a Microservice in azure AKS, there may be multiple pods and replica of same services. If Microservice want to keep any custom log information about it's flow or errors , where better to store such logs centrally? Any PaaS services? e. g. Azure Storage? Any real experience to share here?
I would suggest Azure Application Insigths. You can enrich your telemetry with aks details using this integration package:
... when using Microsoft Application Insights for Kubernetes, you will see Kubernetes related properties like Pod-Name, Deployment ... on all your telemetry entries. Proper values will also be set to make use of the rich features like enabling the Application Map to show the multiple micro services on the same map.
For logging within your application you can use the ILogger interface (if using .net) and pipe it to app insights.
Or you can write your own logging using the sdk, available in selected languages.
For java applications, you can pipe your logs as well. You probably have to manually add pod details to your telemetry using telemetry initializers as the Microsoft Application Insights for Kubernetes package is .Net only. As far as I know they use the kubernetes rest api to query for details.

Can Azure Insights API be used for completely stand-alone custom metrics?

I am hoping I can put in some simple API calls in legacy systems so I can capture point-in-time metrics "somewhere" in Azure, so that I can then take advantage of the Azure Portal dashboard and metrics graphing. I looked into Insights SDK but that seems to require that whatever I'm running be deployed somewhere in Azure cloud. I just want to run a simple powershell script or simple .net console app that connects to a legacy database in our internal network, pulls very basic point-in-time counts for message processing backlog... and then pushes that info with a timestamp out "somewhere" for visualization.
Any ideas what I can use for this in Azure?
Thanks,
Andres
You can use the TrackMetric API in Application Insights SDK.
https://learn.microsoft.com/en-us/azure/application-insights/app-insights-api-custom-events-metrics

Resources