Skip to content

Commit 4222024

Browse files
authored
fix(configuration): improve handling of enums in generated types (#6659)
1 parent 7938714 commit 4222024

9 files changed

Lines changed: 364 additions & 1004 deletions

File tree

experimental/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
1818
* fix(configuration): do not validate `OTEL_CONFIG_FILE` value before using it for file config [#6643](https://github.com/open-telemetry/opentelemetry-js/pull/6643) @trentm
1919
* fix(configuration): improve how 'additionalProperties' in JSON schema is translated to TS types [#6650](https://github.com/open-telemetry/opentelemetry-js/pull/6650) @trentm
2020
* fix(configuration): remove stripMinItems and preprocessNullArrays from validation/parsing [#6657](https://github.com/open-telemetry/opentelemetry-js/pull/6657) @trentm
21+
* fix(configuration): improve handling of enums in generated types [#6659](https://github.com/open-telemetry/opentelemetry-js/pull/6659) @trentm
2122
* fix(sampler-jaeger-remote): add missing axios dep [#6656](https://github.com/open-telemetry/opentelemetry-js/pull/6656) @trentm
2223

2324
### :books: Documentation

experimental/packages/configuration/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ The generation script (`scripts/config/generate-config.js`) handles several post
106106

107107
- Renames the root type from `OpenTelemetryConfiguration` to `ConfigurationModel`
108108
- Makes `file_format` optional (required at parse time but not needed when constructing the model in code)
109-
- Strips `minItems` constraints from the runtime schema (so `processors: null` in YAML is accepted)
110109
- Replaces narrow index signatures (`[k: string]: {} | null`) with `[k: string]: unknown`
111-
- Appends named `const` enum objects for inlined enum types (e.g. `ExemplarFilter`, `SeverityNumber`)
112110
- Deduplicates structurally-identical TLS types (`GrpcTls1`/`HttpTls1` → `GrpcTls`/`HttpTls`)
113111
- Produces a pre-compiled ajv validator (`validator.js` + `validator.d.ts`) for use at runtime
114112

experimental/packages/configuration/src/EnvironmentConfigFactory.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@ import {
99
getNumberFromEnv,
1010
} from '@opentelemetry/core';
1111
import type { ConfigFactory } from './IConfigFactory';
12-
import {
12+
import type {
1313
ExemplarFilter,
14-
OtlpHttpEncoding,
15-
type BatchLogRecordProcessor,
16-
type BatchSpanProcessor,
17-
type ConfigurationModel,
18-
type ExporterDefaultHistogramAggregation,
19-
type ExporterTemporalityPreference,
20-
type LogRecordExporter,
21-
type LogRecordProcessor,
22-
type PeriodicMetricReader,
23-
type PushMetricExporter,
24-
type Sampler,
25-
type SeverityNumber,
26-
type SpanExporter,
27-
type SpanProcessor,
14+
BatchLogRecordProcessor,
15+
BatchSpanProcessor,
16+
ConfigurationModel,
17+
ExporterDefaultHistogramAggregation,
18+
ExporterTemporalityPreference,
19+
LogRecordExporter,
20+
LogRecordProcessor,
21+
PeriodicMetricReader,
22+
PushMetricExporter,
23+
Sampler,
24+
SeverityNumber,
25+
SpanExporter,
26+
SpanProcessor,
2827
} from './generated/types';
2928
import { diag } from '@opentelemetry/api';
3029
import {
@@ -368,9 +367,9 @@ export function setTracerProvider(
368367
);
369368
const encoding =
370369
protocol === 'http/json'
371-
? OtlpHttpEncoding.Json
370+
? 'json'
372371
: protocol === 'http/protobuf'
373-
? OtlpHttpEncoding.Protobuf
372+
? 'protobuf'
374373
: undefined;
375374
const otlpHttp: NonNullable<SpanExporter['otlp_http']> = {
376375
endpoint:
@@ -509,9 +508,9 @@ export function setMeterProvider(config: ConfigurationModel): void {
509508
);
510509
const encoding =
511510
protocol === 'http/json'
512-
? OtlpHttpEncoding.Json
511+
? 'json'
513512
: protocol === 'http/protobuf'
514-
? OtlpHttpEncoding.Protobuf
513+
? 'protobuf'
515514
: undefined;
516515
const otlpHttp: NonNullable<PushMetricExporter['otlp_http']> = {
517516
endpoint:
@@ -536,11 +535,10 @@ export function setMeterProvider(config: ConfigurationModel): void {
536535
}
537536

538537
const rawExemplarFilter =
539-
getStringFromEnv('OTEL_METRICS_EXEMPLAR_FILTER') ??
540-
ExemplarFilter.TraceBased;
538+
getStringFromEnv('OTEL_METRICS_EXEMPLAR_FILTER') ?? 'trace_based';
541539
config.meter_provider.exemplar_filter =
542540
rawExemplarFilter === 'default'
543-
? ExemplarFilter.TraceBased
541+
? 'trace_based'
544542
: (rawExemplarFilter as ExemplarFilter);
545543
}
546544

@@ -647,9 +645,9 @@ export function setLoggerProvider(config: ConfigurationModel): void {
647645
);
648646
const encoding =
649647
protocol === 'http/json'
650-
? OtlpHttpEncoding.Json
648+
? 'json'
651649
: protocol === 'http/protobuf'
652-
? OtlpHttpEncoding.Protobuf
650+
? 'protobuf'
653651
: undefined;
654652
const otlpHttp: NonNullable<LogRecordExporter['otlp_http']> = {
655653
endpoint:

experimental/packages/configuration/src/FileConfigFactory.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import type { ConfigFactory } from './IConfigFactory';
88
import * as fs from 'fs';
99
import * as yaml from 'yaml';
1010
import { envVariableSubstitution } from './utils';
11-
import { SeverityNumber } from './generated/types';
1211
import type {
1312
BatchLogRecordProcessor,
1413
BatchSpanProcessor,
@@ -217,7 +216,7 @@ function applyConfigDefaults(data: ConfigurationModel): void {
217216
data.disabled = false;
218217
}
219218
if (data.log_level == null) {
220-
data.log_level = SeverityNumber.Info;
219+
data.log_level = 'info';
221220
}
222221
if (data.attribute_limits == null) {
223222
data.attribute_limits = { attribute_count_limit: 128 };

0 commit comments

Comments
 (0)