Skip to main content
site24x7DevOpsnodejsexpressapm-insight

Stop Guessing Why Your Node.js App is Slow: A Guide to Site24x7 APM Insight

Usama Amjid
8 min read
6018 words
Stop Guessing Why Your Node.js App is Slow: A Guide to Site24x7 APM Insight

Have you ever had a user complain that your website is "laggy," but when you check your server, everything looks "fine"? Standard server monitoring tells you if the computer is on, but APM (Application Performance Monitoring) tells you what is happening inside your code.

Site24x7 APM Insight is like a high-speed camera for your Node.js application. it tracks every request, every database query, and every error, showing you exactly where the bottlenecks are.

What is Site24x7 APM Insight?

In simple terms, Site24x7 APM Insight is a monitoring tool that sits inside your Node.js app. It watches "Transactions"—which are the paths a request takes from the moment a user clicks a button to the moment they get a response.

Instead of just seeing a "500 Internal Server Error," APM Insight shows you the specific line of code that failed or the exact database query that took 5 seconds to finish.

Why use APM Insight?

  • See slow paths — find which endpoints, database calls, or external requests are taking the most time.
  • Trace errors — the agent groups exceptions with the transaction that triggered them.
  • Add business metrics — you can emit custom metrics (counts, averages) for things like cart size or payments.
  • Works in containers — Site24x7 provides Docker/Kubernetes instructions so it fits typical cloud deployments.

Quick checklist — what you need before starting

  • A Site24x7 account and an APM license key (you get the key from Site24x7 when adding an APM monitor).
  • Node.js v16.20.2+ (per Site24x7 requirements).
  • Access to restart your Node process (or rebuild your container).
  • (Optional) Dockerfile or Kubernetes access when using containers.

Step-by-step: add APM Insight to a Node.js + Express app

1) Install the agent

bash
npm install apminsight --save

Site24x7 documents this as the supported package for Node agent installs. (Documentation)

2) Configure the agent

Create a file named apminsightnode.json in the folder where you run your app (or use environment variables). Minimal file:

json
{
  "licenseKey": "<YOUR_LICENSE_KEY>",
  "appName": "my-express-app",
  "port": 3000
}

You may also set the same values with env vars such as APMINSIGHT_LICENSE_KEY, APMINSIGHT_APP_NAME, and APMINSIGHT_APP_PORT.

3) Load the agent before anything else

Agent must load before other modules so it can auto-instrument frameworks like Express.

javascript
// server.mjs (first lines)
import apminsight from 'apminsight';
apminsight.config(); // init before other imports

import express from 'express';
const app = express();
// ...

4) Restart and verify

Restart your Node process and make a few requests. Data should appear under your application monitor in the Site24x7 dashboard (it may take a short while to show).

Practical examples you’ll want in production

A) Name transactions (useful for grouping & dashboards)

By default requests are auto-detected and shown by the request path, but you can rename transactions for better grouping:

javascript
import apminsight from "apminsight";

app.get('/admin', (req, res) => {
  // Change how this transaction appears in traces
  apminsight.setTransactionName('/homepage');
  res.send('OK');
});

This helps group several routes under one logical transaction name.

B) Track background jobs / cron tasks

Background work is not auto-instrumented. Use the background API:

javascript
import apminsight from "apminsight";

function runRoutine() {
  apminsight.startBackgroundTransaction('daily-sync', () => {
    // long running job
    doSyncWork()
      .then(() => apminsight.endTransaction())
      .catch((err) => { apminsight.trackError(err); apminsight.endTransaction(); });
  });
}

This ensures background work appears in the APM traces.

C) Custom trackers for non-HTTP flows (sockets, jobs)

For socket events or manual chunks you can use startWebTransaction and startTracker:

javascript
import apminsight from "apminsight";

io.on('connection', (socket) => {
  apminsight.startWebTransaction('/socket/message', () => {
    // your code here
    apminsight.endTransaction();
  });
});

Or for a smaller component span:

javascript
apminsight.startTracker('readFile', 'FS', (done) => {
  fs.readFile(..., () => {
    done();
  });
});

These APIs let you capture traces for operations the agent would not auto-instrument.

D) Capture handled errors (so they link to the transaction)

If you catch an error but still want it reported to APM:

javascript
try {
  await something();
} catch (err) {
  apminsight.trackError(err); // records it as part of the current transaction
  // ... handle error ...
}

This is handy when you catch and handle errors but still want observability.

E) Emit custom metrics & parameters (business context)

Add small metrics or trace parameters that help you later:

javascript
// add contextual param (up to 10)
apminsight.addParameter('userId', user.id);

// increment a custom metric (sum)
apminsight.incrementCustomMetric('orders', 1);

// report an average metric
apminsight.averageCustomMetric('checkoutAmount', order.total);

Custom metrics give you business-level signals alongside performance telemetry.

Docker deployment (brief)

Site24x7 documents a minimal Docker approach:

  • Add apminsight to package.json or RUN npm install apminsight in your Dockerfile.
  • Ensure the agent is loaded on process start: either prefix node -r apminsight in your CMD/ENTRYPOINT, or have require('apminsight') as the first line in your app start file. Example:
dockerfile
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
ENV APMINSIGHT_LICENSE_KEY="your_key"
CMD ["node", "-r", "apminsight", "server.js"]

You can also copy apminsightnode.json into the image or pass config via env vars like APMINSIGHT_LICENSE_KEY and APMINSIGHT_APP_NAME.

Best practices & production tips

  • Load the agent first. The agent must be the very first thing your process loads so it can patch frameworks.
  • Keep context small. Use the agent to store small IDs and metrics — don’t stash large objects in the APM context.
  • Instrument background jobs. Jobs are invisible unless you explicitly call the background API.
  • Watch agent logs & resource use. Verify the agent’s log directory and check memory/CPU on rollout; Site24x7 provides troubleshooting docs.
  • Use env vars in containers. Passing keys and app names via env vars simplifies CI/CD and secrets handling.
  • Test upgrades in staging. The Node agent evolves; test upgrades in staging to confirm instrumentation works with your middleware and libraries.

Common issues & how to debug

  • No data in dashboard: confirm license key & app name are correct, agent loaded first, and your app made requests after restart.
  • Transactions not grouped how you expect: use setTransactionName() or custom trackers to create meaningful groupings.
  • Background jobs missing: instrument them with startBackgroundTransaction.

Short migration checklist to add APM Insight to an existing Express app

  1. Add apminsight to package.json.
  2. Create apminsightnode.json or set env vars with license & app name.
  3. Require/import the agent as the first line in your start file.
  4. Restart & smoke test — hit main endpoints and check the Site24x7 APM dashboard.
  5. Add a few custom metrics and error tracking points in critical flows (payment, checkout, sign-in).

Short summary / TL;DR

Site24x7’s APM Insight is a performance monitoring tool that helps you see how your applications behave in real time — measuring key metrics like response time, throughput, errors, and transaction details. You install a small agent in your app (e.g., for Node.js) to automatically collect and send data to your Site24x7 dashboard, so you can spot bottlenecks, slow DB calls, or spikes in errors before they affect your users.

Written by

Usama Amjid

Backend Engineer & Node.js Architect

Get in Touch