No-code Instrumentation for Node.js in Splunk Observability Cloud
No-Code Instrumentation enables distributed tracing in Node.js applications without modifying the source code. Instrumentation is configured declaratively via a JSON file. Spans are generated based on configuration and can include custom attributes extracted from function arguments.
Configuration File Location
By default, the instrumentation loads its configuration from a file named nocode.config.json
in the current working directory. You can override this location using the NOCODE_CONFIG_PATH
environment variable:
export NOCODE_CONFIG_PATH=/path/to/your/config.json
Configuration File Structure
The configuration file contains an array of instrumentation definitions. These map to OpenTelemetry's InstrumentationModuleDefinition
and InstrumentationFileDefinition
objects.
[
{
"moduleName": "mynodemodule",
"supportedVersions": [">=4.0.0"],
"files": [
{
"name": "lib/util.js",
"methodName": "processData",
"spanName": "mynodemodule.processData",
"attributes": [
{
"attrIndex": 0,
"attrPath": "user.id",
"key": "user.id"
}
]
}
]
},
{
"absolutePath": "/absolute/path/to/your/project/src/utils/helper.js",
"files": [
{
"name": "utils/helper",
"methodName": "calculateTotal",
"spanName": "helper.calculateTotal",
"attributes": [
{
"attrIndex": 0,
"attrPath": "items.length",
"key": "item.count"
},
{
"attrIndex": 1,
"attrPath": "options.currency",
"key": "currency"
}
]
}
]
}
]
Configuration Properties
To define how specific functions should be traced, the configuration file uses structured objects. Below are the key components and their properties:
Instrumentation definition
Property | Type | Required | Description |
---|---|---|---|
moduleName | string | No* | Name of the npm module to instrument (e.g., "express", "lodash") |
absolutePath | string | No* | Absolute path to a specific file to instrument |
supportedVersions | string[] | No | Supported version ranges (defaults to ["*"] ) — applies only to moduleName |
mainModuleMethods | array | No | Methods exported directly by the module's main file |
files | array | No | List of files and methods to instrument |
Usage Guidelines
To configure no-code instrumentation correctly, follow these simple rules:
-
Use
moduleName
when instrumenting code from npm packages (likeexpress
orlodash
) -
Use
absolutePath
when instrumenting your own project files -
Use
mainModuleMethods
to target functions exported directly by a module -
Use
files
to target functions inside specific files -
Use
supportedVersions
only withmoduleName
; it has no effect withabsolutePath
-
When using
absolutePath
, omit file extensions in thename
field (e.g."utils/helper"
) -
When using
moduleName
, include file extensions in thename
field (e.g."lib/util.js"
)
Function instrumentation (used in files
and mainModuleMethods
)
Property | Type | Required | Description |
---|---|---|---|
name | string | Yes | Relative path to the file (only used in files ) |
methodName | string | Yes | Name of the function or method to instrument |
spanName | string | No | Custom span name (defaults to the method name) |
attributes | Attribute definition[] | No | List of attributes to extract from function arguments |
name
is required only when the object is used inside thefiles
array.- When used in
mainModuleMethods
,name
is omitted because the method is exported directly by the module.
Limitations
- File-level granularity: Can only instrument functions exported from modules, not internal functions
- Static configuration: Configuration is loaded once at startup and cannot be changed at runtime