@opentelemetry/configuration 0.209.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 (42) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +35 -0
  3. package/build/src/ConfigFactory.d.ts +3 -0
  4. package/build/src/ConfigFactory.js +28 -0
  5. package/build/src/ConfigFactory.js.map +1 -0
  6. package/build/src/EnvironmentConfigFactory.d.ts +17 -0
  7. package/build/src/EnvironmentConfigFactory.js +639 -0
  8. package/build/src/EnvironmentConfigFactory.js.map +1 -0
  9. package/build/src/FileConfigFactory.d.ts +21 -0
  10. package/build/src/FileConfigFactory.js +909 -0
  11. package/build/src/FileConfigFactory.js.map +1 -0
  12. package/build/src/IConfigFactory.d.ts +10 -0
  13. package/build/src/IConfigFactory.js +18 -0
  14. package/build/src/IConfigFactory.js.map +1 -0
  15. package/build/src/index.d.ts +7 -0
  16. package/build/src/index.js +21 -0
  17. package/build/src/index.js.map +1 -0
  18. package/build/src/models/commonModel.d.ts +145 -0
  19. package/build/src/models/commonModel.js +24 -0
  20. package/build/src/models/commonModel.js.map +1 -0
  21. package/build/src/models/configModel.d.ts +82 -0
  22. package/build/src/models/configModel.js +36 -0
  23. package/build/src/models/configModel.js.map +1 -0
  24. package/build/src/models/loggerProviderModel.d.ts +124 -0
  25. package/build/src/models/loggerProviderModel.js +28 -0
  26. package/build/src/models/loggerProviderModel.js.map +1 -0
  27. package/build/src/models/meterProviderModel.d.ts +470 -0
  28. package/build/src/models/meterProviderModel.js +53 -0
  29. package/build/src/models/meterProviderModel.js.map +1 -0
  30. package/build/src/models/resourceModel.d.ts +63 -0
  31. package/build/src/models/resourceModel.js +18 -0
  32. package/build/src/models/resourceModel.js.map +1 -0
  33. package/build/src/models/tracerProviderModel.d.ts +177 -0
  34. package/build/src/models/tracerProviderModel.js +41 -0
  35. package/build/src/models/tracerProviderModel.js.map +1 -0
  36. package/build/src/utils.d.ts +66 -0
  37. package/build/src/utils.js +174 -0
  38. package/build/src/utils.js.map +1 -0
  39. package/build/src/version.d.ts +2 -0
  40. package/build/src/version.js +21 -0
  41. package/build/src/version.js.map +1 -0
  42. package/package.json +60 -0
