@opentelemetry/configuration 0.215.0 → 0.217.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +122 -13
  2. package/build/src/ConfigFactory.js +3 -1
  3. package/build/src/ConfigFactory.js.map +1 -1
  4. package/build/src/EnvironmentConfigFactory.d.ts +1 -1
  5. package/build/src/EnvironmentConfigFactory.js +195 -307
  6. package/build/src/EnvironmentConfigFactory.js.map +1 -1
  7. package/build/src/FileConfigFactory.d.ts +2 -17
  8. package/build/src/FileConfigFactory.js +269 -1054
  9. package/build/src/FileConfigFactory.js.map +1 -1
  10. package/build/src/IConfigFactory.d.ts +2 -2
  11. package/build/src/IConfigFactory.js.map +1 -1
  12. package/build/src/generated/types.d.ts +1652 -0
  13. package/build/src/generated/types.js +13 -0
  14. package/build/src/generated/types.js.map +1 -0
  15. package/build/src/generated/validator.d.ts +17 -0
  16. package/build/src/generated/validator.js +8412 -0
  17. package/build/src/generated/validator.js.map +1 -0
  18. package/build/src/index.d.ts +1 -4
  19. package/build/src/index.js.map +1 -1
  20. package/build/src/utils.d.ts +6 -66
  21. package/build/src/utils.js +68 -151
  22. package/build/src/utils.js.map +1 -1
  23. package/build/src/version.d.ts +1 -1
  24. package/build/src/version.js +1 -1
  25. package/build/src/version.js.map +1 -1
  26. package/package.json +6 -3
  27. package/build/src/models/commonModel.d.ts +0 -183
  28. package/build/src/models/commonModel.js +0 -40
  29. package/build/src/models/commonModel.js.map +0 -1
  30. package/build/src/models/configModel.d.ts +0 -77
  31. package/build/src/models/configModel.js +0 -21
  32. package/build/src/models/configModel.js.map +0 -1
  33. package/build/src/models/loggerProviderModel.d.ts +0 -134
  34. package/build/src/models/loggerProviderModel.js +0 -18
  35. package/build/src/models/loggerProviderModel.js.map +0 -1
  36. package/build/src/models/meterProviderModel.d.ts +0 -459
  37. package/build/src/models/meterProviderModel.js +0 -50
  38. package/build/src/models/meterProviderModel.js.map +0 -1
  39. package/build/src/models/resourceModel.d.ts +0 -72
  40. package/build/src/models/resourceModel.js +0 -7
  41. package/build/src/models/resourceModel.js.map +0 -1
  42. package/build/src/models/tracerProviderModel.d.ts +0 -256
  43. package/build/src/models/tracerProviderModel.js +0 -30
  44. package/build/src/models/tracerProviderModel.js.map +0 -1
package/README.md CHANGED
@@ -1,35 +1,144 @@
1
- # OpenTelemetry SDK for Node.js
1
+ # OpenTelemetry Declarative Configuration
2
2
 
3
+ [![NPM Published Version][npm-img]][npm-url]
3
4
  [![Apache License][license-image]][license-image]
4
5
 
5
6
  **Note: This is an experimental package under active development. New releases may include breaking changes.**
6
7
 
