Objective
Instrument Instana APM with the Contrast Node Agent
Process
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.
- Instana collector is initiated inside your application code (for example,
index.js
):// index.js
The command to start your application and the Contrast Node agent would be:
require('@instana/collector')()
// 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');node -r @contrast/agent index.js
- 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
- 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 withnode 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.