@@ -0,0 +1,639 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.setLoggerProvider = exports.setMeterProvider = exports.setTracerProvider = exports.setPropagators = exports.setAttributeLimits = exports.setResources = exports.EnvironmentConfigFactory = void 0;
19
+ const configModel_1 = require("./models/configModel");
20
+ const core_1 = require("@opentelemetry/core");
21
+ const meterProviderModel_1 = require("./models/meterProviderModel");
22
+ const commonModel_1 = require("./models/commonModel");
23
+ const api_1 = require("@opentelemetry/api");
24
+ const tracerProviderModel_1 = require("./models/tracerProviderModel");
25
+ const loggerProviderModel_1 = require("./models/loggerProviderModel");
26
+ /**
27
+ * EnvironmentConfigProvider provides a configuration based on environment variables.
28
+ */
29
+ class EnvironmentConfigFactory {
30
+ _config;
31
+ constructor() {
32
+ this._config = (0, configModel_1.initializeDefaultConfiguration)();
33
+ this._config.disabled = (0, core_1.getBooleanFromEnv)('OTEL_SDK_DISABLED');
34
+ const logLevel = (0, core_1.diagLogLevelFromString)((0, core_1.getStringFromEnv)('OTEL_LOG_LEVEL'));
35
+ if (logLevel) {
36
+ this._config.log_level = logLevel;
37
+ }
38
+ const nodeResourceDetectors = (0, core_1.getStringListFromEnv)('OTEL_NODE_RESOURCE_DETECTORS');
39
+ if (nodeResourceDetectors) {
40
+ this._config.node_resource_detectors = nodeResourceDetectors;
41
+ }
42
+ setResources(this._config);
43
+ setAttributeLimits(this._config);
44
+ setPropagators(this._config);
45
+ setTracerProvider(this._config);
46
+ setMeterProvider(this._config);
47
+ setLoggerProvider(this._config);
48
+ }
49
+ getConfigModel() {
50
+ return this._config;
51
+ }
52
+ }
53
+ exports.EnvironmentConfigFactory = EnvironmentConfigFactory;
54
+ function setResources(config) {
55
+ if (config.resource == null) {
56
+ config.resource = {};
57
+ }
58
+ const resourceAttrList = (0, core_1.getStringFromEnv)('OTEL_RESOURCE_ATTRIBUTES');
59
+ const list = (0, core_1.getStringListFromEnv)('OTEL_RESOURCE_ATTRIBUTES');
60
+ const serviceName = (0, core_1.getStringFromEnv)('OTEL_SERVICE_NAME');
61
+ if (serviceName) {
62
+ config.resource.attributes = [
63
+ {
64
+ name: 'service.name',
65
+ value: serviceName,
66
+ type: 'string',
67
+ },
68
+ ];
69
+ }
70
+ if (list && list.length > 0) {
71
+ config.resource.attributes_list = resourceAttrList;
72
+ if (config.resource.attributes == null) {
73
+ config.resource.attributes = [];
74
+ }
75
+ for (let i = 0; i < list.length; i++) {
76
+ const element = list[i].split('=');
77
+ if (element[0] !== 'service.name' ||
78
+ (element[0] === 'service.name' && serviceName === undefined)) {
79
+ config.resource.attributes.push({
80
+ name: element[0],
81
+ value: element[1],
82
+ type: 'string',
83
+ });
84
+ }
85
+ }
86
+ }
87
+ }
88
+ exports.setResources = setResources;
89
+ function setAttributeLimits(config) {
90
+ const attributeValueLengthLimit = (0, core_1.getNumberFromEnv)('OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT');
91
+ if (attributeValueLengthLimit && attributeValueLengthLimit > 0) {
92
+ if (config.attribute_limits == null) {
93
+ config.attribute_limits = { attribute_count_limit: 128 };
94
+ }
95
+ config.attribute_limits.attribute_value_length_limit =
96
+ attributeValueLengthLimit;
97
+ }
98
+ const attributeCountLimit = (0, core_1.getNumberFromEnv)('OTEL_ATTRIBUTE_COUNT_LIMIT');
99
+ if (attributeCountLimit) {
100
+ if (config.attribute_limits == null) {
101
+ config.attribute_limits = { attribute_count_limit: attributeCountLimit };
102
+ }
103
+ else {
104
+ config.attribute_limits.attribute_count_limit = attributeCountLimit;
105
+ }
106
+ }
107
+ }
108
+ exports.setAttributeLimits = setAttributeLimits;
109
+ function setPropagators(config) {
110
+ if (config.propagator == null) {
111
+ config.propagator = {};
112
+ }
113
+ const composite = (0, core_1.getStringListFromEnv)('OTEL_PROPAGATORS');
114
+ if (composite && composite.length > 0) {
115
+ config.propagator.composite = [];
116
+ for (let i = 0; i < composite.length; i++) {
117
+ config.propagator.composite.push({ [composite[i]]: null });
118
+ }
119
+ }
120
+ const compositeList = (0, core_1.getStringFromEnv)('OTEL_PROPAGATORS');
121
+ if (compositeList) {
122
+ config.propagator.composite_list = compositeList;
123
+ }
124
+ }
125
+ exports.setPropagators = setPropagators;
126
+ function setTracerProvider(config) {
127
+ const exportersType = Array.from(new Set((0, core_1.getStringListFromEnv)('OTEL_TRACES_EXPORTER')));
128
+ if (exportersType.length === 0) {
129
+ return;
130
+ }
131
+ if (exportersType.includes('none')) {
132
+ api_1.diag.info(`OTEL_TRACES_EXPORTER contains "none". Tracer provider will not be initialized.`);
133
+ return;
134
+ }
135
+ config.tracer_provider = (0, tracerProviderModel_1.initializeDefaultTracerProviderConfiguration)();
136
+ if (config.tracer_provider.limits == null) {
137
+ config.tracer_provider.limits = {};
138
+ }
139
+ const attributeValueLengthLimit = (0, core_1.getNumberFromEnv)('OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT');
140
+ if (attributeValueLengthLimit) {
141
+ config.tracer_provider.limits.attribute_value_length_limit =
142
+ attributeValueLengthLimit;
143
+ }
144
+ const attributeCountLimit = (0, core_1.getNumberFromEnv)('OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT');
145
+ if (attributeCountLimit) {
146
+ config.tracer_provider.limits.attribute_count_limit = attributeCountLimit;
147
+ }
148
+ const eventCountLimit = (0, core_1.getNumberFromEnv)('OTEL_SPAN_EVENT_COUNT_LIMIT');
149
+ if (eventCountLimit) {
150
+ config.tracer_provider.limits.event_count_limit = eventCountLimit;
151
+ }
152
+ const linkCountLimit = (0, core_1.getNumberFromEnv)('OTEL_SPAN_LINK_COUNT_LIMIT');
153
+ if (linkCountLimit) {
154
+ config.tracer_provider.limits.link_count_limit = linkCountLimit;
155
+ }
156
+ const eventAttributeCountLimit = (0, core_1.getNumberFromEnv)('OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT');
157
+ if (eventAttributeCountLimit) {
158
+ config.tracer_provider.limits.event_attribute_count_limit =
159
+ eventAttributeCountLimit;
160
+ }
161
+ const linkAttributeCountLimit = (0, core_1.getNumberFromEnv)('OTEL_LINK_ATTRIBUTE_COUNT_LIMIT');
162
+ if (linkAttributeCountLimit) {
163
+ config.tracer_provider.limits.link_attribute_count_limit =
164
+ linkAttributeCountLimit;
165
+ }
166
+ const batch = { exporter: {} };
167
+ const scheduleDelay = (0, core_1.getNumberFromEnv)('OTEL_BSP_SCHEDULE_DELAY') ?? 5000;
168
+ if (scheduleDelay) {
169
+ batch.schedule_delay = scheduleDelay;
170
+ }
171
+ const exportTimeout = (0, core_1.getNumberFromEnv)('OTEL_BSP_EXPORT_TIMEOUT') ?? 30000;
172
+ if (exportTimeout) {
173
+ batch.export_timeout = exportTimeout;
174
+ }
175
+ const maxQueueSize = (0, core_1.getNumberFromEnv)('OTEL_BSP_MAX_QUEUE_SIZE') ?? 2048;
176
+ if (maxQueueSize) {
177
+ batch.max_queue_size = maxQueueSize;
178
+ }
179
+ const maxExportBatchSize = (0, core_1.getNumberFromEnv)('OTEL_BSP_MAX_EXPORT_BATCH_SIZE') ?? 512;
180
+ if (maxExportBatchSize) {
181
+ batch.max_export_batch_size = maxExportBatchSize;
182
+ }
183
+ for (let i = 0; i < exportersType.length; i++) {
184
+ const exporterType = exportersType[i];
185
+ const batchInfo = { ...batch };
186
+ if (exporterType === 'console') {
187
+ config.tracer_provider.processors.push({
188
+ simple: { exporter: { console: {} } },
189
+ });
190
+ }
191
+ else if (exporterType === 'zipkin') {
192
+ batchInfo.exporter = {
193
+ zipkin: {
194
+ endpoint: (0, core_1.getStringFromEnv)('OTEL_EXPORTER_ZIPKIN_ENDPOINT') ??
195
+ 'http://localhost:9411/api/v2/spans',
196
+ timeout: (0, core_1.getNumberFromEnv)('OTEL_EXPORTER_ZIPKIN_TIMEOUT') ?? 10000,
197
+ },
198
+ };
199
+ config.tracer_provider.processors.push({ batch: batchInfo });
200
+ }
201
+ else {
202
+ // 'otlp' and default
203
+ const protocol = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_PROTOCOL') ??
204
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_PROTOCOL') ??
205
+ 'http/protobuf';
206
+ const certificateFile = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE') ??
207
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_CERTIFICATE');
208
+ const clientKeyFile = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY') ??
209
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_CLIENT_KEY');
210
+ const clientCertificateFile = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE') ??
211
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE');
212
+ const compression = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_COMPRESSION') ??
213
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_COMPRESSION');
214
+ const timeout = (0, core_1.getNumberFromEnv)('OTEL_EXPORTER_OTLP_TRACES_TIMEOUT') ??
215
+ (0, core_1.getNumberFromEnv)('OTEL_EXPORTER_OTLP_TIMEOUT') ??
216
+ 10000;
217
+ const headersList = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_HEADERS') ??
218
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_HEADERS');
219
+ if (protocol === 'grpc') {
220
+ delete batchInfo.exporter.otlp_http;
221
+ batchInfo.exporter.otlp_grpc = {};
222
+ const endpoint = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT') ??
223
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT') ??
224
+ 'http://localhost:4317';
225
+ if (endpoint) {
226
+ batchInfo.exporter.otlp_grpc.endpoint = endpoint;
227
+ }
228
+ if (certificateFile) {
229
+ batchInfo.exporter.otlp_grpc.certificate_file = certificateFile;
230
+ }
231
+ if (clientKeyFile) {
232
+ batchInfo.exporter.otlp_grpc.client_key_file = clientKeyFile;
233
+ }
234
+ if (clientCertificateFile) {
235
+ batchInfo.exporter.otlp_grpc.client_certificate_file =
236
+ clientCertificateFile;
237
+ }
238
+ if (compression) {
239
+ batchInfo.exporter.otlp_grpc.compression = compression;
240
+ }
241
+ if (timeout) {
242
+ batchInfo.exporter.otlp_grpc.timeout = timeout;
243
+ }
244
+ if (headersList) {
245
+ batchInfo.exporter.otlp_grpc.headers_list = headersList;
246
+ }
247
+ }
248
+ else {
249
+ if (batchInfo.exporter.otlp_http == null) {
250
+ batchInfo.exporter.otlp_http = {};
251
+ }
252
+ const endpoint = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT') ??
253
+ ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')
254
+ ? `${(0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')}/v1/traces`
255
+ : 'http://localhost:4318/v1/traces');
256
+ if (endpoint) {
257
+ batchInfo.exporter.otlp_http.endpoint = endpoint;
258
+ }
259
+ if (certificateFile) {
260
+ batchInfo.exporter.otlp_http.certificate_file = certificateFile;
261
+ }
262
+ if (clientKeyFile) {
263
+ batchInfo.exporter.otlp_http.client_key_file = clientKeyFile;
264
+ }
265
+ if (clientCertificateFile) {
266
+ batchInfo.exporter.otlp_http.client_certificate_file =
267
+ clientCertificateFile;
268
+ }
269
+ if (compression) {
270
+ batchInfo.exporter.otlp_http.compression = compression;
271
+ }
272
+ if (timeout) {
273
+ batchInfo.exporter.otlp_http.timeout = timeout;
274
+ }
275
+ if (headersList) {
276
+ batchInfo.exporter.otlp_http.headers_list = headersList;
277
+ }
278
+ if (protocol === 'http/json') {
279
+ batchInfo.exporter.otlp_http.encoding = commonModel_1.OtlpHttpEncoding.JSON;
280
+ }
281
+ else if (protocol === 'http/protobuf') {
282
+ batchInfo.exporter.otlp_http.encoding = commonModel_1.OtlpHttpEncoding.Protobuf;
283
+ }
284
+ }
285
+ config.tracer_provider.processors.push({ batch: batchInfo });
286
+ }
287
+ }
288
+ }
289
+ exports.setTracerProvider = setTracerProvider;
290
+ function setMeterProvider(config) {
291
+ const exportersType = Array.from(new Set((0, core_1.getStringListFromEnv)('OTEL_METRICS_EXPORTER')));
292
+ if (exportersType.length === 0) {
293
+ return;
294
+ }
295
+ if (exportersType.includes('none')) {
296
+ api_1.diag.info(`OTEL_METRICS_EXPORTER contains "none". Meter provider will not be initialized.`);
297
+ return;
298
+ }
299
+ config.meter_provider = (0, meterProviderModel_1.initializeDefaultMeterProviderConfiguration)();
300
+ const readerPeriodic = { exporter: {} };
301
+ const interval = (0, core_1.getNumberFromEnv)('OTEL_METRIC_EXPORT_INTERVAL') ?? 60000;
302
+ if (interval) {
303
+ readerPeriodic.interval = interval;
304
+ }
305
+ for (let i = 0; i < exportersType.length; i++) {
306
+ const exporterType = exportersType[i];
307
+ const readerPeriodicInfo = { ...readerPeriodic };
308
+ const timeout = (0, core_1.getNumberFromEnv)('OTEL_METRIC_EXPORT_TIMEOUT') ?? 30000;
309
+ if (timeout) {
310
+ readerPeriodicInfo.timeout = timeout;
311
+ }
312
+ // TODO: add prometheus exporter support
313
+ if (exporterType === 'console') {
314
+ readerPeriodicInfo.exporter = { console: {} };
315
+ }
316
+ else {
317
+ // 'otlp' and default
318
+ const protocol = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_PROTOCOL') ??
319
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_PROTOCOL') ??
320
+ 'http/protobuf';
321
+ const certificateFile = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE') ??
322
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_CERTIFICATE');
323
+ const clientKeyFile = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY') ??
324
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_CLIENT_KEY');
325
+ const clientCertificateFile = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE') ??
326
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE');
327
+ const compression = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_COMPRESSION') ??
328
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_COMPRESSION');
329
+ const timeoutExporter = (0, core_1.getNumberFromEnv)('OTEL_EXPORTER_OTLP_METRICS_TIMEOUT') ??
330
+ (0, core_1.getNumberFromEnv)('OTEL_EXPORTER_OTLP_TIMEOUT') ??
331
+ 10000;
332
+ const headersList = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_HEADERS') ??
333
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_HEADERS');
334
+ const temporalityPreference = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE') ??
335
+ 'cumulative';
336
+ const defaultHistogramAggregation = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION') ?? 'explicit_bucket_histogram';
337
+ if (protocol === 'grpc') {
338
+ delete readerPeriodicInfo.exporter.otlp_http;
339
+ readerPeriodicInfo.exporter.otlp_grpc = {};
340
+ const endpoint = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_ENDPOINT') ??
341
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT') ??
342
+ 'http://localhost:4317';
343
+ if (endpoint) {
344
+ readerPeriodicInfo.exporter.otlp_grpc.endpoint = endpoint;
345
+ }
346
+ if (certificateFile) {
347
+ readerPeriodicInfo.exporter.otlp_grpc.certificate_file =
348
+ certificateFile;
349
+ }
350
+ if (clientKeyFile) {
351
+ readerPeriodicInfo.exporter.otlp_grpc.client_key_file = clientKeyFile;
352
+ }
353
+ if (clientCertificateFile) {
354
+ readerPeriodicInfo.exporter.otlp_grpc.client_certificate_file =
355
+ clientCertificateFile;
356
+ }
357
+ if (compression) {
358
+ readerPeriodicInfo.exporter.otlp_grpc.compression = compression;
359
+ }
360
+ if (timeoutExporter) {
361
+ readerPeriodicInfo.exporter.otlp_grpc.timeout = timeoutExporter;
362
+ }
363
+ if (headersList) {
364
+ readerPeriodicInfo.exporter.otlp_grpc.headers_list = headersList;
365
+ }
366
+ if (temporalityPreference) {
367
+ switch (temporalityPreference) {
368
+ case 'cumulative':
369
+ readerPeriodicInfo.exporter.otlp_grpc.temporality_preference =
370
+ meterProviderModel_1.ExporterTemporalityPreference.Cumulative;
371
+ break;
372
+ case 'delta':
373
+ readerPeriodicInfo.exporter.otlp_grpc.temporality_preference =
374
+ meterProviderModel_1.ExporterTemporalityPreference.Delta;
375
+ break;
376
+ case 'low_memory':
377
+ readerPeriodicInfo.exporter.otlp_grpc.temporality_preference =
378
+ meterProviderModel_1.ExporterTemporalityPreference.LowMemory;
379
+ break;
380
+ default:
381
+ readerPeriodicInfo.exporter.otlp_grpc.temporality_preference =
382
+ meterProviderModel_1.ExporterTemporalityPreference.Cumulative;
383
+ break;
384
+ }
385
+ }
386
+ if (defaultHistogramAggregation) {
387
+ switch (defaultHistogramAggregation) {
388
+ case 'explicit_bucket_histogram':
389
+ readerPeriodicInfo.exporter.otlp_grpc.default_histogram_aggregation =
390
+ meterProviderModel_1.ExporterDefaultHistogramAggregation.ExplicitBucketHistogram;
391
+ break;
392
+ case 'base2_exponential_bucket_histogram':
393
+ readerPeriodicInfo.exporter.otlp_grpc.default_histogram_aggregation =
394
+ meterProviderModel_1.ExporterDefaultHistogramAggregation.Base2ExponentialBucketHistogram;
395
+ break;
396
+ default:
397
+ readerPeriodicInfo.exporter.otlp_grpc.default_histogram_aggregation =
398
+ meterProviderModel_1.ExporterDefaultHistogramAggregation.ExplicitBucketHistogram;
399
+ break;
400
+ }
401
+ }
402
+ }
403
+ else {
404
+ if (readerPeriodicInfo.exporter.otlp_http == null) {
405
+ readerPeriodicInfo.exporter.otlp_http = {};
406
+ }
407
+ const endpoint = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_METRICS_ENDPOINT') ??
408
+ ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')
409
+ ? `${(0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')}/v1/metrics`
410
+ : 'http://localhost:4318/v1/metrics');
411
+ if (endpoint) {
412
+ readerPeriodicInfo.exporter.otlp_http.endpoint = endpoint;
413
+ }
414
+ if (certificateFile) {
415
+ readerPeriodicInfo.exporter.otlp_http.certificate_file =
416
+ certificateFile;
417
+ }
418
+ if (clientKeyFile) {
419
+ readerPeriodicInfo.exporter.otlp_http.client_key_file = clientKeyFile;
420
+ }
421
+ if (clientCertificateFile) {
422
+ readerPeriodicInfo.exporter.otlp_http.client_certificate_file =
423
+ clientCertificateFile;
424
+ }
425
+ if (compression) {
426
+ readerPeriodicInfo.exporter.otlp_http.compression = compression;
427
+ }
428
+ if (timeoutExporter) {
429
+ readerPeriodicInfo.exporter.otlp_http.timeout = timeoutExporter;
430
+ }
431
+ if (headersList) {
432
+ readerPeriodicInfo.exporter.otlp_http.headers_list = headersList;
433
+ }
434
+ if (temporalityPreference) {
435
+ switch (temporalityPreference) {
436
+ case 'cumulative':
437
+ readerPeriodicInfo.exporter.otlp_http.temporality_preference =
438
+ meterProviderModel_1.ExporterTemporalityPreference.Cumulative;
439
+ break;
440
+ case 'delta':
441
+ readerPeriodicInfo.exporter.otlp_http.temporality_preference =
442
+ meterProviderModel_1.ExporterTemporalityPreference.Delta;
443
+ break;
444
+ case 'low_memory':
445
+ readerPeriodicInfo.exporter.otlp_http.temporality_preference =
446
+ meterProviderModel_1.ExporterTemporalityPreference.LowMemory;
447
+ break;
448
+ default:
449
+ readerPeriodicInfo.exporter.otlp_http.temporality_preference =
450
+ meterProviderModel_1.ExporterTemporalityPreference.Cumulative;
451
+ break;
452
+ }
453
+ }
454
+ if (defaultHistogramAggregation) {
455
+ switch (defaultHistogramAggregation) {
456
+ case 'explicit_bucket_histogram':
457
+ readerPeriodicInfo.exporter.otlp_http.default_histogram_aggregation =
458
+ meterProviderModel_1.ExporterDefaultHistogramAggregation.ExplicitBucketHistogram;
459
+ break;
460
+ case 'base2_exponential_bucket_histogram':
461
+ readerPeriodicInfo.exporter.otlp_http.default_histogram_aggregation =
462
+ meterProviderModel_1.ExporterDefaultHistogramAggregation.Base2ExponentialBucketHistogram;
463
+ break;
464
+ default:
465
+ readerPeriodicInfo.exporter.otlp_http.default_histogram_aggregation =
466
+ meterProviderModel_1.ExporterDefaultHistogramAggregation.ExplicitBucketHistogram;
467
+ break;
468
+ }
469
+ }
470
+ if (protocol === 'http/json') {
471
+ readerPeriodicInfo.exporter.otlp_http.encoding =
472
+ commonModel_1.OtlpHttpEncoding.JSON;
473
+ }
474
+ else if (protocol === 'http/protobuf') {
475
+ readerPeriodicInfo.exporter.otlp_http.encoding =
476
+ commonModel_1.OtlpHttpEncoding.Protobuf;
477
+ }
478
+ }
479
+ }
480
+ config.meter_provider.readers.push({ periodic: readerPeriodicInfo });
481
+ }
482
+ const exemplarFilter = (0, core_1.getStringFromEnv)('OTEL_METRICS_EXEMPLAR_FILTER') ?? 'trace_based';
483
+ if (exemplarFilter) {
484
+ switch (exemplarFilter) {
485
+ case 'trace_based':
486
+ config.meter_provider.exemplar_filter = meterProviderModel_1.ExemplarFilter.TraceBased;
487
+ break;
488
+ case 'always_on':
489
+ config.meter_provider.exemplar_filter = meterProviderModel_1.ExemplarFilter.AlwaysOn;
490
+ break;
491
+ case 'always_off':
492
+ config.meter_provider.exemplar_filter = meterProviderModel_1.ExemplarFilter.AlwaysOff;
493
+ break;
494
+ default:
495
+ config.meter_provider.exemplar_filter = meterProviderModel_1.ExemplarFilter.TraceBased;
496
+ break;
497
+ }
498
+ }
499
+ }
500
+ exports.setMeterProvider = setMeterProvider;
501
+ function setLoggerProvider(config) {
502
+ const exportersType = Array.from(new Set((0, core_1.getStringListFromEnv)('OTEL_LOGS_EXPORTER')));
503
+ if (exportersType.length === 0) {
504
+ return;
505
+ }
506
+ if (exportersType.includes('none')) {
507
+ api_1.diag.info(`OTEL_LOGS_EXPORTER contains "none". Logger provider will not be initialized.`);
508
+ return;
509
+ }
510
+ config.logger_provider = (0, loggerProviderModel_1.initializeDefaultLoggerProviderConfiguration)();
511
+ const attributeValueLengthLimit = (0, core_1.getNumberFromEnv)('OTEL_LOGRECORD_ATTRIBUTE_VALUE_LENGTH_LIMIT');
512
+ const attributeCountLimit = (0, core_1.getNumberFromEnv)('OTEL_LOGRECORD_ATTRIBUTE_COUNT_LIMIT');
513
+ if (attributeValueLengthLimit || attributeCountLimit) {
514
+ if (config.logger_provider.limits == null) {
515
+ config.logger_provider.limits = { attribute_count_limit: 128 };
516
+ }
517
+ if (attributeValueLengthLimit) {
518
+ config.logger_provider.limits.attribute_value_length_limit =
519
+ attributeValueLengthLimit;
520
+ }
521
+ if (attributeCountLimit) {
522
+ config.logger_provider.limits.attribute_count_limit = attributeCountLimit;
523
+ }
524
+ }
525
+ const batch = { exporter: {} };
526
+ const scheduleDelay = (0, core_1.getNumberFromEnv)('OTEL_BLRP_SCHEDULE_DELAY') ?? 1000;
527
+ if (scheduleDelay) {
528
+ batch.schedule_delay = scheduleDelay;
529
+ }
530
+ const exportTimeout = (0, core_1.getNumberFromEnv)('OTEL_BLRP_EXPORT_TIMEOUT') ?? 30000;
531
+ if (exportTimeout) {
532
+ batch.export_timeout = exportTimeout;
533
+ }
534
+ const maxQueueSize = (0, core_1.getNumberFromEnv)('OTEL_BLRP_MAX_QUEUE_SIZE') ?? 2048;
535
+ if (maxQueueSize) {
536
+ batch.max_queue_size = maxQueueSize;
537
+ }
538
+ const maxExportBatchSize = (0, core_1.getNumberFromEnv)('OTEL_BLRP_MAX_EXPORT_BATCH_SIZE') ?? 512;
539
+ if (maxExportBatchSize) {
540
+ batch.max_export_batch_size = maxExportBatchSize;
541
+ }
542
+ for (let i = 0; i < exportersType.length; i++) {
543
+ const exporterType = exportersType[i];
544
+ const batchInfo = { ...batch };
545
+ if (exporterType === 'console') {
546
+ config.logger_provider.processors.push({
547
+ simple: { exporter: { console: {} } },
548
+ });
549
+ }
550
+ else {
551
+ // 'otlp' and default
552
+ const protocol = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_PROTOCOL') ??
553
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_PROTOCOL') ??
554
+ 'http/protobuf';
555
+ const certificateFile = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_CERTIFICATE') ??
556
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_CERTIFICATE');
557
+ const clientKeyFile = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_CLIENT_KEY') ??
558
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_CLIENT_KEY');
559
+ const clientCertificateFile = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_CLIENT_CERTIFICATE') ??
560
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE');
561
+ const compression = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_COMPRESSION') ??
562
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_COMPRESSION');
563
+ const timeout = (0, core_1.getNumberFromEnv)('OTEL_EXPORTER_OTLP_LOGS_TIMEOUT') ??
564
+ (0, core_1.getNumberFromEnv)('OTEL_EXPORTER_OTLP_TIMEOUT') ??
565
+ 10000;
566
+ const headersList = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_HEADERS') ??
567
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_HEADERS');
568
+ if (protocol === 'grpc') {
569
+ delete batchInfo.exporter.otlp_http;
570
+ batchInfo.exporter.otlp_grpc = {};
571
+ const endpoint = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_ENDPOINT') ??
572
+ (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT') ??
573
+ 'http://localhost:4317';
574
+ if (endpoint) {
575
+ batchInfo.exporter.otlp_grpc.endpoint = endpoint;
576
+ }
577
+ if (certificateFile) {
578
+ batchInfo.exporter.otlp_grpc.certificate_file = certificateFile;
579
+ }
580
+ if (clientKeyFile) {
581
+ batchInfo.exporter.otlp_grpc.client_key_file = clientKeyFile;
582
+ }
583
+ if (clientCertificateFile) {
584
+ batchInfo.exporter.otlp_grpc.client_certificate_file =
585
+ clientCertificateFile;
586
+ }
587
+ if (compression) {
588
+ batchInfo.exporter.otlp_grpc.compression = compression;
589
+ }
590
+ if (timeout) {
591
+ batchInfo.exporter.otlp_grpc.timeout = timeout;
592
+ }
593
+ if (headersList) {
594
+ batchInfo.exporter.otlp_grpc.headers_list = headersList;
595
+ }
596
+ }
597
+ else {
598
+ if (batchInfo.exporter.otlp_http == null) {
599
+ batchInfo.exporter.otlp_http = {};
600
+ }
601
+ const endpoint = (0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_LOGS_ENDPOINT') ??
602
+ ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')
603
+ ? `${(0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_ENDPOINT')}/v1/logs`
604
+ : 'http://localhost:4318/v1/logs');
605
+ if (endpoint) {
606
+ batchInfo.exporter.otlp_http.endpoint = endpoint;
607
+ }
608
+ if (certificateFile) {
609
+ batchInfo.exporter.otlp_http.certificate_file = certificateFile;
610
+ }
611
+ if (clientKeyFile) {
612
+ batchInfo.exporter.otlp_http.client_key_file = clientKeyFile;
613
+ }
614
+ if (clientCertificateFile) {
615
+ batchInfo.exporter.otlp_http.client_certificate_file =
616
+ clientCertificateFile;
617
+ }
618
+ if (compression) {
619
+ batchInfo.exporter.otlp_http.compression = compression;
620
+ }
621
+ if (timeout) {
622
+ batchInfo.exporter.otlp_http.timeout = timeout;
623
+ }
624
+ if (headersList) {
625
+ batchInfo.exporter.otlp_http.headers_list = headersList;
626
+ }
627
+ if (protocol === 'http/json') {
628
+ batchInfo.exporter.otlp_http.encoding = commonModel_1.OtlpHttpEncoding.JSON;
629
+ }
630
+ else if (protocol === 'http/protobuf') {
631
+ batchInfo.exporter.otlp_http.encoding = commonModel_1.OtlpHttpEncoding.Protobuf;
632
+ }
633
+ }
634
+ config.logger_provider.processors.push({ batch: batchInfo });
635
+ }
636
+ }
637
+ }
638
+ exports.setLoggerProvider = setLoggerProvider;
639
+ //# sourceMappingURL=EnvironmentConfigFactory.js.map