项目作者: mikaelvesavuori

项目描述 :
Ingest logs from another application to a central, serverless monitoring resource in Azure.
高级语言: TypeScript
项目地址: git://github.com/mikaelvesavuori/azure-observability.git
创建时间: 2021-03-02T13:38:38Z
项目社区:https://github.com/mikaelvesavuori/azure-observability

开源协议:

下载


Azure observability: Logging frontend errors to Application Insights

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:

Instructions

Prerequisites

  • Azure account
  • Logged into the Azure environment
  • Sufficient credentials to set up required infrastructure

Local development

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.

Build and deploy

Run sls deploy.

See logs and metrics

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.

API call examples

Error

  1. POST http://localhost:7071/api/log
  2. {
  3. "severity": "error",
  4. "message": "Something caused an error to be thrown!",
  5. "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!\"}"
  6. }

Warning

  1. POST http://localhost:7071/api/log
  2. {
  3. "severity": "warn",
  4. "message": "Whoops, this was awkward. Time for a warning :(",
  5. "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 :(\"}"
  6. }

References