Getting Started
On Kubernetes
If your Node.js workloads run on Kubernetes, the easiest way to use the distribution is the Dash0 operator for Kubernetes. The operator injects the distribution into your workloads and configures it, so no installation step is required. See Kubernetes injection for how this works.
The rest of this page describes how to add the distribution to an application yourself.
Installation
Install the distribution from npm:
npm install @dash0/opentelemetryThis single package pulls in the OpenTelemetry SDK, the OTLP exporters, the auto-instrumentations and the resource detectors.
Minimal quick start
Point the distribution at a collector and load it with --require:
export DASH0_OTEL_COLLECTOR_BASE_URL=http://localhost:4318
node --require @dash0/opentelemetry app.jsThat is enough to instrument all supported libraries and to export traces, metrics and logs with OTLP over HTTP. Your application needs no OpenTelemetry imports.
If you cannot change the command line, set NODE_OPTIONS instead:
export NODE_OPTIONS="--require @dash0/opentelemetry"The distribution must be loaded before any other module of your application, which --require ensures.
Sending directly to Dash0
To export directly to the Dash0 ingress instead of a local collector, use the Dash0 ingress URL and add an authorization header:
export DASH0_OTEL_COLLECTOR_BASE_URL=https://ingress.<region>.<cloud>.dash0.com
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer $DASH0_AUTH_TOKEN,Dash0-Dataset=default"
node --require @dash0/opentelemetry app.jsUsing a configuration file
Instead of DASH0_OTEL_COLLECTOR_BASE_URL, you can configure the SDK with an OpenTelemetry declarative configuration file:
export OTEL_CONFIG_FILE=/path/to/otel-config.yaml
node --require @dash0/opentelemetry app.jsSee Declarative configuration for the file format and what the distribution adds to it.
What happens at startup
When Node.js loads the distribution:
- The distribution checks
DASH0_DISABLE. If it istrue, the distribution logs a message and does nothing else. - It checks that
DASH0_OTEL_COLLECTOR_BASE_URLis set or that a configuration file is available. If neither is the case, it logs an error and does not start. - It checks whether the OpenTelemetry SDK has already been loaded. If so, it disables itself to prevent double instrumentation.
- It selects the OpenTelemetry JS SDK line that matches the Node.js version, and starts the SDK with the exporters, resource detectors, propagators and instrumentations.
- If requested, it emits a bootstrap span and installs the handlers that flush telemetry on exit.
- Your application starts.
If initialization fails, the distribution logs an error and the application keeps running without telemetry.
Troubleshooting
Set DASH0_DEBUG=true to print additional log output from the distribution.
Set DASH0_DEBUG_PRINT_SPANS=true to also print all spans to stdout.
All messages from the distribution start with [Dash0 OpenTelemetry Distribution] or Dash0 OpenTelemetry distribution for Node.js:.
Last updated: