Skip to content

Commit 6953aa5

Browse files
feat(opentelemetry-config): add backups for compression, timeout, headers (#6058)
Co-authored-by: Marylia Gutierrez <[email protected]>
1 parent 74f470e commit 6953aa5

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

experimental/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
2020
### :rocket: Features
2121

2222
* feat(instrumentation): allow error of safeExecuteInTheMiddleAsync to be async [#6032](https://github.com/open-telemetry/opentelemetry-js/pull/6032) @JPeer264
23+
* feat(opentelemetry-config): add backups for compression, timeout, headers [#6058](https://github.com/open-telemetry/opentelemetry-js/pull/6058) @JamieDanielson
2324

2425
### :bug: Bug Fixes
2526

experimental/packages/opentelemetry-configuration/src/EnvironmentConfigProvider.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,23 @@ export function setTracerProvider(config: ConfigurationModel): void {
240240
batch.exporter.otlp_http.client_certificate_file = clientCertificateFile;
241241
}
242242

243-
const compression = getStringFromEnv(
244-
'OTEL_EXPORTER_OTLP_TRACES_COMPRESSION'
245-
);
243+
const compression =
244+
getStringFromEnv('OTEL_EXPORTER_OTLP_TRACES_COMPRESSION') ??
245+
getStringFromEnv('OTEL_EXPORTER_OTLP_COMPRESSION');
246246
if (compression && batch.exporter.otlp_http) {
247247
batch.exporter.otlp_http.compression = compression;
248248
}
249249

250-
const timeout = getNumberFromEnv('OTEL_EXPORTER_OTLP_TRACES_TIMEOUT');
250+
const timeout =
251+
getNumberFromEnv('OTEL_EXPORTER_OTLP_TRACES_TIMEOUT') ??
252+
getNumberFromEnv('OTEL_EXPORTER_OTLP_TIMEOUT');
251253
if (timeout && batch.exporter.otlp_http) {
252254
batch.exporter.otlp_http.timeout = timeout;
253255
}
254256

255-
const headersList = getStringFromEnv('OTEL_EXPORTER_OTLP_TRACES_HEADERS');
257+
const headersList =
258+
getStringFromEnv('OTEL_EXPORTER_OTLP_TRACES_HEADERS') ??
259+
getStringFromEnv('OTEL_EXPORTER_OTLP_HEADERS');
256260
if (headersList && batch.exporter.otlp_http) {
257261
batch.exporter.otlp_http.headers_list = headersList;
258262
}
@@ -314,19 +318,23 @@ export function setMeterProvider(config: ConfigurationModel): void {
314318
clientCertificateFile;
315319
}
316320

317-
const compression = getStringFromEnv(
318-
'OTEL_EXPORTER_OTLP_METRICS_COMPRESSION'
319-
);
321+
const compression =
322+
getStringFromEnv('OTEL_EXPORTER_OTLP_METRICS_COMPRESSION') ??
323+
getStringFromEnv('OTEL_EXPORTER_OTLP_COMPRESSION');
320324
if (compression) {
321325
readerPeriodic.exporter.otlp_http.compression = compression;
322326
}
323327

324-
const timeoutEx = getNumberFromEnv('OTEL_EXPORTER_OTLP_METRICS_TIMEOUT');
328+
const timeoutEx =
329+
getNumberFromEnv('OTEL_EXPORTER_OTLP_METRICS_TIMEOUT') ??
330+
getNumberFromEnv('OTEL_EXPORTER_OTLP_TIMEOUT');
325331
if (timeoutEx) {
326332
readerPeriodic.exporter.otlp_http.timeout = timeoutEx;
327333
}
328334

329-
const headersList = getStringFromEnv('OTEL_EXPORTER_OTLP_METRICS_HEADERS');
335+
const headersList =
336+
getStringFromEnv('OTEL_EXPORTER_OTLP_METRICS_HEADERS') ??
337+
getStringFromEnv('OTEL_EXPORTER_OTLP_HEADERS');
330338
if (headersList) {
331339
readerPeriodic.exporter.otlp_http.headers_list = headersList;
332340
}
@@ -478,17 +486,23 @@ export function setLoggerProvider(config: ConfigurationModel): void {
478486
batch.exporter.otlp_http.client_certificate_file = clientCertificateFile;
479487
}
480488

481-
const compression = getStringFromEnv('OTEL_EXPORTER_OTLP_LOGS_COMPRESSION');
489+
const compression =
490+
getStringFromEnv('OTEL_EXPORTER_OTLP_LOGS_COMPRESSION') ??
491+
getStringFromEnv('OTEL_EXPORTER_OTLP_COMPRESSION');
482492
if (compression && batch.exporter.otlp_http) {
483493
batch.exporter.otlp_http.compression = compression;
484494
}
485495

486-
const timeout = getNumberFromEnv('OTEL_EXPORTER_OTLP_LOGS_TIMEOUT');
496+
const timeout =
497+
getNumberFromEnv('OTEL_EXPORTER_OTLP_LOGS_TIMEOUT') ??
498+
getNumberFromEnv('OTEL_EXPORTER_OTLP_TIMEOUT');
487499
if (timeout && batch.exporter.otlp_http) {
488500
batch.exporter.otlp_http.timeout = timeout;
489501
}
490502

491-
const headersList = getStringFromEnv('OTEL_EXPORTER_OTLP_LOGS_HEADERS');
503+
const headersList =
504+
getStringFromEnv('OTEL_EXPORTER_OTLP_LOGS_HEADERS') ??
505+
getStringFromEnv('OTEL_EXPORTER_OTLP_HEADERS');
492506
if (headersList && batch.exporter.otlp_http) {
493507
batch.exporter.otlp_http.headers_list = headersList;
494508
}

experimental/packages/opentelemetry-configuration/test/ConfigProvider.test.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,14 +1064,16 @@ describe('ConfigProvider', function () {
10641064
);
10651065
});
10661066

1067-
it('should use backup option for certificates', function () {
1067+
it('should use backup options for exporters', function () {
10681068
process.env.OTEL_EXPORTER_OTLP_CERTIFICATE =
10691069
'backup_certificate_file.pem';
10701070
process.env.OTEL_EXPORTER_OTLP_CLIENT_KEY = 'backup_client_key.pem';
10711071
process.env.OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE =
10721072
'backup_client_certificate.pem';
10731073
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://backup.com:4318';
1074-
1074+
process.env.OTEL_EXPORTER_OTLP_COMPRESSION = 'backup_compression';
1075+
process.env.OTEL_EXPORTER_OTLP_TIMEOUT = '12000';
1076+
process.env.OTEL_EXPORTER_OTLP_HEADERS = 'backup_headers=123';
10751077
const expectedConfig: Configuration = {
10761078
...defaultConfig,
10771079
tracer_provider: {
@@ -1082,11 +1084,13 @@ describe('ConfigProvider', function () {
10821084
exporter: {
10831085
otlp_http: {
10841086
endpoint: 'http://backup.com:4318/v1/traces',
1085-
timeout: 10000,
1087+
timeout: 12000,
1088+
compression: 'backup_compression',
10861089
encoding: OtlpHttpEncoding.Protobuf,
10871090
certificate_file: 'backup_certificate_file.pem',
10881091
client_certificate_file: 'backup_client_certificate.pem',
10891092
client_key_file: 'backup_client_key.pem',
1093+
headers_list: 'backup_headers=123',
10901094
},
10911095
},
10921096
},
@@ -1105,14 +1109,16 @@ describe('ConfigProvider', function () {
11051109
exporter: {
11061110
otlp_http: {
11071111
endpoint: 'http://backup.com:4318/v1/metrics',
1108-
timeout: 10000,
1112+
timeout: 12000,
1113+
compression: 'backup_compression',
11091114
temporality_preference:
11101115
ExporterTemporalityPreference.Cumulative,
11111116
default_histogram_aggregation:
11121117
ExporterDefaultHistogramAggregation.ExplicitBucketHistogram,
11131118
certificate_file: 'backup_certificate_file.pem',
11141119
client_certificate_file: 'backup_client_certificate.pem',
11151120
client_key_file: 'backup_client_key.pem',
1121+
headers_list: 'backup_headers=123',
11161122
},
11171123
},
11181124
},
@@ -1131,11 +1137,13 @@ describe('ConfigProvider', function () {
11311137
exporter: {
11321138
otlp_http: {
11331139
endpoint: 'http://backup.com:4318/v1/logs',
1134-
timeout: 10000,
1140+
timeout: 12000,
1141+
compression: 'backup_compression',
11351142
encoding: OtlpHttpEncoding.Protobuf,
11361143
certificate_file: 'backup_certificate_file.pem',
11371144
client_certificate_file: 'backup_client_certificate.pem',
11381145
client_key_file: 'backup_client_key.pem',
1146+
headers_list: 'backup_headers=123',
11391147
},
11401148
},
11411149
},

0 commit comments

Comments
 (0)