How to instrument Instana APM with the Node Agent

  • Updated


Instrument Instana APM with the Contrast Node Agent


This article assumes you've followed the guide to install the Contrast Node agent: Install Contrast Node.js Agent


There are multiple ways to activate the Instana Node.js collector. This article will go over three ways of attaching the Contrast Node agent.

  1. Instana collector is initiated inside your application code (for example, index.js):
    // index.js


    // All other require statements must be done after the collector is initialized.
    // Note the () after the require statement of the collector which initializes it.

    // const express = require('express');
    The command to start your application and the Contrast Node agent would be:
    node -r @contrast/agent index.js
  2. Installing the Instana collector without modifying your application. You activate the Instana collector using --require:
    node --require ./node_modules/@instana/collector/src/immediate index.js
    We'll want to update this command to require the Contrast Node agent first:
    node -r @contrast/agent -r ./node_modules/@instana/collector/src/immediate index.js
  3. Using NODE_OPTIONS. Similar to #2, we'll add the require calls to the NODE_OPTIONS environment variable:
    NODE_OPTIONS="-r @contrast/agent -r ./node_modules/@instana/collector/src/immediate"
    Then start your application with node index.js.

The Instana collector checks the npm cache for other packages that are required before the collector. The collector logs a message that the instrumentation for that package won’t work as it was required before Instana. This check is not detrimental for the start of the APM, it continues with its execution.


Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request