将 Application Insights 集成到开发人员门户
Application Insights 是 Azure Monitor 的常用功能。 它是面向开发人员和 DevOps 专家的可扩展应用程序性能管理 (APM) 服务。 使用它来监视开发人员门户并检测性能异常。 Application Insights 包含功能强大的分析工具,可帮助你了解用户在访问开发人员门户时实际执行的操作。
按照以下步骤将 Application Insights 插入托管的或自承载的开发人员门户。
重要
托管门户不需要执行步骤 1 - 3。 如果有托管门户,请跳到步骤 4。
为最新版本的开发人员门户设置本地环境。
安装 npm 包以添加用于 Azure 的 Paperbits:
npm install @paperbits/azure --save
在
src
文件夹的startup.publish.ts
文件中导入并注册 Application Insights 模块。 在依赖项注入容器中的现有模块之后添加AppInsightsPublishModule
:import { AppInsightsPublishModule } from "@paperbits/azure"; ... const injector = new InversifyInjector(); injector.bindModule(new CoreModule()); ... injector.bindModule(new AppInsightsPublishModule()); injector.resolve("autostart");
使用内容项 - 获取 REST API 检索门户的配置:
GET https://management.chinacloudapi.cn/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.ApiManagement/service/{api-management-service-name}/contentTypes/document/contentItems/configuration?api-version=2021-08-01
输出类似于:
{ "id": "/contentTypes/document/contentItems/configuration", "type": "Microsoft.ApiManagement/service/contentTypes/contentItems", "name": "configuration", "properties": { "nodes": [ { "site": { "title": "Azure API Management - developer portal", "description": "Discover APIs, learn how to use them, try them out interactively, and sign up to acquire keys.", "keywords": "Azure, API Management, API, developer", "faviconSourceId": null, "author": "Azure API Management" } } ] } }
使用 Application Insights 配置扩展上一步中的站点配置。 使用内容项 - 创建或更新 REST API 更新配置。 在请求正文中的
integration
节点中传递 Application Insights 检测密钥。PUT https://management.chinacloudapi.cn/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.ApiManagement/service/{api-management-service-name}/contentTypes/document/contentItems/configuration?api-version=2021-08-01
{ "id": "/contentTypes/document/contentItems/configuration", "type": "Microsoft.ApiManagement/service/contentTypes/contentItems", "name": "configuration", "properties": { "nodes": [ { "site": { ... }, "integration": { "appInsights": { "instrumentationKey": "xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxx" } } } ] } }
更新配置后,重新发布门户才能使更改生效。
详细了解开发人员门户: