Ingest logs from another application to a central, serverless monitoring resource in Azure.
Ingest logs from another application to a central, serverless monitoring resource in Azure.
Azure has some great observability tools when working with distributed applications.
This repo shows a way to ingest logs from another application—for example a frontend app—to a central monitoring resource: the one this code lets you deploy.
This specific example is very lightweight so adjust it for whatever your use-case is!
The stack is:
The code uses:
Azure Functions can be finicky so you’ll need to use Node 12 or similar to get this to work.
Install dependencies with npm install
, then run sls offline
. You can now start sending API requests to a local version of the API.
I’ve also added a tiny HTML page (“mini app”) to fire events if you need. You can find it under the app
folder.
Run sls deploy
.
The easiest way to see what comes in is Live metrics
and Transaction search
in the Application Insights pane. You can also use the other tools in the “Monitoring” category of Application Insights.
POST http://localhost:7071/api/log
{
"severity": "error",
"message": "Something caused an error to be thrown!",
"error": "{\"stack\":\"Error: Something caused an error to be thrown!\n at log (file:///Users/username/logs/app/index.html:32:25)\n at HTMLButtonElement.<anonymous> (file:///Users/username/logs/app/index.html:38:80)\",\"message\":\"Something caused an error to be thrown!\"}"
}
POST http://localhost:7071/api/log
{
"severity": "warn",
"message": "Whoops, this was awkward. Time for a warning :(",
"error": "{\"stack\":\"Error: Whoops, this was awkward. Time for a warning :(\n at log (file:///Users/username/logs/app/index.html:32:25)\n at HTMLButtonElement.<anonymous> (file:///Users/username/logs/app/index.html:39:79)\",\"message\":\"Whoops, this was awkward. Time for a warning :(\"}"
}