Skip to content

Node.js

The @opentelemetry/auto-instrumentations-node package starts the OpenTelemetry SDK before your code loads. It instruments Express, Fastify, Koa, NestJS, http, fetch, database drivers, Redis, Kafka and more without code changes.

Use this page when you run a Node.js service (JavaScript or TypeScript) and want it in FuseScope. For browser apps, see Real User Monitoring.

Signal Status What is sent
Traces Stable Spans for requests, HTTP calls, database and messaging.
Metrics Stable HTTP server/client metrics, plus what your code records.
Logs Development pino, winston and bunyan records with trace IDs.
  • Node.js on an active or maintenance LTS release. Current package versions require Node.js 22.15 or later.
  • A FuseScope collector you can reach on port 4317 or 4318. See OTLP.
  1. Install the packages:

    Terminal window
    npm install --save @opentelemetry/api @opentelemetry/auto-instrumentations-node
  2. Configure the SDK:

    Terminal window
    export OTEL_SERVICE_NAME=checkout
    export OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=production,service.version=1.4.2
    export OTEL_EXPORTER_OTLP_ENDPOINT=http://fusescope-collector.example.com:4318
    export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
    export OTEL_TRACES_EXPORTER=otlp
    export OTEL_METRICS_EXPORTER=otlp
    export OTEL_LOGS_EXPORTER=otlp
  3. Load the instrumentation before your app:

    Terminal window
    export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"
    node app.js

Useful settings:

Variable Example Purpose
OTEL_NODE_ENABLED_INSTRUMENTATIONS http,express,pg Only load these (names without @opentelemetry/instrumentation-).
OTEL_NODE_DISABLED_INSTRUMENTATIONS fs,dns Skip these. fs is off by default.
OTEL_NODE_RESOURCE_DETECTORS env,host,os Resource detectors to run. All run by default.
OTEL_LOG_LEVEL debug The SDK’s own diagnostic output, printed to the console.
Terminal window
OTEL_EXPORTER_OTLP_ENDPOINT=http://fusescope-collector.example.com:4317
OTEL_EXPORTER_OTLP_PROTOCOL=grpc

The packages are regular dependencies, so they are in node_modules after npm ci:

Dockerfile
FROM node:22-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
ENV NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"
CMD ["node", "app.js"]
Terminal window
docker run \
-e OTEL_SERVICE_NAME=checkout \
-e OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=production \
-e OTEL_EXPORTER_OTLP_ENDPOINT=http://fusescope-collector.example.com:4318 \
-e OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
-e OTEL_LOGS_EXPORTER=otlp \
checkout:latest

Set the variables in the pod spec. The downward API adds the pod name and namespace:

deployment.yaml
env:
- name: NODE_OPTIONS
value: --require @opentelemetry/auto-instrumentations-node/register
- name: OTEL_SERVICE_NAME
value: checkout
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://fusescope-otel-collector.fusescope.svc.cluster.local:4318
- name: OTEL_EXPORTER_OTLP_PROTOCOL
value: http/protobuf
- name: K8S_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: K8S_NAMESPACE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: OTEL_RESOURCE_ATTRIBUTES
value: deployment.environment.name=production,k8s.pod.name=$(K8S_POD_NAME),k8s.namespace.name=$(K8S_NAMESPACE_NAME)

$(VAR) only expands variables defined earlier in the list, so keep OTEL_RESOURCE_ATTRIBUTES last.

The pino, winston and bunyan instrumentations are included. Each does two things, both on by default:

  • Correlation: adds trace_id and span_id to records written inside a span, so they also appear in stdout.
  • Sending: forwards each record to the OpenTelemetry Logs SDK, which exports it over OTLP when OTEL_LOGS_EXPORTER=otlp.
Library Sending needs
pino pino 7 or later.
winston winston 3, and npm install @opentelemetry/winston-transport.
bunyan Nothing extra.

console.log is not captured. If a collector already reads your stdout, set OTEL_LOGS_EXPORTER=none so each line is stored once.

  1. Send a few requests to the service.
  2. Open Services. The service appears under its OTEL_SERVICE_NAME within a minute.
  3. Open the Traces explorer and filter by service.name.

Nothing arrives? Run with OTEL_LOG_LEVEL=debug to see export errors, and check the endpoint and protocol match (4318 with http/protobuf, 4317 with grpc).