Node.js/Express 的应用洞察

Application Insights with Node.js / Express

我收集了越来越多的 Node.js Express 服务,每个服务都有一个运行状况检查端点,每隔几秒就会被 ping 一次。

我已经添加了 Azure App Insights,它会按预期为每个请求捕获数据。

我的问题是我只需要 send/collect 来自特定端点和特定操作的数据,而不是每个请求。所以我真的只需要有一个默认客户端的实例,并在任何需要的地方使用它。

在我的 app.ts 文件中,我有这样的东西:

import appInsights from "applicationinsights";
.
..
...
appInsights
    .setup(<my app insights key>)
    .start();
.
..
...
const client = appInsights.defaultClient;

有什么建议或好的例子吗?

如果您使用的是 expressjs,您可以创建一个包含 appInsights 的单独中间件。然后将该中间件添加到您要跟踪的路由中。

即:app.use('/myroute',appInsightMiddleware, routes)