【问题标题】:How to query Azure App Insights logs using Node.JS如何使用 Node.JS 查询 Azure App Insights 日志
【发布时间】:2022-06-16 13:46:45
【问题描述】:
【问题讨论】:
标签:
node.js
typescript
azure
logging
【解决方案1】:
如何使用 Node.JS 查询 Azure App Insights 日志
- 在 Azure 门户中,创建 Application Insights 实例并从概览页面复制检测密钥
- 在 Visual Studio 代码中创建示例 NodeJS Web App
- 我们可以在 localhost 中添加检测密钥,也可以在 nodejs 应用程序部署到 Azure 后更新一次。这里我添加了所需的应用程序洞察设置并部署了应用程序
- 在
server.js,添加
let appInsights = require('applicationinsights');
appInsights.setup("cc580d32-a7eb-41d7-b0e0-90ea0889fd10");
appInsights.start();
npm install applicationinsights --save
在 Application Insights 中查看日志
- Application Insights 查询基于 KQL
- 导航到 Azure 门户 => 你的
Application Insights 实例 => Logs 在监控下 => 点击跟踪
使用 Node.Js 的单个资源的指标