Preferred way of logging in nodejs deployed to Azure App Services - node.js

I have created nodejs Web API, hosted as Azure App Service.
What would be the best way to log errors/info/debug/warning?

We're using Azure Log Analytics with some custom node-winston middleware that sends an async request out to the ALA REST service. However, there is a bit of a lag between the event being sent from our node Web App and it appearing in the ALA dashboard so although it will be good for monitoring a production environment it's not great for rapid debugging or testing.
If you just write to console.log then everything does get stored in a log file that you can access through the Kudu console. Kudu also has the ability to do a live tail of the console, as does the azure command line interface. Because of this we're debugging using those and leaving ALA for the future.
Once we figure out what the pattern is for those logs being written (i.e. filename/size/time/etc.) we'll drop a scheduled Azure Function in to regularly archive those logs into cold blob storage.
I'll also add that according to the Twelve Factor App in XI they recommend writing logs to stdout, which is what console.log does. I always take these opinionated frameworks/methodologies as guidance and not strict rules, but at these seem to be grounded in reality and will at the very least spawn some interesting discussions among your team.

As you're using Azure, I would recommend the Application Insights:
https://learn.microsoft.com/en-us/azure/application-insights/app-insights-nodejs

Related

How to add logs in log analytics in azure logic apps?

I am following this tutorial and I am also able to add the logic app logs into azure log analytics but the problem is that logic analytics for logic apps is still in preview mode.
https://learn.microsoft.com/en-us/azure/logic-apps/monitor-logic-apps-log-analytics
I have few question regarding this.
should I use it for logging as it is still in preview mode.
If not what other options do I have to logs data in azure monitor?
Preview mode is mode where full-fledged features are not available. This type of modes is provided to give feedbacks to improve it better.
If you ask me about to use it or not, I usually use it and i get desired results, and it works fine for me Example-Reference.
The other way I monitor logs is by using below process:
So firstly, I send logs to Log analytics workspace and then, I created another logic apps and get logs by below process:
Another way is this to log Logs of Azure Logic Apps.

How to ensure that my deployed azure function works?

I created an azure function app, and tested it locally where I using the console, was able to determine that the my application works, and does what it is supposed to do.
Now I have deployed it to Azure cloud, and started the service - but I don't seem to have any indication on whether it is running, no logs showing what state it is in,
nothing.
How do i view the console application log for my application running in the azure cloud?
I have an Azure Function App in the Portal which contains .NET Core 6 Http Trigger Function.
Now, it has run successfully 2 times.
You can observe the function app state in the Log Stream during the execution state and in idle state that there is no new trace, but your function host is running:
You can also observer the metric rates in Function App Overview blade, how many requests and when they came in last 30 minutes, 1 hour, etc. and you can see more metrics in Live Metrics blade from the Application Insights associated with that Function App.
You could also check any performance issues in the Function App using diagnostics.
Refer to Azure Function App Diagnostics Overview doc provided by Microsoft for knowing the issues, latency time related metrics and reports.

Best Practice to store Azure WebJob Logs incl. Data in Azure

I have several Azure WebJobs (.Net Framework, Not .Net Core) running which interact with an Azure Service Bus. Now I want to have a convenient way to store and analyze their Log-Messages (incl. the related Message from the Service Bus). We are talking about a lot of Log Messages per Day.
My Idea is to send the Logs to an Azure Event Hub and store them in an Azure SQL Database. Later I can have for example a WebApp that enables Users to conveniently browse and analyze the Logs and view the Messages.
Is this a bad Idea? Should I instead use Application Insights?
Application insight charges are more than your implementation. So i would say this is good idea. Just one change i would send each logs to logic apps and do some processing like sorting error logs, info logs etc differently. Also why are you thinking about SQL when this can be stored in non SQL Azure tables and fetch them from there.

Monitor when Azure Web App is unloaded?

