Ops AI Node.js / Express APM Configuration

Use the Middleware Node.js SDK to instrument your Node/Express service so Ops AI can analyze production issues and, when possible, generate solution PRs. The SDK supports function code capture for runtime exceptions and is designed to work seamlessly with Express. Use SDK v2.2.0+.

What you’ll set up

  • SDK install via npm
  • Tracker initialization at the very top of your entry file (before any other imports)
  • Express error capture with registerErrorHandler(app)
  • VCS metadata (recommended) so Ops AI can link errors to exact files/commits and propose a PR

1. Install

1npm install @middleware.io/node-apm --save

Use version 2.2.0 or newer.

2. Initialize the tracker (top of entry file)

Place the tracker before you import Express or any other module. This ensures all downstream code runs under tracing.

1// index.js
2const tracker = require('@middleware.io/node-apm');
3tracker.track({
4  serviceName: "your-service-name",
5  accessToken: "<MW_API_KEY>",
6});
7// Import other modules after tracker.track()
8const express = require('express');
9// ...rest of your app
  • serviceName is how the service will appear in APM.
  • accessToken is your Middleware account key (from the Installations page).

3. Capture exception code in Express

Register the Middleware’s error handler on your Express app to capture the function code where the exception occurred (this fuels Ops AI’s analysis).

1const { registerErrorHandler } = require('@middleware.io/node-apm');
2
3// ... define routes above ...
4
5// Register after your routes/middleware:
6registerErrorHandler(app);

This enables the exception code capturing feature shown on the Node/Express page.

4. (Recommended) Provide VCS metadata for Ops AI

If your app has a .git directory at runtime, the SDK automatically fetches the repository URL and commit SHA. If you build into a container or deploy without .git, set the following environment variables before starting your app:

1export MW_VCS_COMMIT_SHA="$(git rev-parse HEAD)"
2export MW_VCS_REPOSITORY_URL="$(git config --get remote.origin.url)"
3node index.js

Providing VCS metadata helps Ops AI correlate incidents to the right file/line and generate solution PRs against the correct commit/branch. (You can set these via CI/CD as well.)

Optional: add release/version tagging

If you want APM data segmented by deployment version, include a custom resource attribute:

1tracker.track({
2  serviceName: 'your-service-name',
3  accessToken: '<MW_API_KEY>',
4  customResourceAttributes: {
5    'app.version': '1.2.0',
6  },
7});

This pattern mirrors the Node APM guidance for distinguishing deploys.

Validate Your Setup

  • SDK loaded first: confirm tracker.track() is the first thing in your entry file (before require('express')).
  • Exceptions captured: trigger a test error in a dev environment and check that the function code appears with the error event.
  • VCS metadata present: ensure the two env vars are set (or .git exists) so Ops AI can map errors to code and propose PRs.

Need assistance or want to learn more about Middleware? Contact our support team at [email protected] or join our Slack channel.