{"id":24917,"library":"applicationinsights-express-middleware","title":"Application Insights Express Middleware","description":"A package that monkey-patches Express and the Application Insights SDK for Node.js to automatically track Express middleware execution as dependency telemetry. It provides a setAutoCollectExpressMiddleware() method to enable collection, sending trackDependency() calls with middleware names and durations. Current version 0.0.5, last updated in May 2020. This is an early-stage project with no production guarantee; it is a WIP and likely has bugs. It targets the deprecated Azure Application Insights SDK and is not maintained actively. Consider the official @opentelemetry/instrumentation-express and @azure/monitor-opentelemetry for modern use cases.","status":"deprecated","version":"0.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/asos-craigmorten/applicationinsights-express-middleware","tags":["javascript","application insights","express monitoring","middleware monitoring","dependency monitoring","microsoft","azure","cloud","tracing","typescript"],"install":[{"cmd":"npm install applicationinsights-express-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add applicationinsights-express-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add applicationinsights-express-middleware","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; patches its SDK","package":"applicationinsights","optional":false},{"reason":"Peer dependency; requires Express to be installed and already loaded","package":"express","optional":false}],"imports":[{"note":"This package has no default export; side-effect require only.","wrong":"import applicationinsightsExpress from 'applicationinsights-express-middleware'","symbol":"default","correct":"require('applicationinsights-express-middleware')"},{"note":"Method is added to the applicationinsights instance after requiring the middleware package, not exported directly.","wrong":"require('applicationinsights-express-middleware').setAutoCollectExpressMiddleware(true)","symbol":"setAutoCollectExpressMiddleware","correct":"appInsights.setup('key'); appInsights.setAutoCollectExpressMiddleware(true); appInsights.start();"},{"note":"ApplicationInsights SDK is CommonJS only; cannot be imported as named ES module.","wrong":"import { ApplicationInsights } from 'applicationinsights'","symbol":"ApplicationInsights","correct":"const appInsights = require('applicationinsights');"}],"quickstart":{"code":"// run: npm install applicationinsights-express-middleware applicationinsights express\n\nrequire('applicationinsights-express-middleware');\nconst appInsights = require('applicationinsights');\nconst express = require('express');\n\nconst app = express();\n\nappInsights\n  .setup(process.env.APPINSIGHTS_INSTRUMENTATIONKEY ?? '')\n  .setAutoCollectExpressMiddleware(true)\n  .start();\n\napp.get('/', (req, res) => {\n  res.send('Hello World');\n});\n\napp.listen(3000, () => console.log('Listening on 3000'));","lang":"javascript","description":"Enables automatic tracking of Express middleware as dependencies in Azure Application Insights."},"warnings":[{"fix":"Migrate to @opentelemetry/instrumentation-express and @azure/monitor-opentelemetry.","message":"Project is abandoned; last release in 2020. Uses deprecated Azure Application Insights SDK.","severity":"deprecated","affected_versions":">=0.0.1"},{"fix":"Update your code to use the new internal names if you relied on undocumented internals.","message":"v0.0.5 renamed 'wrap' to 'patch' internally; API unchanged but internal monkey-patching changed.","severity":"breaking","affected_versions":">=0.0.5"},{"fix":"Reorder requires: require('applicationinsights-express-middleware') first, then applicationinsights, then express.","message":"Must require this package before both applicationinsights and express.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Restart the application to stop tracking.","message":"No support for dispose(); cannot stop instrumentation once started.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Use @azure/monitor-opentelemetry with @opentelemetry/instrumentation-express instead.","message":"Azure Application Insights SDK is deprecated in favor of OpenTelemetry-based SDK.","severity":"deprecated","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure you require('applicationinsights-express-middleware') before const appInsights = require('applicationinsights').","cause":"The middleware package was not required (or required after applicationinsights), so the method was not added to appInsights object.","error":"TypeError: appInsights.setAutoCollectExpressMiddleware is not a function"},{"fix":"Run npm install applicationinsights-express-middleware.","cause":"Package not installed or missing from node_modules.","error":"Error: Cannot find module 'applicationinsights-express-middleware'"},{"fix":"Call appInsights.setup('key').start() after requiring the middleware package.","cause":"Application Insights not started or not configured properly.","error":"Cannot read properties of undefined (reading 'trackDependency')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}