🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@opentelemetry/configuration

Package Overview
Dependencies
Maintainers
6
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/configuration

OpenTelemetry Configuration

latest
Source
npmnpm
Version
0.220.0
Version published
Weekly downloads
6.6M
-14.22%
Maintainers
6
Weekly downloads
 
Created
Source

OpenTelemetry Declarative Configuration

NPM Published Version Apache License

Note: This is an experimental package under active development. New releases may include breaking changes.

This package implements the OpenTelemetry declarative configuration specification for Node.js. It parses configuration from a YAML file or environment variables and produces a ConfigurationModel that the OpenTelemetry SDK uses to initialize providers.

Installation

npm install @opentelemetry/configuration

Usage

createConfigFactory() selects the configuration source automatically:

  • If OTEL_CONFIG_FILE points to a valid .yaml/.yml file, configuration is read from that file.
  • Otherwise, configuration is assembled from standard OpenTelemetry environment variables.
import { createConfigFactory } from '@opentelemetry/configuration';

const factory = createConfigFactory();
const config = factory.getConfigModel();

YAML file configuration

Set OTEL_CONFIG_FILE to the path of your configuration file:

OTEL_CONFIG_FILE=./otel-config.yaml node app.js

Example:

file_format: "1.0"
resource:
  attributes:
    - name: service.name
      value: my-service
tracer_provider:
  processors:
    - batch:
        exporter:
          otlp_http:
            endpoint: http://localhost:4318/v1/traces

Environment variable substitution is supported using ${VAR_NAME}, ${VAR_NAME:-default}, ${env:VAR_NAME}, and ${env:VAR_NAME:-default} syntax. Use $$ for a literal $.

