Configuring the Node.js collector
For most use cases, you need to initialize the Instana Node.js collector with require('@instana/collector')(); and leave the default configuration options in place. You can modify the default configuration as outlined in Modifying default configuration.
- Modifying default configuration
- Agent communication
- Tracing
- Setting the process name
- Reporting unhandled promise rejections
- Logging
- AutoProfile
- Automatic aggregation of short exit calls
- Disable falling back to pre-built native add-ons
- Full configuration reference
- Related topics
Modifying default configuration
You can pass in a configuration object when initializing the Instana Node.js collector:
require('@instana/collector')({
// configuration options, see as follows
});
Additionally, you can configure the Node.js collector via environment variables.
Agent communication
You can configure the collector to change the agent host and port.
Agent host
The collector tries to communicate with the Instana agent via IP 127.0.0.1 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.
require('@instana/collector')({
agentHost: '::1' // use IPv6 to contact via localhost
});
Or leverage an environment variable.
require('@instana/collector')({
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.
require('@instana/collector')({
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 and Red Hat 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.
Disabling Node.js EOL events
In non-serverless environments with an Instana agent, the Node.js Tracer triggers issue events when it detects that the running Node.js version has reached end of life (EOL).
To suppress these EOL events, you can disable them using the following environment variable:
INSTANA_TRACING_DISABLE_EOL_EVENTS=true
For a complete list of EOL Node.js versions, refer to the official Node.js releases page.
Tracing
Tracing provides end-to-end visibility into your application by capturing detailed information about requests as they pass through various services and components.
Tracing is enabled by default. To disable tracing either entirely or selectively, refer to the disabling tracing section for configuration options.
Allow root exit span without entry span
By default, the Instana Node.js Tracer captures only exit spans with an active entry span. You can enable this feature to allow the tracer to trace standalone exit spans.
To enable this feature, use any one of the following options:
-
Set the
INSTANA_ALLOW_ROOT_EXIT_SPANenvironment variable. -
Configure the feature through the Tracer initialization function:
require('@instana/collector')({ tracing: { allowRootExitSpan: true } });
If INSTANA_ALLOW_ROOT_EXIT_SPAN is configured to 1 or true, or if allowRootExitSpan is set to true, the tracer captures exit spans even in the absence of active entry span.
This feature is useful for the following scenarios where tasks are triggered by a mechanism, which is not supported by Instana automatic instrumentation:
- Incoming messages from unsupported messaging libraries
- Requests that are made through unsupported protocols, like raw Transmission Control Protocol (TCP) or WebSocket
- Scheduled jobs that are initiated internally by the application by using mechanisms, such as
setTimeout,setInterval, or unsupported Node.js scheduling libraries
Ignoring endpoints
Starting from Node.js Tracer 4.9.0, you can reduce unnecessary data ingestion by excluding specific traces or calls. This filtering mechanism refines your trace collection. To exclude traces, define these parameters in the Node.js Tracer configuration settings:
- Technology: Specify the relevant technology, for example,
Kafka,Redis,DynamoDB, orHTTP. - Method: Identify the method to be excluded. For example, exclude these methods for the following technologies:
-
Kafka:send,consume -
Redis:get,type -
DynamoDB:query,scan -
HTTP:get,post
-
- Endpoint (if applicable): Further refine filtering based on specific endpoints. For example, the endpoints for the following technologies are defined as:
-
Kafka: The endpoint is the topic name. -
HTTP: The endpoint is the URL path.
-
- Connection (Optional): Exclude traces for a specific connection. For example, the connection for the following technologies is defined as:
-
Redis: The connection is the connection string. -
HTTP: The connection includes the host and port.
-
The ignore endpoints feature has the following restrictions:
- This feature is currently available for Redis, DynamoDB, Kafka, and HTTP. However, only Kafka and HTTP supports filtering by both method and endpoint.
- The Kafka.js library supports the sendBatch method, which allows sending messages to multiple topics at once. When you filter traces by using both method and endpoint, specify all relevant endpoints (topics) in the configuration. If any topic is omitted, tracing is not ignored.
- Connection filtering is currently supported for Redis and HTTP only.
- Filtering for HTTP entry calls is currently supported.
Filtering rules
The rules for filtering traces are as follows:
- When a trace is ignored, all subsequent downstream traces are also ignored.
- Use
*to ignore all endpoints, methods, or connections. - Endpoint values (such as Kafka topic names) remain consistent across services.
- Method names may vary depending on the programming language and technology. Refer to the Instana UI to determine the correct method and endpoint for your service.
The following Instana UI screenshot provides a visual reference for identifying the correct method and endpoint for configuration:
Configuration options
You can enable the endpoint exclusion by using any one of the following options:
- Environment variables
- In-code configuration
- Agent configuration
Environment variables
You can configure ignored endpoints by using the following environment variables to filter endpoints per service:
- INSTANA_IGNORE_ENDPOINTS_PATH
- INSTANA_IGNORE_ENDPOINTS
INSTANA_IGNORE_ENDPOINTS_PATH
With this environment variable, you can configure filtering though an external YAML file as shown in the following example:
INSTANA_IGNORE_ENDPOINTS_PATH=/absolute/path/to/config.yaml
In the preceding example, the config.yaml file must have an absolute path and adhere to the specified configuration structure.
The following example shows filtering by method:
tracing:
ignore-endpoints:
redis:
- get
- type
dynamodb:
- query
kafka:
- send
http:
- get
This configuration filters the following traces:
-
GETandTYPEcommands forRedis -
QUERYcommand forDynamoDB -
SENDmethod forKafkaand all downstream traces -
GETmethod forHTTPand all downstream traces
The following example shows filtering by method, endpoint, and connection:
tracing:
ignore-endpoints:
kafka:
- methods: ["consume"]
endpoints: ["topic1", "topic2"]
- methods: ["consume", "send"]
endpoints: ["topic3"]
- methods: ["*"] # Applied to all methods
endpoints: ["topic4"]
- methods: ["consume"]
endpoints: ["*"] # Applied to all endpoints
http:
- methods: ["get"]
endpoints: ["/status"]
- methods: ["get", "post"]
endpoints: ["/status", "/v1/status"]
- methods: ["*"]
connection: ["localhost:3000"]
redis:
- methods: ['get']
connections: ['192.168.0.1:9191']
This configuration filters the following traces:
-
CONSUMEmethod fortopic1andtopic2inKafkaand all downstream traces -
CONSUMEandSENDmethods fortopic3inKafkaand all downstream traces - All (
*) methods fortopic4inKafkaand all downstream traces -
CONSUMEmethod for all (*) topics inKafkaand all downstream traces -
GETmethod to the URL/statusinHTTPand all downstream traces -
GETandPOSTmethods to the URLs/statusand/v1/statusinHTTPand all downstream traces - All (
*) methods for connectionlocalhost:3000and all downstream traces -
GETmethod on connection192.168.0.1:9191forRedis
You can combine both filtering options (method-only and method and endpoint) in the same configuration file.
This configuration is compatible with the agent configuration.yaml structure.
INSTANA_IGNORE_ENDPOINTS
With this environment variable, you can exclude traces based only on method names.
INSTANA_IGNORE_ENDPOINTS=redis:get,type
This configuration excludes the GET and TYPE commands in the redis package from tracing.
To configure exclusions for multiple packages, use the configurations as shown in the following example.
INSTANA_IGNORE_ENDPOINTS=redis:get,type;dynamodb:query,scan;kafka:send;http:get
This configuration filters the following traces:
-
GETandTYPEcommands inRedis -
QUERYandSCANcommands inDynamoDB -
SENDmethod inKafka -
GETmethod inHTTP
In-code configuration
You can configure ignore endpoints by using the in-code configuration to filter endpoints per service.
The following example shows filtering by method:
require('@instana/collector')({
tracing: {
ignoreEndpoints: {
redis: ['get', 'type'],
dynamodb: ['query', 'scan'],
kafka: ['send'],
http: ['get']
}
}
});
This configuration filters the following traces:
-
GETandTYPEcommands inRedis -
QUERYandSCANcommands inDynamoDB -
SENDmethod inKafkaand all downstream traces -
GETmethod inHTTPand all downstream traces
The following example shows filtering by method and endpoint:
require('@instana/collector')({
tracing: {
ignoreEndpoints: {
kafka: [
{ methods: ['consume'], endpoints: ['topic1', 'topic2'] },
{ methods: ['send'], endpoints: ['topic3'] }
],
http: [
{
methods: ['get'], endpoints: ['/status']
}
]
}
}
});
This configuration filters the following traces:
-
CONSUMEmethod fortopic1andtopic2inKafkaand all downstream traces -
SENDmethod fortopic3inKafkaand all downstream traces -
GETmethod to the URL/statusinHTTPand all downstream traces
You can use both filtering options (method-only and method and endpoint) in the same configuration.
Agent configuration
Alternatively, you can centrally ignore endpoints for all your services by configuring them through the agent. However, be sure to thoroughly review the relevant rules before proceeding. For more information, refer to the ignoring endpoints using the agent section.
Disabling tracing
To disable tracing, you can either turn it off completely or selectively exclude specific instrumentations or entire groups, such as databases, messaging, or logging. This flexibility allows you to fine-tune tracing based on the needs of your application.
To apply the configuration to disable tracing, use any one of the following methods:
- Environment variables
- In-code configuration
- Agent configuration (YAML)
Disabling all tracing
Disabling tracing completely prevents the Instana tracer from collecting or reporting any spans. This approach can be useful for scenarios, such as debugging, testing, or when tracing is temporarily not required.
When tracing is disabled, neither automatic instrumentation nor the Trace SDK is active. All SDK calls are silently ignored without producing any errors or spans.
To disable all tracing, use one of the following methods:
-
Environment variable: Set the environment variables
INSTANA_TRACING_DISABLEtotrue.INSTANA_TRACING_DISABLE=true -
In-code configuration: Pass the following option during tracer initialization:
require('@instana/collector')({ tracing: { disable: true } });
Disabling specific instrumentations
Use the following option to disable tracing for specific instrumentations or package by name. To find the appropriate names, refer to the Instrumentation identifier values listed in the supported libraries section.
To disable specific instrumentations, use one of the following methods:
-
Environment variable: Set the
INSTANA_TRACING_DISABLE_INSTRUMENTATIONSenvironment variable as shown in the following example:INSTANA_TRACING_DISABLE_INSTRUMENTATIONS=redis,graphqlIn this example, the tracing is disabled for
redisandgraphqlwith this configuration. No spans are collected or reported for these two instrumentations. -
In-code configuration: Pass the following option during tracer initialization:
require('@instana/collector')({ tracing: { disable: { instrumentations: ['redis', 'graphql'] } } });
Disabling instrumentation groups
You can disable entire categories of related instrumentations by specifying group names. This approach is helpful when you want to turn off tracing for a broader set of libraries with a single configuration.
Group level disabling is currently limited to the following categories:
To disable specific instrumentation groups, use one of the following methods:
-
Environment variable: Set the
INSTANA_TRACING_DISABLE_GROUPSenvironment variable as shown in the following example:INSTANA_TRACING_DISABLE_GROUPS=logging,databaseIn this example, all instrumentations under the
logginganddatabasesgroups are disabled with this configuration. No spans are collected or reported for any instrumentations that belong to these groups. -
In-code configuration: Pass the following option during tracer initialization:
require('@instana/collector')({ tracing: { disable: { groups: ['logging', 'database'] } } });
Disabling tracing through agent configuration
Alternatively, you can globally disable instrumentations or groups for all your services by configuring them through the agent. For more information, refer to the Disabling tracing section.
Disabling tracing with a single flat list
With the flat list format, you can disable multiple instrumentations or groups by using a comma-separated list.
To disable tracing as single flat list, use one of the following methods:
-
Environment variable: Set the environment variable
INSTANA_TRACING_DISABLEas shown in the following example:INSTANA_TRACING_DISABLE=redis,graphql,logging,databaseIn this example, tracing is disabled for both individual instrumentations (
redisandgraphql) and entire groups (logginganddatabase). No spans are collected for any of the specified entries. -
In-code configuration: Pass the following option during tracer initialization:
require('@instana/collector')({ tracing: { disable: ['redis', 'graphql', 'logging', 'database'] } });
- The INSTANA_DISABLED_TRACERS environment variable is deprecated. Use INSTANA_TRACING_DISABLE instead.
- The INSTANA_DISABLE_TRACING environment variable is deprecated. Use INSTANA_TRACING_DISABLE instead.
- The tracing.disabledTracers configuration option is deprecated. Use tracing.disable instead.
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:
require('@instana/collector')({
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:
require('@instana/collector')({
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.
Disabling worker thread tracing
To prevent the Instana Node.js collector from tracing worker threads, set the following environment variable:
INSTANA_DISABLE_WORKER_THREADS=true
This configuration disables tracing for all worker threads but the main process is still traced automatically. Use this configuration when worker threads run internal or background tasks that you want excluded from tracing.
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.
require('@instana/collector')({
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.
require('@instana/collector')({
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.
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.
require('@instana/collector')({
serviceName: 'shop'
});
You can also configure a custom service name by setting the environment variable INSTANA_SERVICE_NAME. For more information about configuring a custom service, see Setting the service name globally.
Kafka trace correlation headers
Starting from collector version 4.x, Kafka trace correlation headers are always sent in the string format, eliminating support for binary format. For more information, see Kafka header migration.
Remove any configurations that reference the environment variable INSTANA_KAFKA_HEADER_FORMAT and the in-code configuration option tracing: { kafka: { headerFormat: .... }}}.
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:
- 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.
- 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:
require('@instana/collector')({
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.
Logging
To modify the default logging configuration, see the following sections:
Log level configuration
If you want to change the default log level, you can configure that via:
require('@instana/collector')({
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 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.
AutoProfile
Since: 1.98.1. Requires at least Node.js 6.4.0
This feature is currently in public preview testing phase.
To enable AutoProfile add autoProfile: true option when initializing the collector.
require('@instana/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 immediately, use any of the following methods:
- Set the environment variable
INSTANA_SPANBATCHING_ENABLED=true. - Use in-code configuration:
require('@instana/collector')({ tracing: { spanBatchingEnabled: true } }); - Add this to the agent's
configuration.yaml:com.instana.plugin.nodejs: 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 optional dependencies are not installed successfully, the @instana/collector package automatically tries to use the pre-built binaries that match the operating system, Node.js version, and libc variant. You can disable the usage of prebuilds by setting INSTANA_COPY_PRECOMPILED_NATIVE_ADDONS=false.
Full configuration reference
Here are all possible configuration values, with their default values:
{
agentHost: '127.0.0.1',
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_PROCESS_NAME |
– |
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 |
INSTANA_COPY_PRECOMPILED_NATIVE_ADDONS |
– |
INSTANA_ALLOW_ROOT_EXIT_SPAN |
config.tracing.allowRootExitSpan = true |
INSTANA_IGNORE_ENDPOINTS |
config.tracing.ignoreEndpoints |