Azure Application Insights 是一种监视服务,用于捕获遥测数据,例如请求详细信息、性能计数器、日志和异常。 将其与数据 API 生成器(DAB)集成有助于诊断问题并监视生产中的运行时行为。
警告 使用 Azure 应用服务 Web 应用托管 DAB 时,不支持 Application Insights。
配置
若要在 DAB 配置中配置 Application Insights,请执行以下作:
CLI 示例
dab add-telemetry \
--app-insights-enabled true \
--app-insights-conn-string "@env('app-insights-connection-string')"
JSON 示例
"runtime": {
...
"telemetry": {
"application-insights": {
"enabled": true,
"connection-string": "@env('app-insights-connection-string')"
}
}
...
}
这假定 app-insights-connection-string
设置为环境变量。 可以使用 .env
文件来定义它。
捕获的内容
类型 | DESCRIPTION |
---|---|
请求遥测 | URL、状态代码、响应时间 |
追踪遥测 | DAB 中的控制台日志 |
异常遥测 | 错误和堆栈跟踪 |
性能计数器 | CPU、内存、网络指标 |
在 Azure 中查看
- 在 Azure 管理门户中转到 Application Insights (应用洞察) 资源: https://portal.azure.com
- 使用此查询查看日志:
traces
| order by timestamp
LogLevel 映射:
LogLevel | 严重程度 | 价值 |
---|---|---|
跟踪 | 详细 | 0 |
调试 | 详细 | 0 |
信息 | 信息 | 1 |
警告 | 警告 | 2 |
错误 | 错误 | 3 |
危急 | 危急 | 4 |
- 检查 实时指标
- 针对请求运行此查询:
requests
| order by timestamp
- 针对异常运行此查询:
exceptions
| order by timestamp