I've a growing collection of Node.js Express services each has a health check endpoint that is pinged every few seconds.
I've added Azure App Insights and thats capturing data as expected for every request.
My problem is I need to only send/collect data from specific endpoints and for specific actions not every single request. So i really just need to have a single instance of the default client and use that wherever I need to.
Inside my app.ts file I have something like this:
import appInsights from "applicationinsights";
.
..
...
appInsights
.setup(<my app insights key>)
.start();
.
..
...
const client = appInsights.defaultClient;
Any advice or good quality examples?
If you're using expressjs, you could just create a separate Middleware that contains the appInsights. Then add that middleware to the routes you want to track.
i.e.: app.use('/myroute',appInsightMiddleware, routes)