7
- This package provides the configuration for OpenTelemetry JavaScript SDK.
8
+ This package implements the [OpenTelemetry declarative configuration](https://github.com/open-telemetry/opentelemetry-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.
8
9
 
9
- ## Quick Start
10
+ ## Installation
10
11
 
11
- **Note: Much of OpenTelemetry JS documentation is written assuming the compiled application is run as CommonJS.**
12
- For more details on ECMAScript Modules vs CommonJS, refer to [esm-support](https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/esm-support.md).
12
+ ```sh
13
+ npm install @opentelemetry/configuration
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ `createConfigFactory()` selects the configuration source automatically:
19
+
20
+ - If `OTEL_CONFIG_FILE` points to a valid `.yaml`/`.yml` file, configuration is read from that file.
21
+ - Otherwise, configuration is assembled from standard OpenTelemetry environment variables.
22
+
23
+ ```typescript
24
+ import { createConfigFactory } from '@opentelemetry/configuration';
25
+
26
+ const factory = createConfigFactory();
27
+ const config = factory.getConfigModel();
28
+ ```
13
29
 
14
- To get started you need to install `@opentelemetry/configuration`.
30
+ ### YAML file configuration
15
31
 
16
- ### Installation
32
+ Set `OTEL_CONFIG_FILE` to the path of your configuration file:
17
33
 
18
34
  ```sh
19
- # Install the package
20
- npm install @opentelemetry/configuration
35
+ OTEL_CONFIG_FILE=./otel-config.yaml node app.js
21
36
  ```
22
37
 
38
+ Example:
39
+
40
+ ```yaml
41
+ file_format: "1.0"
42
+ resource:
43
+ attributes:
44
+ - name: service.name
45
+ value: my-service
46
+ tracer_provider:
47
+ processors:
48
+ - batch:
49
+ exporter:
50
+ otlp_http:
51
+ endpoint: http://localhost:4318/v1/traces
52
+ ```
53
+
54
+ Environment variable substitution is supported using `${VAR_NAME}`, `${VAR_NAME:-default}`, `${env:VAR_NAME}`, and `${env:VAR_NAME:-default}` syntax. Use `$$` for a literal `$`.
55
+
56
+ ```yaml
57
+ tracer_provider:
58
+ processors:
59
+ - batch:
60
+ exporter:
61
+ otlp_http:
62
+ endpoint: ${OTEL_EXPORTER_ENDPOINT:-http://localhost:4318}/v1/traces
63
+ ```
64
+
65
+ ### Environment variable configuration
66
+
67
+ When no config file is set, the factory reads from the standard OpenTelemetry SDK environment variables:
68
+
69
+ | Variable | Description |
70
+ | --- | --- |
71
+ | `OTEL_SDK_DISABLED` | Disable the SDK entirely |
72
+ | `OTEL_LOG_LEVEL` | Internal SDK log level |
73
+ | `OTEL_SERVICE_NAME` | Service name resource attribute |
74
+ | `OTEL_RESOURCE_ATTRIBUTES` | Comma-separated resource attributes |
75
+ | `OTEL_TRACES_EXPORTER` | Traces exporter(s): `otlp`, `console`, `none` |
76
+ | `OTEL_METRICS_EXPORTER` | Metrics exporter(s): `otlp`, `prometheus`, `console`, `none` |
77
+ | `OTEL_LOGS_EXPORTER` | Logs exporter(s): `otlp`, `console`, `none` |
78
+ | `OTEL_EXPORTER_OTLP_PROTOCOL` | OTLP protocol: `grpc`, `http/protobuf`, `http/json` |
79
+ | `OTEL_PROPAGATORS` | Propagators: `tracecontext`, `baggage`, `b3`, `b3multi` |
80
+
81
+ ## Development
82
+
83
+ ### Generated files
84
+
85
+ `src/generated/` is auto-generated — do not edit manually. It contains:
86
+
87
+ - `types.ts` — TypeScript interfaces derived from the JSON schema (via `json-schema-to-typescript`)
88
+ - `schema.ts` — The raw JSON schema exported as a constant (retained for reference; not used at runtime)
89
+ - `validator.js` — Pre-compiled ajv validator (ahead-of-time compiled from the schema at build time; eliminates runtime `ajv.compile()`)
90
+ - `validator.d.ts` — TypeScript declarations for `validator.js`
91
+
92
+ ### Regenerating after a schema version bump
93
+
94
+ 1. Update the `CONFIG_VERSION` variable in `scripts/config/generate-config.sh`
95
+ 2. Run from this package directory:
96
+
97
+ ```sh
98
+ npm run generate:config
99
+ ```
100
+
101
+ 3. Review the diff in `src/generated/types.ts`, `src/generated/schema.ts`, and `src/generated/validator.js`
102
+ 4. Update `supportedFileVersionPattern` in `src/FileConfigFactory.ts` if the new version falls outside the current regex
103
+ 5. Update `EnvironmentConfigFactory.ts` and `utils.ts` if new fields need env var mapping
104
+
105
+ The generation script (`scripts/config/generate-config.js`) handles several post-processing steps:
106
+
107
+ - Renames the root type from `OpenTelemetryConfiguration` to `ConfigurationModel`
108
+ - Makes `file_format` optional (required at parse time but not needed when constructing the model in code)
109
+ - Replaces narrow index signatures (`[k: string]: {} | null`) with `[k: string]: unknown`
110
+ - Deduplicates structurally-identical TLS types (`GrpcTls1`/`HttpTls1` → `GrpcTls`/`HttpTls`)
111
+ - Produces a pre-compiled ajv validator (`validator.js` + `validator.d.ts`) for use at runtime
112
+
113
+ ### Defaults
114
+
115
+ Both config paths apply the same spec-defined defaults so consumers see consistent behaviour regardless of config source:
116
+
117
+ | Field | Default |
118
+ | --- | --- |
119
+ | `disabled` | `false` |
120
+ | `log_level` | `info` |
121
+ | `attribute_limits.attribute_count_limit` | `128` |
122
+
123
+ `FileConfigFactory` applies these via `applyConfigDefaults()` after schema validation. `EnvironmentConfigFactory` applies them via `initializeDefaultConfiguration()` in the constructor, then overlays env var values on top.
124
+
125
+ 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.
126
+
127
+ ## Supported schema versions
128
+
129
+ - `1.0`
130
+
23
131
  ## Useful links
24
132
 
25
- - For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
26
- - For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>
27
- - For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
133
+ - [OpenTelemetry Declarative Configuration Specification](https://github.com/open-telemetry/opentelemetry-configuration)
134
+ - [OpenTelemetry for Node.js](https://github.com/open-telemetry/opentelemetry-js)
135
+ - [OpenTelemetry Community](https://opentelemetry.io/)
28
136
 
29
137
  ## License
30
138
 
31
139
  Apache 2.0 - See [LICENSE][license-url] for more information.
32
140
 
33
- [discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions
141
+ [npm-url]: https://www.npmjs.com/package/@opentelemetry/configuration
142
+ [npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fconfiguration.svg
34
143
  [license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/main/LICENSE
35
144
  [license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
@@ -5,10 +5,12 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.createConfigFactory = void 0;
8
+ const core_1 = require("@opentelemetry/core");
8
9
  const EnvironmentConfigFactory_1 = require("./EnvironmentConfigFactory");
9
10
  const FileConfigFactory_1 = require("./FileConfigFactory");
10
11
  function createConfigFactory() {
11
- if ((0, FileConfigFactory_1.hasValidConfigFile)()) {
12
+ const configFile = (0, core_1.getStringFromEnv)('OTEL_CONFIG_FILE');
13
+ if (configFile) {
12
14
  return new FileConfigFactory_1.FileConfigFactory();
13
15
  }
14
16
  return new EnvironmentConfigFactory_1.EnvironmentConfigFactory();
@@ -1 +1 @@
1
- {"version":3,"file":"ConfigFactory.js","sourceRoot":"","sources":["../../src/ConfigFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,yEAAsE;AACtE,2DAA4E;AAE5E,SAAgB,mBAAmB;IACjC,IAAI,IAAA,sCAAkB,GAAE,EAAE;QACxB,OAAO,IAAI,qCAAiB,EAAE,CAAC;KAChC;IACD,OAAO,IAAI,mDAAwB,EAAE,CAAC;AACxC,CAAC;AALD,kDAKC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ConfigFactory } from './IConfigFactory';\nimport { EnvironmentConfigFactory } from './EnvironmentConfigFactory';\nimport { FileConfigFactory, hasValidConfigFile } from './FileConfigFactory';\n\nexport function createConfigFactory(): ConfigFactory {\n if (hasValidConfigFile()) {\n return new FileConfigFactory();\n }\n return new EnvironmentConfigFactory();\n}\n"]}
1
+ {"version":3,"file":"ConfigFactory.js","sourceRoot":"","sources":["../../src/ConfigFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,8CAAuD;AAEvD,yEAAsE;AACtE,2DAAwD;AAExD,SAAgB,mBAAmB;IACjC,MAAM,UAAU,GAAG,IAAA,uBAAgB,EAAC,kBAAkB,CAAC,CAAC;IACxD,IAAI,UAAU,EAAE;QACd,OAAO,IAAI,qCAAiB,EAAE,CAAC;KAChC;IACD,OAAO,IAAI,mDAAwB,EAAE,CAAC;AACxC,CAAC;AAND,kDAMC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { getStringFromEnv } from '@opentelemetry/core';\nimport type { ConfigFactory } from './IConfigFactory';\nimport { EnvironmentConfigFactory } from './EnvironmentConfigFactory';\nimport { FileConfigFactory } from './FileConfigFactory';\n\nexport function createConfigFactory(): ConfigFactory {\n const configFile = getStringFromEnv('OTEL_CONFIG_FILE');\n if (configFile) {\n return new FileConfigFactory();\n }\n return new EnvironmentConfigFactory();\n}\n"]}
@@ -1,5 +1,5 @@
1
- import type { ConfigurationModel } from './models/configModel';
2
1
  import type { ConfigFactory } from './IConfigFactory';
2
+ import type { ConfigurationModel } from './generated/types';
3
3
  import type { EnvValues } from './EnvReader';
4
4
  /**
5
5
  * EnvironmentConfigProvider provides a configuration based on environment variables.