Kubernetes Injection

How the Dash0 operator injects the Node.js distribution into Kubernetes workloads via NODE_OPTIONS, with safety checks and graceful self-deactivation.

The distribution is designed to be injected into Node.js workloads by the Dash0 operator for Kubernetes. No application code changes and no changes to the container image are required.

How injection works

The operator adds the distribution to the workload's pods and sets LD_PRELOAD to the OpenTelemetry injector. When a Node.js process starts, the injector adds --require with the path of the distribution to NODE_OPTIONS. Existing NODE_OPTIONS are kept. Node.js then loads the distribution before the application's own code.

The operator also sets DASH0_OTEL_COLLECTOR_BASE_URL, so the distribution sends telemetry to the OpenTelemetry collector that the operator manages.

Safety checks before instrumentation

Before it starts the OpenTelemetry SDK, the distribution performs several checks. If a check fails, the distribution logs a message to stderr and deactivates itself, rather than breaking the application.

Opt-out

If DASH0_DISABLE=true is set, the distribution does nothing.

Export destination

If neither DASH0_OTEL_COLLECTOR_BASE_URL nor a configuration file is available, the distribution does not start, because it would have nowhere to send telemetry.

Node.js version check

The distribution supports Node.js 16 and later. On older versions, it deactivates itself. On Node.js versions newer than those it has been tested with, it logs a warning and starts anyway.

Double-instrumentation check

If the OpenTelemetry Node.js SDK (@opentelemetry/sdk-node) has already been loaded in the process, for example because the application instruments itself, the distribution deactivates itself to avoid double instrumentation.

Initialization errors

If initializing the SDK fails, the distribution logs the error and the application keeps running without telemetry. Likewise, if a configuration file cannot be loaded, the application keeps running without telemetry.

Flushing telemetry on exit

Short-lived processes and pods that are being terminated can lose telemetry that has not been exported yet. By default, the distribution flushes telemetry when the event loop is empty and the process is about to exit. Set DASH0_FLUSH_ON_SIGTERM_SIGINT=true to also flush telemetry when the process receives SIGTERM or SIGINT, for example when Kubernetes stops a pod. See Configuration for the details and caveats of both options.

Alternative JavaScript runtimes

Because the injection modifies NODE_OPTIONS, workloads that use an alternative JavaScript runtime, such as Deno, can run into issues. See the Dash0 operator documentation for how to disable the Node.js auto-instrumentation for a container.

Last updated: