Node.js Collector Configuration

For most use cases it is sufficient to just initialize the Instana Node.js collector with require('@instana/collector')(); and leave the default configuration options in place. You can also pass in a configuration object when initializing the Instana Node.js collector:

  // configuration options, see as follows

Additionally, you can configure the Node.js collector via environment variables.

Agent Communication

Agent Host

The collector tries to communicate with the Instana agent via IP and as a fallback via the host's default gateway. Should the agent not be available under either of these IPs, you can use the agentHost option to use a custom IP.

  agentHost: '::1' // use IPv6 to contact via localhost

Or leverage an environment variable.

  agentHost: process.env.HOST_IP

If not configured, the Instana collector will look for an environment variable called INSTANA_AGENT_HOST and use what is defined in this environment variable to communicate with the agent. If there is no such environment variable, it will try to contact the agent first on localhost and then on the default gateway.

Agent Port

The collector tries to communicate with the Instana Agent via port 42699. Should the port have been changed, you can use the agentPort option to change the port.

  agentPort: 42699

If not configured, the Instana collector will look for an environment variable called INSTANA_AGENT_PORT and use what is defined in this environment variable to communicate with the agent. If there is no such environment variable, it will fall back to the default port 42699.

Kubernetes & OpenShift

If your Node.js application and the Instana agent run in a Kubernetes cluster, check the documentation on Kubernetes network access for information about the required configuration in this setup.


