Node.js

Supported Node.js versions

Automatic tracing is supported in the following Node.js versions:

Node.js versions Support status
4.5 and above GA
5.10 and above GA
6.0.0 and above GA
7.0.0 and above GA
8.2.1 and above GA
9.1.0 and above GA
10.4.0 and above GA
11.0.0 and above GA

This means that automatic tracing works for example for all 4.x versions beginning with 4.5, but not for 4.0.0 - 4.4.x. Similar version ranges are given for the other Node.js release lines, for example Node.js 10.x is supported beginning with 10.4.0; automated tracing is not supported for Node.js releases 10.0.0 - 10.3.x.

Metrics, configuration data and manual tracing via the OpenTracing API is supported in versions 4.0.0 and above.

Installation

The installation of the Instana Node.js sensor is a simple two step process. First, install the instana-nodejs-sensor package in your application via:

npm install --save instana-nodejs-sensor

Now that the sensor is installed, it needs to be activated from within the application. Do this by requiring and initializing it as the first statement in your application. Please take care that this is the first statement as the sensor will otherwise not be able to access certain information.

require('instana-nodejs-sensor')();

The code shown above initializes the sensor with default configuration options. Refer to the CONFIGURATION.md file for a list of valid configuration options.

Common Pitfalls

Incorrectly integrating the sensor will usually lead to a loss of observability. Your Node.js application will still be shown in Instana but tracing will only work partially. Some calls will be traced but others will be missing.

Important: It is not enough to only have the require statement as the first statement in your application and calling the function exported by require('instana-nodejs-sensor') later. That is, the following is not supported:

// WRONG!
const instana = require('instana-nodejs-sensor');

require('something');
require('another-thing');

instana(); // TOO LATE!
...

Instead, the function exported by require('instana-nodejs-sensor') must be called right away, before any other require or import statements. This can either be done in one statement as shown above (note the second pair of parantheses in require('instana-nodejs-sensor')()) or in two consecutive statements:

// Correct:
const instana = require('instana-nodejs-sensor');
instana(); // this is fine

// Now all other modules can be required:
require('something');
require('another-thing');
...

The same constraint applies if you are using ES6 module syntax. The following is not supported:

// WRONG!
import instana from 'instana-nodejs-sensor';

import { something, else } from 'some-module';
import anotherThing from 'another-module';

instana(); // TOO LATE!
...

Instead, do this:

import instana from 'instana-nodejs-sensor';
// You need to call the exported function *immediately*, before importing anything else.
instana();

// Now all other modules can be imported:
import { something, else } from 'some-module';
import anotherThing from 'another-module';
...

Updating the instana-nodejs-sensor Package

We continuously improve the Instana Node.js support and recommend to always use the latest available version of the instana-nodejs-sensor package to benefit from the these improvements. Updating the package to its latest version everytime you build/roll out your app is a good practice. Updating works just like with any other npm package.

After the initial npm install --save instana-nodejs-sensor (see above), your package.json will contain a dependency declaration like "instana-nodejs-sensor": "^1.55.1". The caret (^) denotes a SemVer version range (in this example ^1.55.1 stands for >= 1.55.1 && < 2.0.0). The version ranges dictates the behaviour of the npm install and npm update commands.

Specifiying the version as "instana-nodejs-sensor": "1.55.1" (without the caret or more generally, without using a version range) would pin that exact version, that is, npm install and npm update would always use version 1.55.1. This is not recommended. Check out the npm docs on version ranges for more details.

  • Executing npm update instana-nodejs-sensor in your project will install the latest version that matches the version range in your package.json file. It will also update the version range string in package.json. If a lockfile (package-lock.json) is present, it too will be updated accordingly. See the docs for npm update.
  • Executing npm install in your project will also install the latest version that matches the version range in your package.json file, but only if

    1. the node_modules folder does not already contain a version of instana-nodejs-sensor that matches the version range, and
    2. no package-lock.json file is present that locks the version of the package.

In conclusion, if you build your app on CI and do a fresh npm install every time (you don’t keep the node_modules folder between builds), and if you do not commit package-lock.json to version control, running npm install as a build step is sufficient to get the latest version. In all other cases (keeping node_modules between builds and/or having package-lock.json in version control, it is recommended to run npm update instana-nodejs-sensor as part of your build.

If you use yarn instead of npm, please refer to the yarn documentation, in particular yarn update for details, but basically the recommendations and procedures are the same.

Supported Libraries

HTTP
HTTP(s) servers
HTTP(s) clients
Express error handling & path templates
Fastify path templates
koa-router path templates
RPC
GRPC
Databases
Elasticsearch
MongoDB
Mongoose
MySQL
MSSQL
Postgres
Redis
ioredis
Messaging
kafka-node
RabbitMQ/amqplib
Logging
Bunyan
Pino
Winston
Async
Timers
Native Promises
Bluebird Promises

Sensor Data Collection

Tracked Configuration Metrics
Runtime Versions GC Activity
Deployed Apps Memory Usage
Name Heap Spaces
Version Event Loop
Description HTTP Servers - Request/Response Times
Arguments Health check status and time of last status change
Dependencies
HTTP Servers Config
Health checks (via admin-plugin-healthcheck )  

Health Signatures

  • Garbage Collection Activity
  • Latency
  • Calls
  • Errors
  • Failing health checks (see Health Check Support below)

Health check support

The Instana Node.js sensor will conduct custom health checks and execute them every ten seconds. If the checks fail for at least 30 seconds, an issue will be raised to inform the user.

Health checks are gathered from installed admin-plugin-healthcheck modules.

health check

Health checks listed in the Node.js dashboard.

issue

Issue raised about failing health checks.

Tracing

Mode

OpenTracing

To instantiate the Node.js OpenTracing tracer:

const instana = require('instana-nodejs-sensor');

// Always initialize the sensor as the first module inside the application.
instana({
  tracing: {
    enabled: true
  }
});

const opentracing = require('opentracing');

// optionally use the opentracing provided singleton tracer wrapper
opentracing.initGlobalTracer(instana.opentracing.createTracer());

// retrieve the tracer instance from the opentracing tracer wrapper
const tracer = opentracing.globalTracer();

See https://github.com/instana/nodejs-sensor#opentracing for details.