What would be the best way to monitor when our Azure web app is being unloaded when no requests have been made to the web app for a certain amount of time?
Enabling Logstream for the web server doesn't seem to reveal anything of use..
Any hints much appreciated!
You can use Azure Application Insights to create a web test that will alert you when the site is not available anymore. It will ping your site from the data centers you select and perform some action you select (mail, webhook, etc).
However, if you want your web app to stay online, you could upgrade its plan to be at least basic, and under settings enable always on.
In addition to the kim’s response:
If you are running your web app in the Standard pricing tier, Web Apps lets you monitor two endpoints from three geographic locations.
Endpoint monitoring configures web tests from geo-distributed locations that test response time and uptime of web URLs. The test performs an HTTP GET operation on the web URL to determine the response time and uptime from each location. Each configured location runs a test every five minutes.
Uptime is monitored using HTTP response codes, and response time is measured in milliseconds. A monitoring test fails if the HTTP response code is greater than or equal to 400 or if the response takes more than 30 seconds. An endpoint is considered available if its monitoring tests succeed from all the specified locations.
Web Apps also provides you with the ability to troubleshoot issues related to your web app by looking at HTTP logs, event logs, process dumps, and more. You can access all this information using our Support portal at http://.scm.azurewebsites.net/Support
The Azure App Service support portal provides you with three separate tabs to support the three steps of a common troubleshooting scenario:
-Observe current behavior
-Analyze by collecting diagnostics information and running the built-in analyzers
-Mitigate
If the issue is happening right now, click Analyze > Diagnostics > Diagnose Now to create a diagnostic session for you, which collects HTTP logs, event viewer logs, memory dumps, PHP error logs, and PHP process report.
Once the data is collected, the support portal runs an analysis on the data and provides you with an HTML report.
In case you want to download the data, by default, it would be stored in the D:\home\data\DaaS folder.
Hope this helps.

Can ApplicationInsights track events across many WebApps/LogicApps/etc?

I have the following resources
One Mobile/API app
One MVC app
Three Logic apps
One Azure function deployment with 5 functions
I want to have a single tracking number (correlation ID) to track across all instances at the same time. I'm looking at the Contoso Insurance sample, but I'm rebuilding it by hand (not using Azure Deploy scripts).
I've read the deployment code, but I'm not sure if I can merge app insight logs together, or if it's a hack of some sort.
Observations
When I right click on visual studio, I can only associate to Application insights instances that aren't already connected to a *app (web | mobile | api).
However, in the configuration, I can give Application insights a direct GUID which might allow me to achieve the goal of one App Insights activity log for the entire process
Question
Is it possible to have one app insights log among all Mobile/API/Logic/MVC sites?
Is there a way to have (or should I have) one standard app insights instance per web app, then a special dedicated shared app insights instance for my code to call into and log?
What is contoso insurance doing with Azure App Insights?
Jeff from Logic Apps team here -- So the answer is yes - but there are some caveats. We are working to make the experience seamless and automatic, but for now it will require the following. First as a heads up:
First, for Logic Apps we have what's called the client tracking ID -- this is a header you can set on an incoming HTTP Request or Service Bus message to track and correlate events across actions. It will be sent to all steps (functions, connectors, etc.) with the x-ms-client-tracking-id header.
Logic Apps emits all logs to Azure Monitor - which unfortunately today only has a sink into Event Hubs, Storage, and Log Analytics -- not App Insights.
With all of that in-mind, here's the architecture we see many following:
Have your web apps just emit to App Insights directly. Use some correlation ID as needed. When firing any Logic Apps, pass in the x-ms-client-tracking-id header so you can correlate events.
Log your events to App Insights in the Function app. This blog details some of how to do that, and it is also being worked on for a better experience soon.
In your logic app - either write a Function to consume events off of Azure monitor and push to App Insights, or write a function that is an App Insight "logger" that you can call in your workflow to also get the data into App Insights.
This is how Contoso Insurance is leveraging App Insights as far as I understand. We are working across all teams (App Insights, Azure Monitor, Azure Functions, Logic Apps) to make this super-simple and integrated in the coming weeks/months, but for now achievable with above. Feel free to reach out for any ?s

Resources