The tracing feature is enabled by default. To disable it, pass the following option to the initialization function:

  tracing: {
    enabled: false

You can also disable tracing by setting the environment variable INSTANA_DISABLE_TRACING=true.

When tracing is disabled, you can neither use the trace SDK nor the OpenTracing API, and automatic tracing will also be disabled. Calls using the SDK or OpenTracing will be silently ignored.

Disabling Automatic Tracing

Automatic tracing is also enabled by default. To disable only automatic tracing (leaving manual tracing via the SDK or openTracing enabled), pass the following option to the initialization function:

  tracing: {
    automaticTracingEnabled: false

Finally, you can disable automatic tracing by setting the environment variable INSTANA_DISABLE_AUTO_INSTR=true.

When automatic tracing is disabled, you can still use the SDK or the OpenTracing API to create spans manually.

Disabling OpenTelemetry integration

The Opentelemetry integration is enabled by default. To disable the integration, pass the following option to the initialization function:

  tracing: {
    useOpentelemetry: false

Moreover, you can disable the OpenTelemetry integration by setting the INSTANA_DISABLE_USE_OPENTELEMETRY variable to true. For more information, see Instana environment variables.

Capturing Stack Traces

By default, the collector captures the last ten call sites for every captured exit span. This value can be increased and decreased as necessary. (Note that the stack traces of HTTP entry spans are not collected – they would only show Node.js core code.) Use a value of 0 to disable stack trace capturing.

  tracing: {
    stackTraceLength: 10

You can also configure the stack trace length by setting the environment variable INSTANA_STACK_TRACE_LENGTH.

Configuring a custom package.json path

The Instana collector attempts to locate the primary package.json file within your project to extract important information like your application's name. If you need to define a custom path for your package.json file or if the collector is unable to locate the file, then you can use the configuration option named packageJsonPath.

  packageJsonPath: 'absolute/path/to/package.json'

You can also configure the path for the package.json file by setting the INSTANA_PACKAGE_JSON_PATH environment variable.

Disabling Individual Tracers

Since: 1.80.0

You can disable individual tracing instrumentations. This should only be used in special circumstances or for troubleshooting.

  tracing: {
    disabledTracers: ['graphql', 'grpc']

Alternatively, this can be archived by setting the environment variable INSTANA_DISABLED_TRACERS to a comma separated list of tracers you want to disable:


Possible values (case insensitive):

  • amqp: Disables instrumentation of the amqplib package for RabbitMQ/amqp tracing.
  • bunyan: Disables instrumentation of the bunyan package for Bunyan warn/error log message collection.
  • db2: Disables instrumentation of the ibm_db package for IBM DB2 tracing.
  • couchbase: Disables instrumentation of the couchbase package for Couchbase tracing.
  • elasticsearchLegacy: Disables instrumentation of the elasticsearch package for Elasticsearch tracing (legacy client).
  • elasticsearchModern: Disables instrumentation of the @elastic/elasticsearch package for Elasticsearch tracing (modern client).
  • express: Disables instrumentation of the express package for Express path template collection.
  • fastify: Disables instrumentation of the fastify package for Fastify path template collection.
  • graphql: Disables instrumentation of the packages graphql and @apollo\/gateway for GraphQL tracing.
  • grpc: Disables instrumentation of the grpc package for gRPC tracing.
  • grpcjs: Disables instrumentation of the @grpc/grpc-js package for JavaScript gRPC tracing.
  • hapi: Disables instrumentation of the @hapi/call package for path template collection for Hapi.
  • httpClient: Disables instrumentation of the core http and https modules for tracing of outgoing HTTP(S) calls (exits).
  • httpServer: Disables instrumentation of the core http and https modules for tracing of incoming HTTP(S) calls (entries).
  • ioredis: Disables instrumentation of the ioredis package for Redis tracing (also see option redis).
  • kafkaJs: Disables instrumentation of the kafkajs package for Kafka tracing (also see option kafkaNode).
  • kafkaNode: Disables instrumentation of the kafka-node package for Kafka tracing (also see option kafaJs).
  • koa: Disables instrumentation of the koa-router package for Koa path template collection.
  • log4js: Disables instrumentation of the log4js package for warn/error log message collection.
  • mongodb: Disables instrumentation of the mongodb/mongodb-core package for MongoDB tracing.
  • mssql: Disables instrumentation of the mssql package for MSSQL tracing.
  • mysql: Disables instrumentation of the mysql and `mysql2' packages for MySQL tracing.
  • natsStreaming: Disables instrumentation of the node-nats-streaming package for NATS streaming (but not NATS) tracing (also see option nats).
  • nats: Disables instrumentation of the nats package for NATS (but not NATS streaming) tracing (also see option natsStreaming).
  • pgNative: Disables instrumentation of the pg-native package for PostgreSQL tracing (also see option (pg).
  • pg: Disables instrumentation of the pg package for PostgreSQL tracing (also see option pgNative).
  • pino: Disables instrumentation of the pino package for warn/error log message collection.
  • redis: Disables instrumentation of the redis package for Redis tracing (also see option ioredis).
  • winston: Disables instrumentation of the winston package for warn/error log message collection.

Service Naming

Services are a central concept within Instana. Calls, spans and traces are closely associated to services. By default, the Node.js collector will use the name and version attribute from the main package.json file. To customize the service name, you can configure the serviceName property.

  serviceName: 'shop'

You can also configure a custom service name by setting the environment variable INSTANA_SERVICE_NAME.

Kafka Trace Correlation Headers

You can configure the format for Kafka trace correlation headers that are used by the Node.js tracer with the environment variable INSTANA_KAFKA_HEADER_FORMAT. Valid values are binary, string, or both. You can also disable Kafka trace correlation entirely with INSTANA_KAFKA_TRACE_CORRELATION=false, but this is not recommended.

Both options can also be configured in the application code as follows:

  tracing: {
    kafka: {
      // valid options: 'binary', 'string', or 'both'
      headerFormat: 'string',
      // valid options: true or false
      traceCorrelation: true

Another alternative is to configure the Kafka trace correlation options at the level of the Instana host agent.

For more information, see Kafka Header Migration.

Setting the Process Name

Use the environment variable INSTANA_PROCESS_NAME to set a custom label for the infrastructure entity that represents the Node.js process.

Reporting Unhandled Promise Rejections

The Instana Node.js collector can report unhandled promise rejections as issues to Instana. An unhandled promise rejection is a promise that is rejected but for which no rejection handler has been defined (that is, the promise chain does not have a .catch(...)).

This capability is disabled by default. If it is enabled and an unhandled promise rejection is detected, this is reported as an issue of severity "warning" to Instana.

Note that the call that is in progress while the promise is rejected is not marked as an error due to the unhandled rejection. The reason for this is twofold:

  1. Unhandled rejections do not cause an error in the Node.js runtime. Even if unhandled rejections occur during the processing of a request, the request can still be processed successfully.
  2. The Node.js runtime has no way of detecting unhandled rejections in the context of specific calls. In fact, unhandled rejections are only detected later, when the associated promise is about to be garbage collected. By that time, the request which triggered the unhandled rejection is already finished and has been responded to.

This capability can be enabled with the option reportUnhandledPromiseRejections, as follows:

  reportUnhandledPromiseRejections: true

Starting with Node.js 12.0.0, there is a command line flag --unhandled-rejections that controls how unhandled promise rejections are handled. Reporting unhandled rejections is not supported with --unhandled-rejections=strict, because in this mode, Node.js will convert unhandled rejections to uncaught exceptions.


Log Level Configuration

If you want to change the default log level, you can configure that via:

  level: 'debug'

You can also configure the log level by setting the environment variable INSTANA_LOG_LEVEL to either debug, info, warn or error. Finally, setting INSTANA_DEBUG to any non-empty string will set the log level to debug.

Please note that the default log level is info. If you see unexpected Instana-related debug logs (log lines including "name":"@instana/collector" and "level":20) check if you have set the log level to debug in your configuration as shown above or if INSTANA_LOG_LEVEL=debug or INSTANA_DEBUG is set. If you provide your own logger (see as follows) you are responsible for setting the log level on it as desired.

Custom (Parent) Logger

See setting the logger.


Since: 1.98.1. Requires at least Node.js 6.4.0

This feature is currently in beta testing phase.

To enable AutoProfile™ add autoProfile: true option when initializing the collector.

  autoProfile: true

You can also enable AutoProfile™ by setting the environment variable INSTANA_AUTO_PROFILE to true

Automatic Aggregation of Short Exit Calls

Since: 1.108.0.

The Node.js tracer supports automatic aggregation of very short (< 10 ms), high frequency database calls. This helps to keep the performance overhead of tracing at a minimum in scenarios where such calls are executed in rapid succession. At the moment this capability is opt-in and needs to be enabled explicitly. It will become the default behaviour in one of the next releases.

To enable it right away, any of the three following methods can be used:

  • Set the environment variable INSTANA_SPANBATCHING_ENABLED=true.
  • Use in-code configuration:
      tracing: {
        spanBatchingEnabled: true
  • Add this to the agent's configuration.yaml:
      span-batching-enabled: true

Note that these configuration options will be ignored once the behavior becomes on by default.

Due to the way this feature works, it is possible that enabling this option has an impact on endpoint extraction, changing the number of calls to some low latency database endpoints.

Disable Falling Back To Pre-Built Native Add-Ons

If the native add-on dependencies like gcstats.js and event-loop-stats were not installed successfully when the command npm install ran, the package @instana/collector will automatically try to use the pre-built binaries that match the operating system, Node.js version and libc variant. This feature is only available on x64 Linux. It can be disabled by setting INSTANA_COPY_PRECOMPILED_NATIVE_ADDONS=false.

Full Configuration Reference

Here are all possible configuration values, with their default values:

  agentHost: '',
  agentPort: 42699,
  serviceName: null,
  packageJsonPath: null,
  // the log level:
  level: 'info',
  tracing: {
    enabled: true,
    automaticTracingEnabled: true,
    // Spans are batched and sent to the agent once every second, or if ${forceTransmissionStartingAt} spans have been collected (whichever happens earlier)
    forceTransmissionStartingAt: 500,
    // If more than ${maxBufferedSpans} have been buffered and the collector has not been able to send them to the agent, it will start to drop spans to avoid causing memory issues.
    maxBufferedSpans: 1000,
    http: {
      // This is usually configured at the agent level (configuration.yaml).
      extraHttpHeadersToCapture: []
    // How many stack trace frames are to be captured. Can also be 0 to disable collecting stack traces.
    stackTraceLength: 10,
    // To disable individual tracing plug-ins.
    disabledTracers: [],
     // Can also be configured at the agent level (configuration.yaml).
    spanBatchingEnabled: false
  metrics: {
    timeBetweenHealthcheckCalls: 3000
  // This is usually configured at the agent level (configuration.yaml).
  secrets: {
    matcherMode: 'contains-ignore-case',
    keywords: ['key', 'pass', 'secret']
  autoProfile: false

The following is a list of all environment variables that the Node.js collector supports:

Environment Variable Equivalent Configuration Option
INSTANA_AGENT_HOST config.agentHost
INSTANA_AGENT_PORT config.agentPort
INSTANA_SERVICE_NAME config.serviceName
INSTANA_PACKAGE_JSON_PATH config.packageJsonPath
INSTANA_DISABLE_TRACING=true config.tracing.enabled = false
INSTANA_DISABLE_AUTO_INSTR=true config.tracing.automaticTracingEnabled = false
INSTANA_DISABLED_TRACERS config.tracing.disabledTracers
INSTANA_STACK_TRACE_LENGTH config.tracing.stackTraceLength
INSTANA_LOG_LEVEL config.level
INSTANA_DEBUG config.level = debug
INSTANA_AUTO_PROFILE=true config.autoProfile = true
INSTANA_SPANBATCHING_ENABLED=true config.tracing.spanBatchingEnabled = true
INSTANA_TRACE_IMMEDIATELY=true config.tracing.activateImmediately = true

See Also