Version: 0.71.0This documentation is for Spitfire 0.71.0.
Connecting a Node.js service with OTel
@opentelemetry/auto-instrumentations-node collects traces, metrics and logs without touching the
code. Values and general rules: Connecting services with OTel: overview.
Version table
| Node.js | @opentelemetry/auto-instrumentations-node |
Note |
|---|---|---|
| 22.15 and later (22, 24, 26) | 0.82.0 | The LTS versions OTel supports |
| 18.19+, 20.6+, 22.0 – 22.14 | 0.81.2, @opentelemetry/api 1.9.1 |
0.82.0 does not install on these versions; 0.81.2 does not install with api 1.10.0 |
| 18.18 and earlier (16 included) | not supported | Upgrade to Node.js 22 or take server metrics only: Collector |
Find your version: node --version with the Node.js the service uses.
The commands below say 0.82.0 and api@1.10.0; if your band is 18/20/22.0–22.14, write 0.81.2 and api@1.9.1.
Verified: 2026-11-02. Source: supported runtimes, npm page (engines), package documentation.
What you need
- Spitfire address
https://<spitfire>and OTLP receiver tokensfotlp_… - Tower address
http://<tower>:4318and Collector tokensfcol_… - Protocol
http/protobuf - Service name
<service-name>, version<service-version>, environment<environment> - With a private CA, the CA file
/etc/spitfire-otel/ca.pem - With a proxy, the Tower and Spitfire in
NO_PROXY - Sampling
parentbased_traceidratio,0.1
Linux (systemd)
- In the application's folder (where
package.jsonis), install the packages:
npm install --save @opentelemetry/auto-instrumentations-node@0.82.0 @opentelemetry/api@1.10.0
sudo mkdir -p /opt/spitfire-otel /etc/spitfire-otel- Create the file
/etc/spitfire-otel/<service-name>.envand paste this:
IS_OTEL_ENABLED=true
OTEL_SERVICE_NAME=<service-name>
OTEL_RESOURCE_ATTRIBUTES=service.version=<service-version>,deployment.environment=<environment>
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://<spitfire>/otlp/v1/traces
OTEL_EXPORTER_OTLP_TRACES_HEADERS=authorization=sfotlp_…
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://<spitfire>/otlp/v1/logs
OTEL_EXPORTER_OTLP_LOGS_HEADERS=authorization=sfotlp_…
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://<tower>:4318/v1/metrics
OTEL_EXPORTER_OTLP_METRICS_HEADERS=authorization=sfcol_…
OTEL_TRACES_EXPORTER=otlp
OTEL_METRICS_EXPORTER=otlp
OTEL_LOGS_EXPORTER=otlp
OTEL_TRACES_SAMPLER=parentbased_traceidratio
OTEL_TRACES_SAMPLER_ARG=0.1
NO_PROXY=<tower>,<spitfire>
#OTEL_EXPORTER_OTLP_CERTIFICATE=/etc/spitfire-otel/ca.pem- Restrict its permission:
sudo chmod 600 /etc/spitfire-otel/<service-name>.env - Create the file
/opt/spitfire-otel/otel-runand paste this:
#!/bin/sh
# IS_OTEL_ENABLED=true: OTel is loaded with --require; any other value: not loaded, SDK off.
if [ "$IS_OTEL_ENABLED" = "true" ]; then
export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register ${NODE_OPTIONS:-}"
else
export OTEL_SDK_DISABLED=true
fi
exec "$@"- Make it executable:
sudo chmod 755 /opt/spitfire-otel/otel-run - Find the service's current start command:
systemctl cat <unit> | grep ^ExecStart - Open
sudo systemctl edit <unit>and paste this (on the last line, replace the command afterExecStart=with the command from step 6;WorkingDirectorymust be the application's folder):
[Service]
EnvironmentFile=/etc/spitfire-otel/<service-name>.env
WorkingDirectory=/srv/app
ExecStart=
ExecStart=/opt/spitfire-otel/otel-run /usr/bin/node /srv/app/server.js- Restart:
sudo systemctl daemon-reload && sudo systemctl restart <unit> - See that it is loaded: the
journalctl -u <unit> -n 50output must not show the errorCannot find module '@opentelemetry/auto-instrumentations-node/register'.
If it runs under pm2, do not use otel-run: write the values from the environment file
under env in pm2's ecosystem.config.js and add
node_args: "--require @opentelemetry/auto-instrumentations-node/register"; to turn it off,
delete the node_args line and write OTEL_SDK_DISABLED=true.
Docker
- Put the
otel-runfile (Linux step 4) next to theDockerfile. - Add this to the
Dockerfile(afternpm install, withWORKDIRthe application's folder);/opt/spitfire-otel/otel-rungoes at the start ofENTRYPOINT, the rest is your command:
RUN npm install --save @opentelemetry/auto-instrumentations-node@0.82.0 @opentelemetry/api@1.10.0
COPY --chmod=755 otel-run /opt/spitfire-otel/otel-run
ENTRYPOINT ["/opt/spitfire-otel/otel-run", "node", "server.js"]- Save the environment file (Linux step 2) on the Docker machine as
/etc/spitfire-otel/<service-name>.env. - Run:
docker run --env-file /etc/spitfire-otel/<service-name>.env …or, in compose, under the serviceenv_file: /etc/spitfire-otel/<service-name>.env. - When the environment file changes, recreate the container (
restartis not enough):docker compose up -d --force-recreate <service>
Kubernetes
- Prepare the image as in the Docker section.
- Save the environment file (Linux step 2) as
<service-name>.envand make it a Secret:
kubectl create secret generic <service-name>-otel --from-env-file=<service-name>.env \
--dry-run=client -o yaml | kubectl apply -f -- In the Deployment, add this under the container:
envFrom:
- secretRef:
name: <service-name>-otel- Restart:
kubectl rollout restart deployment/<deployment>
Windows (service)
- In the application's folder (where
package.jsonis), install the packages:
npm install --save @opentelemetry/auto-instrumentations-node@0.82.0 @opentelemetry/api@1.10.0- The service must start in the application's folder (with NSSM:
nssm set <windows-service> AppDirectory C:\app; with another wrapper, its working directory setting). - In an administrator PowerShell, write the service's name (Name in the
Get-Servicelist) in place of<windows-service>and run:
$Service = "<windows-service>"
$IS_OTEL_ENABLED = "true"
$Otel = @(
"IS_OTEL_ENABLED=$IS_OTEL_ENABLED",
"OTEL_SERVICE_NAME=<service-name>",
"OTEL_RESOURCE_ATTRIBUTES=service.version=<service-version>,deployment.environment=<environment>",
"OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf",
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://<spitfire>/otlp/v1/traces",
"OTEL_EXPORTER_OTLP_TRACES_HEADERS=authorization=sfotlp_…",
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://<spitfire>/otlp/v1/logs",
"OTEL_EXPORTER_OTLP_LOGS_HEADERS=authorization=sfotlp_…",
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://<tower>:4318/v1/metrics",
"OTEL_EXPORTER_OTLP_METRICS_HEADERS=authorization=sfcol_…",
"OTEL_TRACES_EXPORTER=otlp",
"OTEL_METRICS_EXPORTER=otlp",
"OTEL_LOGS_EXPORTER=otlp",
"OTEL_TRACES_SAMPLER=parentbased_traceidratio",
"OTEL_TRACES_SAMPLER_ARG=0.1",
"NO_PROXY=<tower>,<spitfire>"
)
# Private CA: $Otel += "OTEL_EXPORTER_OTLP_CERTIFICATE=C:\spitfire-otel\ca.pem"
if ($IS_OTEL_ENABLED -eq "true") {
$Otel += "NODE_OPTIONS=--require @opentelemetry/auto-instrumentations-node/register"
} else {
$Otel += "OTEL_SDK_DISABLED=true"
}
$Key = "HKLM:\SYSTEM\CurrentControlSet\Services\$Service"
$Keep = @((Get-ItemProperty $Key).Environment | Where-Object { $_ -and $_ -notmatch '^(IS_OTEL_ENABLED|OTEL_|NODE_OPTIONS|NO_PROXY)=' })
Set-ItemProperty $Key -Name Environment -Type MultiString -Value ($Keep + $Otel)
Restart-Service -Name $Service -Force- See that it is loaded: the service's log must not show the error
Cannot find module '@opentelemetry/auto-instrumentations-node/register'.
--require looks for the package from the working directory
(Node.js documentation); that is why step 2 is needed.
Turning off and removing
- Turning off: set
IS_OTEL_ENABLED=falsein the environment file (in the script on Windows) and restart the service (Linux step 8, Docker step 5, Kubernetes step 4, or run the Windows script again). - Removing:
sudo systemctl revert <unit>,sudo rm -r /opt/spitfire-otel /etc/spitfire-otelandnpm uninstall @opentelemetry/auto-instrumentations-node @opentelemetry/api; in Docker, delete the lines added to theDockerfile; on Windows, delete the OTel lines from the service'sEnvironmentvalue.
Common problems
| Symptom | Cause | Fix |
|---|---|---|
Cannot find module '@opentelemetry/auto-instrumentations-node/register' |
The service does not start in the application's folder | Make WorkingDirectory (WORKDIR in Docker) the folder with node_modules |
npm EBADENGINE warning or install error |
The Node.js version is outside the band | Write your band's versions (0.81.2, api@1.9.1) |
No spans in an ES module ("type": "module") application |
Some libraries are not caught with --require in ESM |
In otel-run, add --experimental-loader=@opentelemetry/instrumentation/hook.mjs at the start of NODE_OPTIONS (ESM support) |
| No traces or metrics arrive | Address, token or network | Follow the Verifying steps |