@opentelemetry/configuration 0.216.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.
- package/README.md +122 -13
- package/build/src/ConfigFactory.js +3 -1
- package/build/src/ConfigFactory.js.map +1 -1
- package/build/src/EnvironmentConfigFactory.d.ts +1 -1
- package/build/src/EnvironmentConfigFactory.js +195 -307
- package/build/src/EnvironmentConfigFactory.js.map +1 -1
- package/build/src/FileConfigFactory.d.ts +2 -17
- package/build/src/FileConfigFactory.js +269 -1054
- package/build/src/FileConfigFactory.js.map +1 -1
- package/build/src/IConfigFactory.d.ts +2 -2
- package/build/src/IConfigFactory.js.map +1 -1
- package/build/src/generated/types.d.ts +1652 -0
- package/build/src/generated/types.js +13 -0
- package/build/src/generated/types.js.map +1 -0
- package/build/src/generated/validator.d.ts +17 -0
- package/build/src/generated/validator.js +8412 -0
- package/build/src/generated/validator.js.map +1 -0
- package/build/src/index.d.ts +1 -5
- package/build/src/index.js.map +1 -1
- package/build/src/utils.d.ts +6 -66
- package/build/src/utils.js +68 -151
- package/build/src/utils.js.map +1 -1
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/build/src/version.js.map +1 -1
- package/package.json +5 -2
- package/build/src/models/commonModel.d.ts +0 -183
- package/build/src/models/commonModel.js +0 -40
- package/build/src/models/commonModel.js.map +0 -1
- package/build/src/models/configModel.d.ts +0 -77
- package/build/src/models/configModel.js +0 -21
- package/build/src/models/configModel.js.map +0 -1
- package/build/src/models/loggerProviderModel.d.ts +0 -134
- package/build/src/models/loggerProviderModel.js +0 -18
- package/build/src/models/loggerProviderModel.js.map +0 -1
- package/build/src/models/meterProviderModel.d.ts +0 -459
- package/build/src/models/meterProviderModel.js +0 -50
- package/build/src/models/meterProviderModel.js.map +0 -1
- package/build/src/models/resourceModel.d.ts +0 -72
- package/build/src/models/resourceModel.js +0 -7
- package/build/src/models/resourceModel.js.map +0 -1
- package/build/src/models/tracerProviderModel.d.ts +0 -256
- package/build/src/models/tracerProviderModel.js +0 -30
- package/build/src/models/tracerProviderModel.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,35 +1,144 @@
|
|
|
1
|
-
# OpenTelemetry
|
|
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
|
|
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
|
-
##
|
|
10
|
+
## Installation
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
30
|
+
### YAML file configuration
|
|
15
31
|
|
|
16
|
-
|
|
32
|
+
Set `OTEL_CONFIG_FILE` to the path of your configuration file:
|
|
17
33
|
|
|
18
34
|
```sh
|
|
19
|
-
|
|
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
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
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
|
-
[
|
|
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
|
-
|
|
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;;;
|
|
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.
|