Persistent application logs for NodeJS app on azure app service - node.js

I have a nodejs app which is nothing but a BOT built using Microsoft's bot builder framework. I created an azure app service to host this app. I would like to find a way to persist all the application logs and web server logs as well (if possible) to some persistent store. Just like native web applications where we can look up logs on a app server & debug the application issues.
After doing some research I found official document from microsoft on this but looks like it has following limitations.
We can't use file storage option of app service as it's good for 12
hours only so logs will not be saved forever.
Currently only .NET application logs can be written to the blob
storage. Java, PHP, Node.js, Python application logs can only be
stored on the file system (without code modifications to write logs
to external storage).
I would like to check if anyone has tried any different approach for nodejs app. If yes then please share.
Thank you.

So I would respond by saying that this is not really a Bot specific problem... meaning you would have the same problem if you were writing a vanilla Web API and wanted to have persistent logs. You need to pick on a logging technology that let's you log to a more persistent store than just the file system.
Since you're using Node you might want to look at leveraging the Winston logging framework which has an abstraction for various transports to be plugged in. Then you would plug in the Azure Storage Blob Transport when running in production and that will ensure that your logs are written out to Azure Storage.
Still, you'd have to go collect those from Azure Storage and aggregate them yourself which can be painful. If you really want real-time a distributed tracing system though, you might want to look into using Application Insights instead. There's even a Winston transport for that as well if you want to stay abstracted from using AI directly and just use it as another log stream.

Related

Browser-less server-side websockets client in Azure

I have an azure static web app that gets data via azure functions written in javascript.
I would like to subscribe to external data push services using wss websockets. The socket may be open for up to 24 hours. I thought, having read some answers on SO that I might be able to do this using durable functions but it appears that it isn't possible.
Almost all examples of using websockets in azure I've seen create a server, eg with SignalR, and communicate with the browser.
This helps. It shows how to build a server-side websockets client in a webjob
https://mikewaniewski.wordpress.com/2015/06/14/websocket-client-as-azure-webjob/
but as it is from 2015 I wondered if there more recent technologies available to do the same thing? Before I go about setting all that up.
Thanks in advance

Do you recommend using loggers like bunyan or morgan for application hosted on Azure App Services

I have Node.JS Application and I implemented Morgan and Bunyan logger in my application.
later on I published my application on Azure App services, Azure app services has Application Insights and log feature where it logs all the errors on my application and provides details about status of my application API calls ...etc. now I want to know do we still need to add loggers in our application, what do you suggest. Thanks.
If you're planning on deploying Node.js code on Azure I would recommend taking a look at a standard approach using Application Insights for your logging needs : more info here
Unless you want to be cloud agnostic to eventually deploy on other cloud providers I would stick with standard approches and not add additional modules/layers.
Yes,as far as I know you can use Bunyan as a logger in your node.js application and use Azure storage to store logs.
This blog talked it well. Azure web sites mentioned in this blog is Azure App Services' earlier name.

Logging from an azure console app as a web job

I am in search for a good way to log various messages while being able to use functions, logic, monitoring, etc to get notified or run a certain task to fix a problem and notify someone.
What I have in mind is something like "If a specific error happens send me a notification or restart a service"
What I currently already have is an app service that holds 10 web jobs(continuous, triggered). Two of them use the Azure Web job SDK and the rest of them are plain .net core console apps. All of them generate structured logs using serilog and are saved to blob storage.
Is there something I am missing? I don't want to reinvent the wheel here.
You can use application insights with webjobs, more details are here.
You can also set an alert in application insights if error occurs, refer to this doc.
Any more questions please let me know.

Azure web app (nodejs) logs don't appear in blob storage but webjob logs do

I configured Azure Web App Application Logging (Diagnostics logs).
https://learn.microsoft.com/en-us/azure/app-service/web-sites-enable-diagnostic-log
I have a nodejs backend api (express) and a couple of webjobs hosted on the same webapp.
I use console.info/console.error in the code for logging.
In the logstream/console in the portal I can see that logs coming from the webjobs are formatted with date, pid, level, ... but logs coming from the actual application are not formated.
Example of 2 console.info. First is from the api and 2nd from one webjob :
Start handling command DeleteCustomerCommand
2018-01-12T17:02:16 PID[9484] Information CustomerDeletedEvent handled
The problem is that in the blob storage, only the logs coming from webjobs are stored. I suppose this format is a requirement from Azure.
Do you know why the console.info behaves differently ? Can I do something to have the same behavior in the api ?
Do you know why the console.info behaves differently?
Azure WebJobs and Azure Web Apps actually run in the different context. WebJobs is hosted on the Kudu SCM site, and it is executed by Kudu API that captures the script log and formats it for you; while Web Apps is hosted on Microsoft IIS, and there's nothing built into the iisnode module to do this.
Can I do something to have the same behavior in the api?
You'll need to look into other modules to provide a richer formatting experience. For example: winston. Also, there is an Azure blob storage transport for winston.

How to deploy windows service on Azure App Service

I have developed a windows service. i need to deploy it in Azure App Service. Please someone explain me how to do that. Is there any way to install it on console or any other option.
You can't deploy a Windows Service using App Service. One option is to convert your code into a Web Job. Another option is to use a Virtual Machine instead of App Service.
Azure App Service is the service that should be used for Web/Mobile and basically is the web-server-as-a-service. You have almost no access to the underlying system, and system-wide actions like a working windows service is likely impossible.
I see three ways:
1) Migrate to Worker Role, but it is classic model. There is a good article on how to do that, i took a look and did not see any potential problems. It is more simple way.
2) Migrate your windows service to Web Job and run it as a background service. It will need you to rewrite some parts of your service, i think - but there are supported executable formats out-of-the-box. Take a look at how it works.
3) Take a look at Azure Functions - it is "trigger-and-invoke" service that can be used for listening for events and executing actions.
But, if you need to catch some events from DB, then i am not sure that it will be possible with that, because Web Job is more like a service that listens for external events, and yours scenario looks like you want to catch events from the same server. That way, i would recommend you to place it on a virtual machine to avoid the rewriting or migrating time-consuming issues.

Resources