Declarative Configuration

Configure the Node.js distribution with an OpenTelemetry declarative configuration file via OTEL_CONFIG_FILE, including the Dash0 resource detectors and the xray propagator.

Instead of environment variables, the OpenTelemetry SDK can be configured with an OpenTelemetry declarative configuration file .

Selecting the file

Set OTEL_CONFIG_FILE to the path of the file. When OTEL_CONFIG_FILE is unset or empty and /etc/opentelemetry/nodejs/otel-config.yaml exists, the distribution uses that file instead. The distribution does not fall back to the default file when OTEL_CONFIG_FILE is set but names a missing file.

The file then is the complete SDK configuration: it defines the exporters, endpoints, processors, sampling and the resource. As the specification requires, other OTEL_* environment variables are ignored unless the file references them via ${VARIABLE} substitution.

A minimal file

A minimal file that exports all three signals to a collector looks like this:

file_format: "1.0"
resource:
  attributes:
    - name: service.name
      value: ${OTEL_SERVICE_NAME:-unknown_service}
  attributes_list: ${OTEL_RESOURCE_ATTRIBUTES:-}
tracer_provider:
  processors:
    - batch:
        exporter:
          otlp_http:
            endpoint: http://localhost:4318/v1/traces
meter_provider:
  readers:
    - periodic:
        exporter:
          otlp_http:
            endpoint: http://localhost:4318/v1/metrics
logger_provider:
  processors:
    - batch:
        exporter:
          otlp_http:
            endpoint: http://localhost:4318/v1/logs

Supported Node.js versions

Declarative configuration requires Node.js 18.19.0 or later, excluding 20.0.0 to 20.5.1. On older Node.js versions, the configuration file is ignored, and the distribution falls back to DASH0_OTEL_COLLECTOR_BASE_URL; if that is not set either, the distribution does not start. A warning is logged when the ignored file was set via OTEL_CONFIG_FILE, but not for the default file.

If the file cannot be loaded, an error is logged and the application keeps running without telemetry.

Combining the file with DASH0_OTEL_COLLECTOR_BASE_URL

When both a configuration file and DASH0_OTEL_COLLECTOR_BASE_URL are set, the file takes precedence, and DASH0_OTEL_COLLECTOR_BASE_URL sets the default for OTEL_EXPORTER_OTLP_ENDPOINT, without trailing slashes. A file that references ${OTEL_EXPORTER_OTLP_ENDPOINT} then exports to that collector. An explicitly set OTEL_EXPORTER_OTLP_ENDPOINT takes precedence.

Dash0 resource detectors

The distribution's own resource detectors can be enabled in the file by name, alongside the upstream host, process and service detectors:

resource:
  detection/development:
    detectors:
      - process: {}
      - dash0_distribution: {}
      - dash0_kubernetes: {}
      - dash0_service_name: {}

See Resource detection for what each detector adds. Attributes set in the file take precedence over those from these detectors.

Propagators

In addition to the propagators the OpenTelemetry SDK supports, the file can name xray, in composite or in composite_list. Unlike in OTEL_PROPAGATORS, xray-lambda and ottrace are not supported in a file; naming them makes the file fail to load. Propagators are applied in the order the file lists them, so the following matches the distribution's default without a configuration file (see Context propagation):

propagator:
  composite:
    - tracecontext:
    - baggage:
    - xray:

Settings that do not apply with a file

Because the file defines the whole SDK, the following do not apply when a configuration file is used:

  • DASH0_AUTOMATIC_SERVICE_NAME: use the dash0_service_name detector, or set service.name in the file.
  • DASH0_DEBUG_PRINT_SPANS: add a span processor with a console exporter to the file instead.
  • OTEL_METRIC_EXPORT_INTERVAL and OTEL_METRIC_EXPORT_TIMEOUT: set interval and timeout on the periodic metric reader in the file instead.

These continue to work as described in Configuration:

  • DASH0_BOOTSTRAP_SPAN
  • DASH0_DEBUG
  • DASH0_DISABLE
  • DASH0_ENABLE_FS_INSTRUMENTATION
  • DASH0_FLUSH_ON_SIGTERM_SIGINT
  • DASH0_FLUSH_ON_EMPTY_EVENT_LOOP
  • OTEL_NODE_ENABLED_INSTRUMENTATIONS (see Auto-instrumentation)

Last updated: