@opentelemetry/configuration 0.216.0 → 0.218.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 +281 -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 +8413 -0
  17. package/build/src/generated/validator.js.map +1 -0
  18. package/build/src/index.d.ts +1 -5
  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 +5 -2
  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
@@ -5,13 +5,8 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.setLoggerProvider = exports.setMeterProvider = exports.setTracerProvider = exports.setSampler = exports.setPropagators = exports.setAttributeLimits = exports.setResources = exports.EnvironmentConfigFactory = void 0;
8
- const configModel_1 = require("./models/configModel");
9
8
  const core_1 = require("@opentelemetry/core");
10
- const meterProviderModel_1 = require("./models/meterProviderModel");
11
- const commonModel_1 = require("./models/commonModel");
12
9
  const api_1 = require("@opentelemetry/api");
13
- const tracerProviderModel_1 = require("./models/tracerProviderModel");
14
- const loggerProviderModel_1 = require("./models/loggerProviderModel");
15
10
  const utils_1 = require("./utils");
16
11
  const EnvReader_1 = require("./EnvReader");
17
12
  const EnvDefinition_1 = require("./EnvDefinition");
@@ -21,12 +16,13 @@ const EnvDefinition_1 = require("./EnvDefinition");
21
16
  class EnvironmentConfigFactory {
22
17
  _config;
23
18
  constructor() {
24
- this._config = (0, configModel_1.initializeDefaultConfiguration)();
19
+ this._config = (0, utils_1.initializeDefaultConfiguration)();
25
20
  const envValues = (0, EnvReader_1.readAllEnvVars)();
26
21
  this._config.disabled = envValues.OTEL_SDK_DISABLED;
27
- const logLevel = (0, core_1.diagLogLevelFromString)((0, core_1.getStringFromEnv)('OTEL_LOG_LEVEL'));
28
- if (logLevel) {
29
- this._config.log_level = logLevel;
22
+ const logLevelString = (0, core_1.getStringFromEnv)('OTEL_LOG_LEVEL');
23
+ if (logLevelString) {
24
+ this._config.log_level =
25
+ severityNumberConfigFromLogLevelString(logLevelString);
30
26
  }
31
27
  setResources(this._config);
32
28
  setAttributeLimits(this._config);
@@ -40,6 +36,36 @@ class EnvironmentConfigFactory {
40
36
  }
41
37
  }
42
38
  exports.EnvironmentConfigFactory = EnvironmentConfigFactory;
39
+ const SEV_NUM_CONFIG_FROM_LOG_LEVEL = {
40
+ // Declarative config `log_level` has no "NONE". Using 'fatal' is
41
+ // equivalent, because the OTel JS diag API does not have a "fatal" level.
42
+ NONE: 'fatal',
43
+ ERROR: 'error',
44
+ WARN: 'warn',
45
+ INFO: 'info',
46
+ DEBUG: 'debug',
47
+ VERBOSE: 'trace2',
48
+ // Declarative config `log_level` has no "ALL". Using 'trace' is
49
+ // equivalent, because that is the lowest SeverityNumber level.
50
+ ALL: 'trace',
51
+ };
52
+ /**
53
+ * Return a declarative config SeverityNumberConfig value (as used for
54
+ * `log_level`) for the given `OTEL_LOG_LEVEL` string value.
55
+ *
56
+ * See notes at "opentelemetr-sdk-node/src/diag.ts".
57
+ */
58
+ function severityNumberConfigFromLogLevelString(str) {
59
+ if (!str) {
60
+ return undefined;
61
+ }
62
+ const sevNumConfig = SEV_NUM_CONFIG_FROM_LOG_LEVEL[str.toUpperCase()];
63
+ if (!sevNumConfig) {
64
+ api_1.diag.warn(`Unknown log level "${str}", expected one of ${Object.keys(SEV_NUM_CONFIG_FROM_LOG_LEVEL)}, using default info`);
65
+ return 'info';
66
+ }
67
+ return sevNumConfig;
68
+ }
43
69
  function setResources(config) {
44
70
  if (config.resource == null) {
45
71
  config.resource = {};
@@ -127,8 +153,22 @@ function setPropagators(config) {
127
153
  const composite = (0, core_1.getStringListFromEnv)('OTEL_PROPAGATORS');
128
154
  if (composite && composite.length > 0) {
129
155
  config.propagator.composite = [];
130
- for (let i = 0; i < composite.length; i++) {
131
- config.propagator.composite.push({ [composite[i]]: null });
156
+ for (const name of composite) {
157
+ if (name === 'tracecontext') {
158
+ config.propagator.composite.push({ tracecontext: {} });
159
+ }
160
+ else if (name === 'baggage') {
161
+ config.propagator.composite.push({ baggage: {} });
162
+ }
163
+ else if (name === 'b3') {
164
+ config.propagator.composite.push({ b3: {} });
165
+ }
166
+ else if (name === 'b3multi') {
167
+ config.propagator.composite.push({ b3multi: {} });
168
+ }
169
+ else {
170
+ config.propagator.composite.push({ [name]: {} });
171
+ }
132
172
  }
133
173
  }
134
174
  const compositeList = (0, core_1.getStringFromEnv)('OTEL_PROPAGATORS');
@@ -186,7 +226,7 @@ function setTracerProvider(config, env) {
186
226
  api_1.diag.info(`OTEL_TRACES_EXPORTER contains "none". Tracer provider will not be initialized.`);
187
227
  return;
188
228
  }
189
- config.tracer_provider = (0, tracerProviderModel_1.initializeDefaultTracerProviderConfiguration)();
229
+ config.tracer_provider = (0, utils_1.initializeDefaultTracerProviderConfiguration)();
190
230
  setSampler(config, env);
191
231
  const attributeValueLengthLimit = (0, core_1.getNumberFromEnv)('OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT');
192
232
  if (attributeValueLengthLimit) {
@@ -215,33 +255,26 @@ function setTracerProvider(config, env) {
215
255
  config.tracer_provider.limits.link_attribute_count_limit =
216
256
  linkAttributeCountLimit;
217
257
  }
218
- const batch = { exporter: {} };
219
- const scheduleDelay = (0, core_1.getNumberFromEnv)('OTEL_BSP_SCHEDULE_DELAY') ?? 5000;
220
- if (scheduleDelay) {
221
- batch.schedule_delay = scheduleDelay;
222
- }
223
- const exportTimeout = (0, core_1.getNumberFromEnv)('OTEL_BSP_EXPORT_TIMEOUT') ?? 30000;
224
- if (exportTimeout) {
225
- batch.export_timeout = exportTimeout;
226
- }
227
- const maxQueueSize = (0, core_1.getNumberFromEnv)('OTEL_BSP_MAX_QUEUE_SIZE') ?? 2048;
228
- if (maxQueueSize) {
229
- batch.max_queue_size = maxQueueSize;
230
- }
231
- const maxExportBatchSize = (0, core_1.getNumberFromEnv)('OTEL_BSP_MAX_EXPORT_BATCH_SIZE') ?? 512;
232
- if (maxExportBatchSize) {
233
- batch.max_export_batch_size = maxExportBatchSize;
234
- }
258
+ const batch = {
259
+ exporter: {},
260
+ schedule_delay: (0, core_1.getNumberFromEnv)('OTEL_BSP_SCHEDULE_DELAY') ?? 5000,
261
+ export_timeout: (0, core_1.getNumberFromEnv)('OTEL_BSP_EXPORT_TIMEOUT') ?? 30000,
262
+ max_queue_size: (0, core_1.getNumberFromEnv)('OTEL_BSP_MAX_QUEUE_SIZE') ?? 2048,
263
+ max_export_batch_size: (0, core_1.getNumberFromEnv)('OTEL_BSP_MAX_EXPORT_BATCH_SIZE') ?? 512,
264
+ };
235
265
  for (let i = 0; i < exportersType.length; i++) {
236
266
  const exporterType = exportersType[i];
237
- const batchInfo = { ...batch };
267
+ const batchInfo = {
268
+ ...batch,
269
+ exporter: {},
270
+ };
238
271
  if (exporterType === 'console') {
239
- config.tracer_provider.processors.push({
272
+ const processor = {
240
273
  simple: { exporter: { console: {} } },
241
- });
274
+ };
275
+ config.tracer_provider.processors.push(processor);
242
276
  }
243
277
  else {
244
- // 'otlp' and default
245
278
  const protocol = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_PROTOCOL') ??
246
279
  (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_PROTOCOL') ??
247
280
  'http/protobuf';
@@ -259,60 +292,40 @@ function setTracerProvider(config, env) {
259
292
  const headersList = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_HEADERS') ??
260
293
  (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_HEADERS');
261
294
  if (protocol === 'grpc') {
262
- delete batchInfo.exporter.otlp_http;
263
- batchInfo.exporter.otlp_grpc = {};
264
- const endpoint = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT') ??
265
- (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT') ??
266
- 'http://localhost:4317';
267
- if (endpoint) {
268
- batchInfo.exporter.otlp_grpc.endpoint = endpoint;
269
- }
270
295
  const tls = (0, utils_1.getGrpcTlsConfig)(certificateFile, clientKeyFile, clientCertificateFile);
271
- if (tls) {
272
- batchInfo.exporter.otlp_grpc.tls = tls;
273
- }
274
- if (compression) {
275
- batchInfo.exporter.otlp_grpc.compression = compression;
276
- }
277
- if (timeout) {
278
- batchInfo.exporter.otlp_grpc.timeout = timeout;
279
- }
280
- if (headersList) {
281
- batchInfo.exporter.otlp_grpc.headers_list = headersList;
282
- }
296
+ const otlpGrpc = {
297
+ endpoint: (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT') ??
298
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT') ??
299
+ 'http://localhost:4317',
300
+ timeout,
301
+ ...(tls !== undefined && { tls }),
302
+ ...(compression !== undefined && { compression }),
303
+ ...(headersList !== undefined && { headers_list: headersList }),
304
+ };
305
+ batchInfo.exporter = { otlp_grpc: otlpGrpc };
283
306
  }
284
307
  else {
285
- if (batchInfo.exporter.otlp_http == null) {
286
- batchInfo.exporter.otlp_http = {};
287
- }
288
- const endpoint = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT') ??
289
- ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')
290
- ? `${(0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')}/v1/traces`
291
- : 'http://localhost:4318/v1/traces');
292
- if (endpoint) {
293
- batchInfo.exporter.otlp_http.endpoint = endpoint;
294
- }
295
308
  const tls = (0, utils_1.getHttpTlsConfig)(certificateFile, clientKeyFile, clientCertificateFile);
296
- if (tls) {
297
- batchInfo.exporter.otlp_http.tls = tls;
298
- }
299
- if (compression) {
300
- batchInfo.exporter.otlp_http.compression = compression;
301
- }
302
- if (timeout) {
303
- batchInfo.exporter.otlp_http.timeout = timeout;
304
- }
305
- if (headersList) {
306
- batchInfo.exporter.otlp_http.headers_list = headersList;
307
- }
308
- if (protocol === 'http/json') {
309
- batchInfo.exporter.otlp_http.encoding = commonModel_1.OtlpHttpEncoding.JSON;
310
- }
311
- else if (protocol === 'http/protobuf') {
312
- batchInfo.exporter.otlp_http.encoding = commonModel_1.OtlpHttpEncoding.Protobuf;
313
- }
309
+ const encoding = protocol === 'http/json'
310
+ ? 'json'
311
+ : protocol === 'http/protobuf'
312
+ ? 'protobuf'
313
+ : undefined;
314
+ const otlpHttp = {
315
+ endpoint: (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT') ??
316
+ ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')
317
+ ? `${(0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')}/v1/traces`
318
+ : 'http://localhost:4318/v1/traces'),
319
+ timeout,
320
+ ...(tls !== undefined && { tls }),
321
+ ...(compression !== undefined && { compression }),
322
+ ...(headersList !== undefined && { headers_list: headersList }),
323
+ ...(encoding !== undefined && { encoding }),
324
+ };
325
+ batchInfo.exporter = { otlp_http: otlpHttp };
314
326
  }
315
- config.tracer_provider.processors.push({ batch: batchInfo });
327
+ const processor = { batch: batchInfo };
328
+ config.tracer_provider.processors.push(processor);
316
329
  }
317
330
  }
318
331
  }
@@ -326,39 +339,33 @@ function setMeterProvider(config) {
326
339
  api_1.diag.info(`OTEL_METRICS_EXPORTER contains "none". Meter provider will not be initialized.`);
327
340
  return;
328
341
  }
329
- config.meter_provider = (0, meterProviderModel_1.initializeDefaultMeterProviderConfiguration)();
330
- const readerPeriodic = { exporter: {} };
342
+ config.meter_provider = (0, utils_1.initializeDefaultMeterProviderConfiguration)();
331
343
  const interval = (0, core_1.getNumberFromEnv)('OTEL_METRIC_EXPORT_INTERVAL') ?? 60000;
332
- if (interval) {
333
- readerPeriodic.interval = interval;
334
- }
335
344
  for (let i = 0; i < exportersType.length; i++) {
336
345
  const exporterType = exportersType[i];
337
346
  if (exporterType === 'prometheus') {
338
- // Prometheus uses a pull reader
339
347
  const pullReader = {
340
348
  exporter: {
341
349
  'prometheus/development': {
342
350
  host: (0, core_1.getStringFromEnv)('OTEL_EXPORTER_PROMETHEUS_HOST') ?? 'localhost',
343
351
  port: (0, core_1.getNumberFromEnv)('OTEL_EXPORTER_PROMETHEUS_PORT') ?? 9464,
344
352
  without_scope_info: false,
345
- without_target_info: false,
353
+ 'without_target_info/development': false,
346
354
  },
347
355
  },
348
356
  };
349
357
  config.meter_provider.readers.push({ pull: pullReader });
350
358
  continue;
351
359
  }
352
- const readerPeriodicInfo = { ...readerPeriodic };
353
- const timeout = (0, core_1.getNumberFromEnv)('OTEL_METRIC_EXPORT_TIMEOUT') ?? 30000;
354
- if (timeout) {
355
- readerPeriodicInfo.timeout = timeout;
356
- }
360
+ const readerPeriodicInfo = {
361
+ interval,
362
+ timeout: (0, core_1.getNumberFromEnv)('OTEL_METRIC_EXPORT_TIMEOUT') ?? 30000,
363
+ exporter: {},
364
+ };
357
365
  if (exporterType === 'console') {
358
366
  readerPeriodicInfo.exporter = { console: {} };
359
367
  }
360
368
  else {
361
- // 'otlp' and default
362
369
  const protocol = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_PROTOCOL') ??
363
370
  (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_PROTOCOL') ??
364
371
  'http/protobuf';
@@ -375,157 +382,65 @@ function setMeterProvider(config) {
375
382
  10000;
376
383
  const headersList = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_HEADERS') ??
377
384
  (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_HEADERS');
378
- const temporalityPreference = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE') ??
385
+ const rawTemporality = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE') ??
379
386
  'cumulative';
380
- const defaultHistogramAggregation = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION') ?? 'explicit_bucket_histogram';
387
+ const validTemporalities = ['cumulative', 'delta', 'low_memory'];
388
+ const temporalityPreference = validTemporalities.includes(rawTemporality)
389
+ ? rawTemporality
390
+ : 'cumulative';
391
+ const rawHistogramAgg = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION') ?? 'explicit_bucket_histogram';
392
+ const validHistogramAggs = [
393
+ 'explicit_bucket_histogram',
394
+ 'base2_exponential_bucket_histogram',
395
+ ];
396
+ const defaultHistogramAggregation = validHistogramAggs.includes(rawHistogramAgg)
397
+ ? rawHistogramAgg
398
+ : 'explicit_bucket_histogram';
381
399
  if (protocol === 'grpc') {
382
- delete readerPeriodicInfo.exporter.otlp_http;
383
- readerPeriodicInfo.exporter.otlp_grpc = {};
384
- const endpoint = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_ENDPOINT') ??
385
- (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT') ??
386
- 'http://localhost:4317';
387
- if (endpoint) {
388
- readerPeriodicInfo.exporter.otlp_grpc.endpoint = endpoint;
389
- }
390
400
  const tls = (0, utils_1.getGrpcTlsConfig)(certificateFile, clientKeyFile, clientCertificateFile);
391
- if (tls) {
392
- readerPeriodicInfo.exporter.otlp_grpc.tls = tls;
393
- }
394
- if (compression) {
395
- readerPeriodicInfo.exporter.otlp_grpc.compression = compression;
396
- }
397
- if (timeoutExporter) {
398
- readerPeriodicInfo.exporter.otlp_grpc.timeout = timeoutExporter;
399
- }
400
- if (headersList) {
401
- readerPeriodicInfo.exporter.otlp_grpc.headers_list = headersList;
402
- }
403
- if (temporalityPreference) {
404
- switch (temporalityPreference) {
405
- case 'cumulative':
406
- readerPeriodicInfo.exporter.otlp_grpc.temporality_preference =
407
- meterProviderModel_1.ExporterTemporalityPreference.Cumulative;
408
- break;
409
- case 'delta':
410
- readerPeriodicInfo.exporter.otlp_grpc.temporality_preference =
411
- meterProviderModel_1.ExporterTemporalityPreference.Delta;
412
- break;
413
- case 'low_memory':
414
- readerPeriodicInfo.exporter.otlp_grpc.temporality_preference =
415
- meterProviderModel_1.ExporterTemporalityPreference.LowMemory;
416
- break;
417
- default:
418
- readerPeriodicInfo.exporter.otlp_grpc.temporality_preference =
419
- meterProviderModel_1.ExporterTemporalityPreference.Cumulative;
420
- break;
421
- }
422
- }
423
- if (defaultHistogramAggregation) {
424
- switch (defaultHistogramAggregation) {
425
- case 'explicit_bucket_histogram':
426
- readerPeriodicInfo.exporter.otlp_grpc.default_histogram_aggregation =
427
- meterProviderModel_1.ExporterDefaultHistogramAggregation.ExplicitBucketHistogram;
428
- break;
429
- case 'base2_exponential_bucket_histogram':
430
- readerPeriodicInfo.exporter.otlp_grpc.default_histogram_aggregation =
431
- meterProviderModel_1.ExporterDefaultHistogramAggregation.Base2ExponentialBucketHistogram;
432
- break;
433
- default:
434
- readerPeriodicInfo.exporter.otlp_grpc.default_histogram_aggregation =
435
- meterProviderModel_1.ExporterDefaultHistogramAggregation.ExplicitBucketHistogram;
436
- break;
437
- }
438
- }
401
+ const otlpGrpc = {
402
+ endpoint: (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_ENDPOINT') ??
403
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT') ??
404
+ 'http://localhost:4317',
405
+ timeout: timeoutExporter,
406
+ temporality_preference: temporalityPreference,
407
+ default_histogram_aggregation: defaultHistogramAggregation,
408
+ ...(tls !== undefined && { tls }),
409
+ ...(compression !== undefined && { compression }),
410
+ ...(headersList !== undefined && { headers_list: headersList }),
411
+ };
412
+ readerPeriodicInfo.exporter = { otlp_grpc: otlpGrpc };
439
413
  }
440
414
  else {
441
- if (readerPeriodicInfo.exporter.otlp_http == null) {
442
- readerPeriodicInfo.exporter.otlp_http = {};
443
- }
444
- const endpoint = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_ENDPOINT') ??
445
- ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')
446
- ? `${(0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')}/v1/metrics`
447
- : 'http://localhost:4318/v1/metrics');
448
- if (endpoint) {
449
- readerPeriodicInfo.exporter.otlp_http.endpoint = endpoint;
450
- }
451
415
  const tls = (0, utils_1.getHttpTlsConfig)(certificateFile, clientKeyFile, clientCertificateFile);
452
- if (tls) {
453
- readerPeriodicInfo.exporter.otlp_http.tls = tls;
454
- }
455
- if (compression) {
456
- readerPeriodicInfo.exporter.otlp_http.compression = compression;
457
- }
458
- if (timeoutExporter) {
459
- readerPeriodicInfo.exporter.otlp_http.timeout = timeoutExporter;
460
- }
461
- if (headersList) {
462
- readerPeriodicInfo.exporter.otlp_http.headers_list = headersList;
463
- }
464
- if (temporalityPreference) {
465
- switch (temporalityPreference) {
466
- case 'cumulative':
467
- readerPeriodicInfo.exporter.otlp_http.temporality_preference =
468
- meterProviderModel_1.ExporterTemporalityPreference.Cumulative;
469
- break;
470
- case 'delta':
471
- readerPeriodicInfo.exporter.otlp_http.temporality_preference =
472
- meterProviderModel_1.ExporterTemporalityPreference.Delta;
473
- break;
474
- case 'low_memory':
475
- readerPeriodicInfo.exporter.otlp_http.temporality_preference =
476
- meterProviderModel_1.ExporterTemporalityPreference.LowMemory;
477
- break;
478
- default:
479
- readerPeriodicInfo.exporter.otlp_http.temporality_preference =
480
- meterProviderModel_1.ExporterTemporalityPreference.Cumulative;
481
- break;
482
- }
483
- }
484
- if (defaultHistogramAggregation) {
485
- switch (defaultHistogramAggregation) {
486
- case 'explicit_bucket_histogram':
487
- readerPeriodicInfo.exporter.otlp_http.default_histogram_aggregation =
488
- meterProviderModel_1.ExporterDefaultHistogramAggregation.ExplicitBucketHistogram;
489
- break;
490
- case 'base2_exponential_bucket_histogram':
491
- readerPeriodicInfo.exporter.otlp_http.default_histogram_aggregation =
492
- meterProviderModel_1.ExporterDefaultHistogramAggregation.Base2ExponentialBucketHistogram;
493
- break;
494
- default:
495
- readerPeriodicInfo.exporter.otlp_http.default_histogram_aggregation =
496
- meterProviderModel_1.ExporterDefaultHistogramAggregation.ExplicitBucketHistogram;
497
- break;
498
- }
499
- }
500
- if (protocol === 'http/json') {
501
- readerPeriodicInfo.exporter.otlp_http.encoding =
502
- commonModel_1.OtlpHttpEncoding.JSON;
503
- }
504
- else if (protocol === 'http/protobuf') {
505
- readerPeriodicInfo.exporter.otlp_http.encoding =
506
- commonModel_1.OtlpHttpEncoding.Protobuf;
507
- }
416
+ const encoding = protocol === 'http/json'
417
+ ? 'json'
418
+ : protocol === 'http/protobuf'
419
+ ? 'protobuf'
420
+ : undefined;
421
+ const otlpHttp = {
422
+ endpoint: (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_ENDPOINT') ??
423
+ ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')
424
+ ? `${(0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')}/v1/metrics`
425
+ : 'http://localhost:4318/v1/metrics'),
426
+ timeout: timeoutExporter,
427
+ temporality_preference: temporalityPreference,
428
+ default_histogram_aggregation: defaultHistogramAggregation,
429
+ ...(tls !== undefined && { tls }),
430
+ ...(compression !== undefined && { compression }),
431
+ ...(headersList !== undefined && { headers_list: headersList }),
432
+ ...(encoding !== undefined && { encoding }),
433
+ };
434
+ readerPeriodicInfo.exporter = { otlp_http: otlpHttp };
508
435
  }
509
436
  }
510
437
  config.meter_provider.readers.push({ periodic: readerPeriodicInfo });
511
438
  }
512
- const exemplarFilter = (0, core_1.getStringFromEnv)('OTEL_METRICS_EXEMPLAR_FILTER') ?? 'trace_based';
513
- if (exemplarFilter) {
514
- switch (exemplarFilter) {
515
- case 'trace_based':
516
- config.meter_provider.exemplar_filter = meterProviderModel_1.ExemplarFilter.TraceBased;
517
- break;
518
- case 'always_on':
519
- config.meter_provider.exemplar_filter = meterProviderModel_1.ExemplarFilter.AlwaysOn;
520
- break;
521
- case 'always_off':
522
- config.meter_provider.exemplar_filter = meterProviderModel_1.ExemplarFilter.AlwaysOff;
523
- break;
524
- default:
525
- config.meter_provider.exemplar_filter = meterProviderModel_1.ExemplarFilter.TraceBased;
526
- break;
527
- }
528
- }
439
+ const rawExemplarFilter = (0, core_1.getStringFromEnv)('OTEL_METRICS_EXEMPLAR_FILTER') ?? 'trace_based';
440
+ config.meter_provider.exemplar_filter =
441
+ rawExemplarFilter === 'default'
442
+ ? 'trace_based'
443
+ : rawExemplarFilter;
529
444
  }
530
445
  exports.setMeterProvider = setMeterProvider;
531
446
  function setLoggerProvider(config) {
@@ -537,7 +452,7 @@ function setLoggerProvider(config) {
537
452
  api_1.diag.info(`OTEL_LOGS_EXPORTER contains "none". Logger provider will not be initialized.`);
538
453
  return;
539
454
  }
540
- config.logger_provider = (0, loggerProviderModel_1.initializeDefaultLoggerProviderConfiguration)();
455
+ config.logger_provider = (0, utils_1.initializeDefaultLoggerProviderConfiguration)();
541
456
  const attributeValueLengthLimit = (0, core_1.getNumberFromEnv)('OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT');
542
457
  const attributeCountLimit = (0, core_1.getNumberFromEnv)('OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT');
543
458
  if (attributeValueLengthLimit || attributeCountLimit) {
@@ -550,33 +465,26 @@ function setLoggerProvider(config) {
550
465
  attributeCountLimit;
551
466
  }
552
467
  }
553
- const batch = { exporter: {} };
554
- const scheduleDelay = (0, core_1.getNumberFromEnv)('OTEL_BLRP_SCHEDULE_DELAY') ?? 1000;
555
- if (scheduleDelay) {
556
- batch.schedule_delay = scheduleDelay;
557
- }
558
- const exportTimeout = (0, core_1.getNumberFromEnv)('OTEL_BLRP_EXPORT_TIMEOUT') ?? 30000;
559
- if (exportTimeout) {
560
- batch.export_timeout = exportTimeout;
561
- }
562
- const maxQueueSize = (0, core_1.getNumberFromEnv)('OTEL_BLRP_MAX_QUEUE_SIZE') ?? 2048;
563
- if (maxQueueSize) {
564
- batch.max_queue_size = maxQueueSize;
565
- }
566
- const maxExportBatchSize = (0, core_1.getNumberFromEnv)('OTEL_BLRP_MAX_EXPORT_BATCH_SIZE') ?? 512;
567
- if (maxExportBatchSize) {
568
- batch.max_export_batch_size = maxExportBatchSize;
569
- }
468
+ const batch = {
469
+ exporter: {},
470
+ schedule_delay: (0, core_1.getNumberFromEnv)('OTEL_BLRP_SCHEDULE_DELAY') ?? 1000,
471
+ export_timeout: (0, core_1.getNumberFromEnv)('OTEL_BLRP_EXPORT_TIMEOUT') ?? 30000,
472
+ max_queue_size: (0, core_1.getNumberFromEnv)('OTEL_BLRP_MAX_QUEUE_SIZE') ?? 2048,
473
+ max_export_batch_size: (0, core_1.getNumberFromEnv)('OTEL_BLRP_MAX_EXPORT_BATCH_SIZE') ?? 512,
474
+ };
570
475
  for (let i = 0; i < exportersType.length; i++) {
571
476
  const exporterType = exportersType[i];
572
- const batchInfo = { ...batch };
477
+ const batchInfo = {
478
+ ...batch,
479
+ exporter: {},
480
+ };
573
481
  if (exporterType === 'console') {
574
- config.logger_provider.processors.push({
482
+ const processor = {
575
483
  simple: { exporter: { console: {} } },
576
- });
484
+ };
485
+ config.logger_provider.processors.push(processor);
577
486
  }
578
487
  else {
579
- // 'otlp' and default
580
488
  const protocol = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_PROTOCOL') ??
581
489
  (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_PROTOCOL') ??
582
490
  'http/protobuf';
@@ -594,60 +502,40 @@ function setLoggerProvider(config) {
594
502
  const headersList = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_HEADERS') ??
595
503
  (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_HEADERS');
596
504
  if (protocol === 'grpc') {
597
- delete batchInfo.exporter.otlp_http;
598
- batchInfo.exporter.otlp_grpc = {};
599
- const endpoint = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_ENDPOINT') ??
600
- (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT') ??
601
- 'http://localhost:4317';
602
- if (endpoint) {
603
- batchInfo.exporter.otlp_grpc.endpoint = endpoint;
604
- }
605
505
  const tls = (0, utils_1.getGrpcTlsConfig)(certificateFile, clientKeyFile, clientCertificateFile);
606
- if (tls) {
607
- batchInfo.exporter.otlp_grpc.tls = tls;
608
- }
609
- if (compression) {
610
- batchInfo.exporter.otlp_grpc.compression = compression;
611
- }
612
- if (timeout) {
613
- batchInfo.exporter.otlp_grpc.timeout = timeout;
614
- }
615
- if (headersList) {
616
- batchInfo.exporter.otlp_grpc.headers_list = headersList;
617
- }
506
+ const otlpGrpc = {
507
+ endpoint: (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_ENDPOINT') ??
508
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT') ??
509
+ 'http://localhost:4317',
510
+ timeout,
511
+ ...(tls !== undefined && { tls }),
512
+ ...(compression !== undefined && { compression }),
513
+ ...(headersList !== undefined && { headers_list: headersList }),
514
+ };
515
+ batchInfo.exporter = { otlp_grpc: otlpGrpc };
618
516
  }
619
517
  else {
620
- if (batchInfo.exporter.otlp_http == null) {
621
- batchInfo.exporter.otlp_http = {};
622
- }
623
- const endpoint = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_ENDPOINT') ??
624
- ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')
625
- ? `${(0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')}/v1/logs`
626
- : 'http://localhost:4318/v1/logs');
627
- if (endpoint) {
628
- batchInfo.exporter.otlp_http.endpoint = endpoint;
629
- }
630
518
  const tls = (0, utils_1.getHttpTlsConfig)(certificateFile, clientKeyFile, clientCertificateFile);
631
- if (tls) {
632
- batchInfo.exporter.otlp_http.tls = tls;
633
- }
634
- if (compression) {
635
- batchInfo.exporter.otlp_http.compression = compression;
636
- }
637
- if (timeout) {
638
- batchInfo.exporter.otlp_http.timeout = timeout;
639
- }
640
- if (headersList) {
641
- batchInfo.exporter.otlp_http.headers_list = headersList;
642
- }
643
- if (protocol === 'http/json') {
644
- batchInfo.exporter.otlp_http.encoding = commonModel_1.OtlpHttpEncoding.JSON;
645
- }
646
- else if (protocol === 'http/protobuf') {
647
- batchInfo.exporter.otlp_http.encoding = commonModel_1.OtlpHttpEncoding.Protobuf;
648
- }
519
+ const encoding = protocol === 'http/json'
520
+ ? 'json'
521
+ : protocol === 'http/protobuf'
522
+ ? 'protobuf'
523
+ : undefined;
524
+ const otlpHttp = {
525
+ endpoint: (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_ENDPOINT') ??
526
+ ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')
527
+ ? `${(0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')}/v1/logs`
528
+ : 'http://localhost:4318/v1/logs'),
529
+ timeout,
530
+ ...(tls !== undefined && { tls }),
531
+ ...(compression !== undefined && { compression }),
532
+ ...(headersList !== undefined && { headers_list: headersList }),
533
+ ...(encoding !== undefined && { encoding }),
534
+ };
535
+ batchInfo.exporter = { otlp_http: otlpHttp };
649
536
  }
650
- config.logger_provider.processors.push({ batch: batchInfo });
537
+ const processor = { batch: batchInfo };
538
+ config.logger_provider.processors.push(processor);
651
539
  }
652
540
  }
653
541
  }