tracer_provider:
  processors:
    - batch:
        exporter:
          otlp_http:
            endpoint: ${OTEL_EXPORTER_ENDPOINT:-http://localhost:4318}/v1/traces

Environment variable configuration

When no config file is set, the factory reads from the standard OpenTelemetry SDK environment variables. The full set of variables this package consumes:

VariableDescription
OTEL_SDK_DISABLEDDisable the SDK entirely
OTEL_LOG_LEVELInternal SDK log level
OTEL_SERVICE_NAMEService name resource attribute
OTEL_RESOURCE_ATTRIBUTESComma-separated resource attributes
OTEL_NODE_RESOURCE_DETECTORSResource detectors to enable (env, host, os, process, serviceinstance, all, none)
OTEL_PROPAGATORSPropagators: tracecontext, baggage, b3, b3multi
OTEL_TRACES_EXPORTERTraces exporter(s): otlp, console, none
OTEL_METRICS_EXPORTERMetrics exporter(s): otlp, prometheus, console, none
OTEL_LOGS_EXPORTERLogs exporter(s): otlp, console, none
OTEL_TRACES_SAMPLERSampler name (e.g. parentbased_always_on, traceidratio)
OTEL_TRACES_SAMPLER_ARGSampler argument (e.g. ratio value)
OTEL_EXPORTER_OTLP_ENDPOINTOTLP endpoint (all signals)
OTEL_EXPORTER_OTLP_HEADERSOTLP headers (all signals)
OTEL_EXPORTER_OTLP_PROTOCOLOTLP protocol: grpc, http/protobuf, http/json
OTEL_EXPORTER_OTLP_TIMEOUTOTLP request timeout (all signals)
OTEL_EXPORTER_OTLP_COMPRESSIONOTLP compression (all signals): gzip, none
OTEL_EXPORTER_OTLP_CERTIFICATEOTLP server CA certificate file (all signals)
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATEOTLP client certificate file for mTLS (all signals)
OTEL_EXPORTER_OTLP_CLIENT_KEYOTLP client private key file for mTLS (all signals)
OTEL_EXPORTER_OTLP_TRACES_ENDPOINTPer-signal override (traces)
OTEL_EXPORTER_OTLP_TRACES_HEADERSPer-signal override (traces)
OTEL_EXPORTER_OTLP_TRACES_PROTOCOLPer-signal override (traces)
OTEL_EXPORTER_OTLP_TRACES_TIMEOUTPer-signal override (traces)
OTEL_EXPORTER_OTLP_TRACES_COMPRESSIONPer-signal override (traces)
OTEL_EXPORTER_OTLP_TRACES_CERTIFICATEPer-signal override (traces)
OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATEPer-signal override (traces)
OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEYPer-signal override (traces)
OTEL_EXPORTER_OTLP_METRICS_ENDPOINTPer-signal override (metrics)
OTEL_EXPORTER_OTLP_METRICS_HEADERSPer-signal override (metrics)
OTEL_EXPORTER_OTLP_METRICS_PROTOCOLPer-signal override (metrics)
OTEL_EXPORTER_OTLP_METRICS_TIMEOUTPer-signal override (metrics)
OTEL_EXPORTER_OTLP_METRICS_COMPRESSIONPer-signal override (metrics)
OTEL_EXPORTER_OTLP_METRICS_CERTIFICATEPer-signal override (metrics)
OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATEPer-signal override (metrics)
OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEYPer-signal override (metrics)
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCEMetric temporality preference: cumulative, delta, lowmemory
OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATIONDefault histogram aggregation: explicit_bucket_histogram, base2_exponential_bucket_histogram
OTEL_EXPORTER_OTLP_LOGS_ENDPOINTPer-signal override (logs)
OTEL_EXPORTER_OTLP_LOGS_HEADERSPer-signal override (logs)
OTEL_EXPORTER_OTLP_LOGS_PROTOCOLPer-signal override (logs)
OTEL_EXPORTER_OTLP_LOGS_TIMEOUTPer-signal override (logs)
OTEL_EXPORTER_OTLP_LOGS_COMPRESSIONPer-signal override (logs)
OTEL_EXPORTER_OTLP_LOGS_CERTIFICATEPer-signal override (logs)
OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATEPer-signal override (logs)
OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEYPer-signal override (logs)
OTEL_EXPORTER_PROMETHEUS_HOSTPrometheus exporter bind host
OTEL_EXPORTER_PROMETHEUS_PORTPrometheus exporter bind port
OTEL_METRIC_EXPORT_INTERVALPeriodic metric reader export interval (ms)
OTEL_METRIC_EXPORT_TIMEOUTPeriodic metric reader export timeout (ms)
OTEL_METRICS_EXEMPLAR_FILTERExemplar filter: always_on, always_off, trace_based
OTEL_BSP_SCHEDULE_DELAYBatch span processor: schedule delay (ms)
OTEL_BSP_EXPORT_TIMEOUTBatch span processor: export timeout (ms)
OTEL_BSP_MAX_QUEUE_SIZEBatch span processor: max queue size
OTEL_BSP_MAX_EXPORT_BATCH_SIZEBatch span processor: max export batch size
OTEL_BLRP_SCHEDULE_DELAYBatch log record processor: schedule delay (ms)
OTEL_BLRP_EXPORT_TIMEOUTBatch log record processor: export timeout (ms)
OTEL_BLRP_MAX_QUEUE_SIZEBatch log record processor: max queue size
OTEL_BLRP_MAX_EXPORT_BATCH_SIZEBatch log record processor: max export batch size
OTEL_ATTRIBUTE_COUNT_LIMITDefault max attributes per span/log/event/link
OTEL_ATTRIBUTE_VALUE_LENGTH_LIMITDefault max attribute value length
OTEL_SPAN_ATTRIBUTE_COUNT_LIMITMax attributes per span
OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMITMax span attribute value length
OTEL_SPAN_EVENT_COUNT_LIMITMax events per span
OTEL_SPAN_LINK_COUNT_LIMITMax links per span
OTEL_EVENT_ATTRIBUTE_COUNT_LIMITMax attributes per span event
OTEL_LINK_ATTRIBUTE_COUNT_LIMITMax attributes per span link
OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMITMax attributes per log record
OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMITMax log record attribute value length

See src/EnvironmentConfigFactory.ts for the exact parsing logic.

Development

Generated files

src/generated/ is auto-generated — do not edit manually. It contains:

  • types.ts — TypeScript interfaces derived from the JSON schema (via json-schema-to-typescript)
  • validator.js — Pre-compiled ajv validator (ahead-of-time compiled from the schema at build time; eliminates runtime ajv.compile())
  • validator.d.ts — TypeScript declarations for validator.js

Regenerating after a schema version bump

  • Update the CONFIG_VERSION constant in scripts/generate-config.js

  • Run from this package directory:

    npm run generate:config
    
  • Review the diff in src/generated/types.ts and src/generated/validator.js

  • Update SUPPORTED_FILE_FORMAT_MAJOR / SUPPORTED_FILE_FORMAT_MINOR in src/FileConfigFactory.ts if the new schema version is outside the currently-supported range

  • Update EnvironmentConfigFactory.ts and utils.ts if new fields need env var mapping

The generation script (scripts/generate-config.js) handles several post-processing steps:

  • Renames the root type from OpenTelemetryConfiguration to ConfigurationModel
  • Makes file_format optional (required at parse time but not needed when constructing the model in code)
  • Removes the duplicate type declarations that json-schema-to-typescript emits for structurally-identical sub-schemas (e.g. the second GrpcTls/HttpTls)
  • Produces a pre-compiled ajv validator (validator.js + validator.d.ts) for use at runtime

Defaults

Both config paths apply the same spec-defined defaults so consumers see consistent behaviour regardless of config source:

FieldDefault
disabledfalse
log_levelinfo
attribute_limits.attribute_count_limit128

FileConfigFactory applies these via applyConfigDefaults() after schema validation. EnvironmentConfigFactory applies them via initializeDefaultConfiguration() in the constructor, then overlays env var values on top.

One intentional exception in both paths: AttributeNameValue.type is not defaulted even though the spec says "if omitted, string is used". This is a semantic default for SDK code interpreting resource attributes, not a config-parser concern. SDK code reading resource.attributes should apply attr.type ?? 'string' at the point of use.

Supported schema versions

  • 1.0
  • 1.1

For a per-field view of which schema fields the SDK currently applies, see the JS row in the cross-SDK language support status doc maintained in the opentelemetry-configuration repo. That doc is the source of truth for declarative-config conformance across all SDKs.

License

Apache 2.0 - See LICENSE for more information.

Keywords

opentelemetry

FAQs

Package last updated on 02 Jul 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts