Azure Batch Application Insights - azure

I'm trying to get application insights to work in azure batch job/task while running through a .net core 3.1 console application.
When I run the console app through Visual Studio debug or directly on a node in the batch pool, I get all the appropriate telemetry and logs. However when I setup a task to run the console app I'm not getting any data in application insights.
Guides I looked through:
https://learn.microsoft.com/en-us/azure/batch/monitor-application-insights
https://learn.microsoft.com/en-us/azure/azure-monitor/app/worker-service
https://learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core
Is there anyway to get the AppInsights data when running the console app through the task?
edit
I have added a TelemetryClient.Flush and Thread.sleep to the end of the process. I can now see explicit calls to TelemetryClient.TrackedEvents but I'm not getting any dependency information, such as SQL call, api calls etc.This only happens to calls made inside a Task. If the console application gets called through a regular command line all information is visible.

Probably the issue is that the console app closes before telemetry is sent. you'll need to explicitly call "flush" on the telemetry client/etc and wait some time to allow telemetry to be sent.
see: TelemetryClient produces inconsistent results in Application Insights

Related

dotnet.exe fails to start when restarting Azure app service

We have several Azure app services live and I've ran into a consistent problem when restarting any of them.
We've right-click -> Published from Visual Studio upto an existing instance of an App Service which brings it online and functional immediately, we can update and republish new code without a problem, but restarting to app service from Azure Portal doesn't launch dotnet.exe.
When restarting or stopping/starting, the thread count instantly drops to 0 and continues to do nothing.
I have to manually publish from VS again to reboot dotnet.exe.
I can see that dotnet.exe isn't an active process via Kudu -> Process Explorer, and manually publishing up to the App Service and then refreshing the Process Explorer list again shows that dotnet.exe is now an active process and the App Service begins to function as expected.
Is there a way to prevent this, or at the very least debug why it's happening?
As it turns out this is being caused by silent failures, outside of error handling I'd put in place. IIS would spin up the associated processes but dotnet would throw and error and "silently" die.
I use quotes because I'd failed to utilise Azure's indepth logging, which hid the error message from plain view until switched on.
For some basic debugging steps:
Open up your Kudu console (Advanced Tools -> Go -> Debug Console) and navigate to LogFiles, open up eventlog.xml, the latest events are listed at the bottom.
Run dotnet myDll.dll against your debug folder locally, where myDll.dll is the main dll in your project. This will typically throw the error causing dotnet to exit out, which wasn't obvious at design time.
Ensure that your server-side appsettings.json (or the associated appsettings.[development/release].json contains the connection strings you're attempting to access.
The errors that were occuring we'ren't due to design-time bugs, it generally fell over when trying to access run-time resources (such as appsettings).

(Azure DevOps) Command Line Script .exe Console messages not visible in logs

I'm trying to run an .exe during a release pipeline on Azure DevOps.
In order to do so, I'm using a Command Line Script task where i just "invoke" the .exe file.
It works as it's correctly launched but i cannot see the output of the .exe (that is a .net framework 4.7.2 Console Application).
I've used a simple "Console.WriteLine()" method in the Console App in order to dump the messages. Obviously, on local machine it correctly writes messages on the console output. On Azure DevOps...just the Std Errors.
Why? How could I dump application messages to the task log?
Thanks
My bad. After different tries and retries i've found that the problem was related to a wrong dependency (resolved via reflection at runtime) that was causing exceptions before any log was written.
So, in fact, it works as expected.

Application Insights Reporting Duplicate Events for each Server Request

I have an API App running under Azure App Service, with Application Insights installed to track server side telemetry of API calls. When viewing Application Insights in the Azure portal, I am seeing two events for every one server call. Each event has an exact duplicate with the same timestamp, response time, telemetry, etc. I have verified that only one event is in the web server logs, so I'm not accidentally calling the same function twice from the client.
Here are a couple of screenshots to illustrate:
What could be causing this? And how can I fix it?
There is a one known scenario that may lead to the data duplication:
Application is not onboarded to AI SDK is deployed as an Azure
Web App
AI Extension is installed to the app -> after this step
you start to receive data without need to modify your code
Later on you decided to use more powerful features of AI let's say custom
event tracking and on-boarded your application to AI from VS and
re-deployed.
Now you may end up in the situation when HTTP module is registered twice and you start to receive duplicate request data. It happens because AI nuget packages add HTTP module definition in web.config, but extension installation drops additional assembly into your application bin folder that registers HTTP module dynamically during app start - Microsoft.AI.HttpModule.dll (Microsoft.ApplicationInsights.Extensibility.HttpModule.dll in previous versions). To correctly handle this case you need to remove extension leftovers during your application deployment by choosing "Settings->Remove additional files from destination" in case of deploying from VS.

Application Insight - Unable to get teletry from different environments

We are experimenting Azure Application Insight within a SharePoint 2013 solution. We managed to configure it manually, and we are collecting data from the development farm.
However, the same configuration looks like not to be working in the test farm, as only a few requests are tracked.
We tried two ways of diagnosing the issue:
With a custom command-line tool that traces an exception, on the test front-end. No errors are shown, and enabling diagnostic tracing on System.Net shows no problem actually occurs in transmission. Eventually, the exception is logged on AppInsight, but not every time.
Implementing a custom WebApi controller that performs the same action, but within of our solution code. This never gets collected.
In the end, what looks very weird is only certain URL are tracked server-side (no problems with client JS), which interestingly are the slowest requests.
I've decompiled all Application Insight assemblies, and of course telemetry transmission in done asynchronusly, but within w3wp.exe there's no chance that the process is aborted and the transmission never occurs...
What else can I try?
You can install Fiddler or Other HTTP Debugging tool on the box to see the data that AI sends.
To View internal Application Insights traces you can Install PerfView and collect traces:
PerfView.exe /onlyProviders=*Microsoft-ApplicationInsights- collect
http://www.microsoft.com/en-us/download/details.aspx?id=28567
http://channel9.msdn.com/Series/PerfView-Tutorial

Unable to debug Azure webjobs - the webjob processes do not show in the "Attach to process" dialog

Visual Studio 2013 update 3. I have deployed several Webjobs to Azure, both manually (upload a bundle via the portal) and also published directly from Visual Studio. The webjobs I am testing with are set to run "Continuous" and have code that runs inside a while(true) {} loop; so the process never ends. The webjobs are functioning properly and I see their runtime output in the Webjobs dashboard log output screen.
I've enabled remote debugging on the website. When I select Debug, Attach to process, the webjob process names never show on the list. All I see are the remote debugger processes and w3wp.exe.
Ideas?
Instead of attaching to SITENAME.azurewebsites.net, try to attach to SITENAME.scm.azurewebsites.net. Use same credentials as for the regular debugging connection. WebJobs run under a different context (Kudu), hence the different endpoint.

Resources