Registry / azure / applicationinsights-express-middleware

applicationinsights-express-middleware

JSON →
library0.0.5jsnpmunverified

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.

npm install applicationinsights-express-middleware
INSTALL
IMPORT
SIG · APPLICATIONINSIGHT
A
applicationinsights-express-middleware
azurejavascriptv0.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
require('applicationinsights-express-middleware')
import applicationinsightsExpress from 'applicationinsights-express-middleware'
This package has no default export; side-effect require only.
setAutoCollectExpressMiddleware
appInsights.setup('key'); appInsights.setAutoCollectExpressMiddleware(true); appInsights.start();
require('applicationinsights-express-middleware').setAutoCollectExpressMiddleware(true)
Method is added to the applicationinsights instance after requiring the middleware package, not exported directly.
ApplicationInsights
const appInsights = require('applicationinsights');
import { ApplicationInsights } from 'applicationinsights'
ApplicationInsights SDK is CommonJS only; cannot be imported as named ES module.

Enables automatic tracking of Express middleware as dependencies in Azure Application Insights.

// run: npm install applicationinsights-express-middleware applicationinsights express require('applicationinsights-express-middleware'); const appInsights = require('applicationinsights'); const express = require('express'); const app = express(); appInsights .setup(process.env.APPINSIGHTS_INSTRUMENTATIONKEY ?? '') .setAutoCollectExpressMiddleware(true) .start(); app.get('/', (req, res) => { res.send('Hello World'); }); app.listen(3000, () => console.log('Listening on 3000'));
Debug
Known issues
deprecatedProject is abandoned; last release in 2020. Uses deprecated Azure Application Insights SDK.
fix
Migrate to @opentelemetry/instrumentation-express and @azure/monitor-opentelemetry.
affects: >=0.0.1
breakingv0.0.5 renamed 'wrap' to 'patch' internally; API unchanged but internal monkey-patching changed.
fix
Update your code to use the new internal names if you relied on undocumented internals.
affects: >=0.0.5
gotchaMust require this package before both applicationinsights and express.
fix
Reorder requires: require('applicationinsights-express-middleware') first, then applicationinsights, then express.
affects: >=0.0.1
gotchaNo support for dispose(); cannot stop instrumentation once started.
fix
Restart the application to stop tracking.
affects: >=0.0.1
deprecatedAzure Application Insights SDK is deprecated in favor of OpenTelemetry-based SDK.
fix
Use @azure/monitor-opentelemetry with @opentelemetry/instrumentation-express instead.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: appInsights.setAutoCollectExpressMiddleware is not a function
The middleware package was not required (or required after applicationinsights), so the method was not added to appInsights object.
fix
Ensure you require('applicationinsights-express-middleware') before const appInsights = require('applicationinsights').
Error: Cannot find module 'applicationinsights-express-middleware'
Package not installed or missing from node_modules.
fix
Run npm install applicationinsights-express-middleware.
Cannot read properties of undefined (reading 'trackDependency')
Application Insights not started or not configured properly.
fix
Call appInsights.setup('key').start() after requiring the middleware package.
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies
applicationinsightsrequiredPeer dependency; patches its SDK
expressrequiredPeer dependency; requires Express to be installed and already loaded
Agent activity
57 hits · last 30 days
node
50
OpenAI (training)
1
Resources
applicationinsights-express-middleware — npm install applicationinsights-express-middleware · libregistry