@opentelemetry/sdk-node 0.221.0 → 0.222.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/build/src/create-from-config.d.ts +20 -2
- package/build/src/create-from-config.js +841 -12
- package/build/src/create-from-config.js.map +1 -1
- package/build/src/create-from-env.js +1 -0
- package/build/src/create-from-env.js.map +1 -1
- package/build/src/start.d.ts +0 -3
- package/build/src/start.js +14 -61
- package/build/src/start.js.map +1 -1
- package/build/src/types.d.ts +0 -1
- package/build/src/types.js.map +1 -1
- package/build/src/utils.d.ts +4 -47
- package/build/src/utils.js +1 -629
- 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 +31 -30
package/build/src/utils.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.getInstanceID = exports.getBatchLogRecordProcessorFromEnv = exports.getBatchLogRecordProcessorConfigFromEnv = exports.getLoggerProviderConfigFromEnv = exports.getOtlpMetricExporterFromEnv = exports.getPeriodicExportingMetricReaderFromEnv = exports.getNonNegativeNumberFromEnv = exports.getKeyListFromObjectArray = exports.setupPropagator = exports.setupContextManager = exports.getPropagatorFromEnv = exports.getSpanProcessorsFromEnv = exports.getOtlpProtocolFromEnv = exports.getResourceDetectorsFromEnv = void 0;
|
|
8
8
|
const api_1 = require("@opentelemetry/api");
|
|
9
9
|
const core_1 = require("@opentelemetry/core");
|
|
10
10
|
const exporter_trace_otlp_proto_1 = require("@opentelemetry/exporter-trace-otlp-proto");
|
|
@@ -16,43 +16,17 @@ const sdk_trace_1 = require("@opentelemetry/sdk-trace");
|
|
|
16
16
|
const propagator_b3_1 = require("@opentelemetry/propagator-b3");
|
|
17
17
|
const propagator_jaeger_1 = require("@opentelemetry/propagator-jaeger");
|
|
18
18
|
const context_async_hooks_1 = require("@opentelemetry/context-async-hooks");
|
|
19
|
-
const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
|
|
20
|
-
const otlp_grpc_exporter_base_1 = require("@opentelemetry/otlp-grpc-exporter-base");
|
|
21
|
-
const configuration_1 = require("@opentelemetry/configuration");
|
|
22
19
|
const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
|
|
23
20
|
const exporter_metrics_otlp_grpc_1 = require("@opentelemetry/exporter-metrics-otlp-grpc");
|
|
24
21
|
const exporter_metrics_otlp_http_1 = require("@opentelemetry/exporter-metrics-otlp-http");
|
|
25
|
-
const exporter_metrics_otlp_http_2 = require("@opentelemetry/exporter-metrics-otlp-http");
|
|
26
22
|
const exporter_metrics_otlp_proto_1 = require("@opentelemetry/exporter-metrics-otlp-proto");
|
|
27
23
|
const sdk_logs_1 = require("@opentelemetry/sdk-logs");
|
|
28
|
-
const fs = require("fs");
|
|
29
|
-
const util_1 = require("util");
|
|
30
24
|
const create_from_env_1 = require("./create-from-env");
|
|
31
25
|
const RESOURCE_DETECTOR_ENVIRONMENT = 'env';
|
|
32
26
|
const RESOURCE_DETECTOR_HOST = 'host';
|
|
33
27
|
const RESOURCE_DETECTOR_OS = 'os';
|
|
34
28
|
const RESOURCE_DETECTOR_PROCESS = 'process';
|
|
35
29
|
const RESOURCE_DETECTOR_SERVICE_INSTANCE_ID = 'serviceinstance';
|
|
36
|
-
function getResourceFromConfiguration(config) {
|
|
37
|
-
if (!config.resource) {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
const configAttrs = (0, configuration_1.mergeResourceAttributesConfig)(config.resource.attributes, config.resource.attributes_list);
|
|
41
|
-
if (!configAttrs) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
const attrs = {};
|
|
45
|
-
for (let i = 0; i < configAttrs.length; i++) {
|
|
46
|
-
const a = configAttrs[i];
|
|
47
|
-
if (a.value !== null) {
|
|
48
|
-
attrs[a.name] = a.value;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return (0, resources_1.resourceFromAttributes)(attrs, {
|
|
52
|
-
schemaUrl: config.resource.schema_url ?? undefined,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
exports.getResourceFromConfiguration = getResourceFromConfiguration;
|
|
56
30
|
function getResourceDetectorsFromEnv() {
|
|
57
31
|
// When updating this list, make sure to also update the section `resourceDetectors` on README.
|
|
58
32
|
const resourceDetectors = new Map([
|
|
@@ -78,24 +52,6 @@ function getResourceDetectorsFromEnv() {
|
|
|
78
52
|
});
|
|
79
53
|
}
|
|
80
54
|
exports.getResourceDetectorsFromEnv = getResourceDetectorsFromEnv;
|
|
81
|
-
function getResourceDetectorsFromConfiguration(config) {
|
|
82
|
-
const detectors = config.resource?.['detection/development']?.detectors ?? [];
|
|
83
|
-
return detectors.flatMap(detector => {
|
|
84
|
-
const result = [];
|
|
85
|
-
if (detector.host !== undefined)
|
|
86
|
-
result.push(resources_1.hostDetector);
|
|
87
|
-
if (detector.os !== undefined)
|
|
88
|
-
result.push(resources_1.osDetector);
|
|
89
|
-
if (detector.process !== undefined)
|
|
90
|
-
result.push(resources_1.processDetector);
|
|
91
|
-
if (detector.service !== undefined)
|
|
92
|
-
result.push(resources_1.serviceInstanceIdDetector);
|
|
93
|
-
if (detector.env !== undefined)
|
|
94
|
-
result.push(resources_1.envDetector);
|
|
95
|
-
return result;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
exports.getResourceDetectorsFromConfiguration = getResourceDetectorsFromConfiguration;
|
|
99
55
|
function getOtlpProtocolFromEnv() {
|
|
100
56
|
return ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_PROTOCOL') ??
|
|
101
57
|
(0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_PROTOCOL') ??
|
|
@@ -217,95 +173,6 @@ function getPropagatorFromEnv() {
|
|
|
217
173
|
}
|
|
218
174
|
}
|
|
219
175
|
exports.getPropagatorFromEnv = getPropagatorFromEnv;
|
|
220
|
-
/**
|
|
221
|
-
* Get a propagator as defined by configuration model from configuration
|
|
222
|
-
*/
|
|
223
|
-
function getPropagatorFromConfiguration(config) {
|
|
224
|
-
if (!config.propagator) {
|
|
225
|
-
return undefined;
|
|
226
|
-
}
|
|
227
|
-
const configComposite = (0, configuration_1.mergePropagatorCompositeConfig)(config.propagator.composite, config.propagator.composite_list);
|
|
228
|
-
if (!configComposite) {
|
|
229
|
-
return undefined;
|
|
230
|
-
}
|
|
231
|
-
// TextMapPropagator config items are objects with a single key (the name).
|
|
232
|
-
// Transform this into a more convenient `(name, value)` 2-tuple.
|
|
233
|
-
//
|
|
234
|
-
// As well, guard against two cases where the TypeScript type
|
|
235
|
-
// `TextMapPropagatorConfigModel` does not exactly represent the JSON schema:
|
|
236
|
-
// 1. `"minProperties": 1, "maxProperties": 1,`
|
|
237
|
-
// 2. The type allows keys with an `undefined` value, but the JSON schema
|
|
238
|
-
// does not.
|
|
239
|
-
const kvFromItem = (item) => {
|
|
240
|
-
const keys = [];
|
|
241
|
-
let value = undefined;
|
|
242
|
-
for (const key of Object.keys(item)) {
|
|
243
|
-
value = item[key];
|
|
244
|
-
if (value === undefined) {
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
keys.push(key);
|
|
248
|
-
}
|
|
249
|
-
if (keys.length !== 1) {
|
|
250
|
-
throw new Error(`invalid "propagator" entry in configuration, there must be exactly one key (with a non-undefined value): ${(0, util_1.inspect)(item)}`);
|
|
251
|
-
}
|
|
252
|
-
return [keys[0], value];
|
|
253
|
-
};
|
|
254
|
-
// First pass: handle 'none', remove dupes.
|
|
255
|
-
const names = new Set();
|
|
256
|
-
const kvs = [];
|
|
257
|
-
for (const item of configComposite) {
|
|
258
|
-
const kv = kvFromItem(item);
|
|
259
|
-
const k = kv[0];
|
|
260
|
-
if (names.has(k)) {
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
names.add(k);
|
|
264
|
-
kvs.push(kv);
|
|
265
|
-
if (k === 'none') {
|
|
266
|
-
return undefined;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
// Implementation note: this only contains specification required propagators that are actually hosted in this repo.
|
|
270
|
-
// Any other propagators (like aws, aws-lambda, should go into `@opentelemetry/auto-configuration-propagators` instead).
|
|
271
|
-
const propagatorsFactory = new Map([
|
|
272
|
-
['tracecontext', () => new core_1.W3CTraceContextPropagator()],
|
|
273
|
-
['baggage', () => new core_1.W3CBaggagePropagator()],
|
|
274
|
-
['b3', () => new propagator_b3_1.B3Propagator()],
|
|
275
|
-
[
|
|
276
|
-
'b3multi',
|
|
277
|
-
() => new propagator_b3_1.B3Propagator({ injectEncoding: propagator_b3_1.B3InjectEncoding.MULTI_HEADER }),
|
|
278
|
-
],
|
|
279
|
-
[
|
|
280
|
-
'jaeger',
|
|
281
|
-
() => {
|
|
282
|
-
api_1.diag.warn('The Jaeger propagator is deprecated and will be removed in a future release. Use the W3C TraceContext propagator ("tracecontext") instead.');
|
|
283
|
-
return new propagator_jaeger_1.JaegerPropagator();
|
|
284
|
-
},
|
|
285
|
-
],
|
|
286
|
-
]);
|
|
287
|
-
const validPropagators = [];
|
|
288
|
-
for (const [name] of kvs) {
|
|
289
|
-
const propagator = propagatorsFactory.get(name)?.();
|
|
290
|
-
if (!propagator) {
|
|
291
|
-
api_1.diag.warn(`Propagator "${name}" requested through configuration is unavailable.`);
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
validPropagators.push(propagator);
|
|
295
|
-
}
|
|
296
|
-
if (validPropagators.length === 0) {
|
|
297
|
-
return undefined;
|
|
298
|
-
}
|
|
299
|
-
else if (validPropagators.length === 1) {
|
|
300
|
-
return validPropagators[0];
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
return new core_1.CompositePropagator({
|
|
304
|
-
propagators: validPropagators,
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
exports.getPropagatorFromConfiguration = getPropagatorFromConfiguration;
|
|
309
176
|
function setupContextManager(contextManager) {
|
|
310
177
|
// null means 'do not register'
|
|
311
178
|
if (contextManager === null) {
|
|
@@ -412,127 +279,6 @@ function getOtlpMetricExporterFromEnv() {
|
|
|
412
279
|
return new exporter_metrics_otlp_proto_1.OTLPMetricExporter();
|
|
413
280
|
}
|
|
414
281
|
exports.getOtlpMetricExporterFromEnv = getOtlpMetricExporterFromEnv;
|
|
415
|
-
function getMetricProducersFromConfiguration(producers) {
|
|
416
|
-
if (!producers || producers.length === 0) {
|
|
417
|
-
return undefined;
|
|
418
|
-
}
|
|
419
|
-
const result = [];
|
|
420
|
-
for (const producer of producers) {
|
|
421
|
-
// Note: The "opencensus" MetricProducer is intentionally not supported.
|
|
422
|
-
// It is deprecated in OpenTelemetry Configuration v1.2.0.
|
|
423
|
-
api_1.diag.warn(`Unsupported metric producer in configuration: "${producer}". Skipping.`);
|
|
424
|
-
}
|
|
425
|
-
return result.length > 0 ? result : undefined;
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Map a declarative-config `temporality_preference` value to the enum the OTLP
|
|
429
|
-
* metric exporters expect. Returns undefined for an unspecified preference so
|
|
430
|
-
* the exporter falls back to its own default (cumulative).
|
|
431
|
-
*/
|
|
432
|
-
function getMetricTemporalityPreference(preference) {
|
|
433
|
-
switch (preference) {
|
|
434
|
-
case 'delta':
|
|
435
|
-
return exporter_metrics_otlp_http_2.AggregationTemporalityPreference.DELTA;
|
|
436
|
-
case 'low_memory':
|
|
437
|
-
return exporter_metrics_otlp_http_2.AggregationTemporalityPreference.LOWMEMORY;
|
|
438
|
-
case 'cumulative':
|
|
439
|
-
return exporter_metrics_otlp_http_2.AggregationTemporalityPreference.CUMULATIVE;
|
|
440
|
-
default:
|
|
441
|
-
return undefined;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Map a declarative-config `default_histogram_aggregation` value to an
|
|
446
|
-
* AggregationSelector that applies the requested aggregation to histogram
|
|
447
|
-
* instruments and leaves all other instrument types at their default. Returns
|
|
448
|
-
* undefined for an unspecified value so the exporter uses its own default.
|
|
449
|
-
*/
|
|
450
|
-
function getMetricAggregationPreference(aggregation) {
|
|
451
|
-
let histogramAggregation;
|
|
452
|
-
switch (aggregation) {
|
|
453
|
-
case 'base2_exponential_bucket_histogram':
|
|
454
|
-
histogramAggregation = { type: sdk_metrics_1.AggregationType.EXPONENTIAL_HISTOGRAM };
|
|
455
|
-
break;
|
|
456
|
-
case 'explicit_bucket_histogram':
|
|
457
|
-
histogramAggregation = {
|
|
458
|
-
type: sdk_metrics_1.AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
|
|
459
|
-
};
|
|
460
|
-
break;
|
|
461
|
-
default:
|
|
462
|
-
return undefined;
|
|
463
|
-
}
|
|
464
|
-
return (instrumentType) => instrumentType === sdk_metrics_1.InstrumentType.HISTOGRAM
|
|
465
|
-
? histogramAggregation
|
|
466
|
-
: { type: sdk_metrics_1.AggregationType.DEFAULT };
|
|
467
|
-
}
|
|
468
|
-
function getOtlpHttpMetricExporter(otlpHttp) {
|
|
469
|
-
const encoding = otlpHttp?.encoding ?? 'protobuf';
|
|
470
|
-
const options = {
|
|
471
|
-
compression: otlpHttp?.compression === 'gzip'
|
|
472
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
473
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
474
|
-
url: otlpHttp?.endpoint ?? undefined,
|
|
475
|
-
headers: getHeadersFromConfiguration(otlpHttp?.headers),
|
|
476
|
-
timeoutMillis: validateExporterTimeout(otlpHttp?.timeout),
|
|
477
|
-
httpAgentOptions: getHttpAgentOptionsFromTls(otlpHttp?.tls),
|
|
478
|
-
temporalityPreference: getMetricTemporalityPreference(otlpHttp?.temporality_preference),
|
|
479
|
-
aggregationPreference: getMetricAggregationPreference(otlpHttp?.default_histogram_aggregation),
|
|
480
|
-
};
|
|
481
|
-
if (encoding === 'json') {
|
|
482
|
-
return new exporter_metrics_otlp_http_1.OTLPMetricExporter(options);
|
|
483
|
-
}
|
|
484
|
-
else if (encoding === 'protobuf') {
|
|
485
|
-
return new exporter_metrics_otlp_proto_1.OTLPMetricExporter(options);
|
|
486
|
-
}
|
|
487
|
-
api_1.diag.warn(`Unsupported OTLP metrics encoding: ${encoding}.`);
|
|
488
|
-
return undefined;
|
|
489
|
-
}
|
|
490
|
-
function getOtlpGrpcMetricExporter(otlpGrpc) {
|
|
491
|
-
return new exporter_metrics_otlp_grpc_1.OTLPMetricExporter({
|
|
492
|
-
compression: otlpGrpc?.compression === 'gzip'
|
|
493
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
494
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
495
|
-
url: otlpGrpc?.endpoint ?? undefined,
|
|
496
|
-
timeoutMillis: validateExporterTimeout(otlpGrpc?.timeout),
|
|
497
|
-
credentials: getGrpcCredentialsFromTls(otlpGrpc?.tls),
|
|
498
|
-
metadata: getGrpcMetadataFromHeaders(otlpGrpc?.headers),
|
|
499
|
-
temporalityPreference: getMetricTemporalityPreference(otlpGrpc?.temporality_preference),
|
|
500
|
-
aggregationPreference: getMetricAggregationPreference(otlpGrpc?.default_histogram_aggregation),
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
function getMetricExporter(exporter) {
|
|
504
|
-
if (exporter.otlp_http !== undefined) {
|
|
505
|
-
return getOtlpHttpMetricExporter(exporter.otlp_http);
|
|
506
|
-
}
|
|
507
|
-
if (exporter.otlp_grpc !== undefined) {
|
|
508
|
-
return getOtlpGrpcMetricExporter(exporter.otlp_grpc);
|
|
509
|
-
}
|
|
510
|
-
if (exporter.console !== undefined) {
|
|
511
|
-
return new sdk_metrics_1.ConsoleMetricExporter();
|
|
512
|
-
}
|
|
513
|
-
api_1.diag.warn('Unsupported Metric Exporter.');
|
|
514
|
-
return undefined;
|
|
515
|
-
}
|
|
516
|
-
exports.getMetricExporter = getMetricExporter;
|
|
517
|
-
function getPeriodicMetricReaderFromConfiguration(periodic) {
|
|
518
|
-
if (!periodic.exporter) {
|
|
519
|
-
api_1.diag.warn('Unsupported Metric Exporter.');
|
|
520
|
-
return undefined;
|
|
521
|
-
}
|
|
522
|
-
const exporter = getMetricExporter(periodic.exporter);
|
|
523
|
-
if (!exporter) {
|
|
524
|
-
return undefined;
|
|
525
|
-
}
|
|
526
|
-
const metricProducers = getMetricProducersFromConfiguration(periodic.producers);
|
|
527
|
-
// TODO(6425): add cardinality_limits
|
|
528
|
-
return new sdk_metrics_1.PeriodicExportingMetricReader({
|
|
529
|
-
exportIntervalMillis: periodic.interval ?? 60000,
|
|
530
|
-
exportTimeoutMillis: periodic.timeout ?? 30000,
|
|
531
|
-
exporter,
|
|
532
|
-
metricProducers,
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
exports.getPeriodicMetricReaderFromConfiguration = getPeriodicMetricReaderFromConfiguration;
|
|
536
282
|
/**
|
|
537
283
|
* Get LoggerProviderConfig from environment variables.
|
|
538
284
|
*/
|
|
@@ -566,330 +312,6 @@ function getBatchLogRecordProcessorFromEnv(exporter, selfObsMeterProvider) {
|
|
|
566
312
|
});
|
|
567
313
|
}
|
|
568
314
|
exports.getBatchLogRecordProcessorFromEnv = getBatchLogRecordProcessorFromEnv;
|
|
569
|
-
function getHeadersFromConfiguration(headers) {
|
|
570
|
-
if (!headers) {
|
|
571
|
-
return undefined;
|
|
572
|
-
}
|
|
573
|
-
const result = {};
|
|
574
|
-
headers.forEach(header => {
|
|
575
|
-
if (header.value !== null) {
|
|
576
|
-
result[header.name] = header.value;
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
return result;
|
|
580
|
-
}
|
|
581
|
-
exports.getHeadersFromConfiguration = getHeadersFromConfiguration;
|
|
582
|
-
/**
|
|
583
|
-
* Validate an exporter timeout value. The spec says 0 means "no limit
|
|
584
|
-
* (infinity)" but the JS exporters don't support that yet (see #6617).
|
|
585
|
-
* Warn and return undefined so the exporter falls back to its default.
|
|
586
|
-
*/
|
|
587
|
-
function validateExporterTimeout(timeout) {
|
|
588
|
-
if (timeout === null) {
|
|
589
|
-
return undefined;
|
|
590
|
-
}
|
|
591
|
-
else if (timeout === 0) {
|
|
592
|
-
api_1.diag.warn('Exporter timeout of 0 (infinite) is not supported. Using default timeout.');
|
|
593
|
-
return undefined;
|
|
594
|
-
}
|
|
595
|
-
return timeout;
|
|
596
|
-
}
|
|
597
|
-
exports.validateExporterTimeout = validateExporterTimeout;
|
|
598
|
-
function getHttpAgentOptionsFromTls(tls) {
|
|
599
|
-
if (tls && (tls.ca_file || tls.cert_file || tls.key_file)) {
|
|
600
|
-
return {
|
|
601
|
-
ca: readFileOrWarn(tls.ca_file, 'TLS CA'),
|
|
602
|
-
cert: readFileOrWarn(tls.cert_file, 'TLS cert'),
|
|
603
|
-
key: readFileOrWarn(tls.key_file, 'TLS key'),
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
return undefined;
|
|
607
|
-
}
|
|
608
|
-
exports.getHttpAgentOptionsFromTls = getHttpAgentOptionsFromTls;
|
|
609
|
-
function getGrpcCredentialsFromTls(tls) {
|
|
610
|
-
if (tls?.insecure) {
|
|
611
|
-
return (0, otlp_grpc_exporter_base_1.createInsecureCredentials)();
|
|
612
|
-
}
|
|
613
|
-
const rootCert = readFileOrWarn(tls?.ca_file, 'TLS CA');
|
|
614
|
-
const privateKey = readFileOrWarn(tls?.key_file, 'TLS key');
|
|
615
|
-
const certChain = readFileOrWarn(tls?.cert_file, 'TLS cert');
|
|
616
|
-
if (rootCert || privateKey || certChain) {
|
|
617
|
-
try {
|
|
618
|
-
return (0, otlp_grpc_exporter_base_1.createSslCredentials)(rootCert, privateKey, certChain);
|
|
619
|
-
}
|
|
620
|
-
catch (e) {
|
|
621
|
-
api_1.diag.warn(`Failed to create gRPC SSL credentials: ${e}`);
|
|
622
|
-
return undefined;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
return undefined;
|
|
626
|
-
}
|
|
627
|
-
exports.getGrpcCredentialsFromTls = getGrpcCredentialsFromTls;
|
|
628
|
-
function getGrpcMetadataFromHeaders(headers) {
|
|
629
|
-
if (!headers || headers.length === 0) {
|
|
630
|
-
return undefined;
|
|
631
|
-
}
|
|
632
|
-
const metadata = (0, otlp_grpc_exporter_base_1.createEmptyMetadata)();
|
|
633
|
-
for (const header of headers) {
|
|
634
|
-
if (header.value !== null) {
|
|
635
|
-
metadata.set(header.name, header.value);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
return metadata;
|
|
639
|
-
}
|
|
640
|
-
exports.getGrpcMetadataFromHeaders = getGrpcMetadataFromHeaders;
|
|
641
|
-
function readFileOrWarn(filePath, label) {
|
|
642
|
-
if (!filePath)
|
|
643
|
-
return undefined;
|
|
644
|
-
try {
|
|
645
|
-
return fs.readFileSync(filePath);
|
|
646
|
-
}
|
|
647
|
-
catch (e) {
|
|
648
|
-
api_1.diag.warn(`Failed to read ${label} file at ${filePath}: ${e}`);
|
|
649
|
-
return undefined;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
function getSpanExporter(exporter) {
|
|
653
|
-
if (exporter.otlp_http !== undefined) {
|
|
654
|
-
const encoding = exporter.otlp_http?.encoding ?? 'protobuf';
|
|
655
|
-
if (encoding === 'json') {
|
|
656
|
-
return new exporter_trace_otlp_http_1.OTLPTraceExporter({
|
|
657
|
-
compression: exporter.otlp_http?.compression === 'gzip'
|
|
658
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
659
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
660
|
-
url: exporter.otlp_http?.endpoint ?? undefined,
|
|
661
|
-
headers: getHeadersFromConfiguration(exporter.otlp_http?.headers),
|
|
662
|
-
timeoutMillis: validateExporterTimeout(exporter.otlp_http?.timeout),
|
|
663
|
-
httpAgentOptions: getHttpAgentOptionsFromTls(exporter.otlp_http?.tls),
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
else {
|
|
667
|
-
return new exporter_trace_otlp_proto_1.OTLPTraceExporter({
|
|
668
|
-
compression: exporter.otlp_http?.compression === 'gzip'
|
|
669
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
670
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
671
|
-
url: exporter.otlp_http?.endpoint ?? undefined,
|
|
672
|
-
headers: getHeadersFromConfiguration(exporter.otlp_http?.headers),
|
|
673
|
-
timeoutMillis: validateExporterTimeout(exporter.otlp_http?.timeout),
|
|
674
|
-
httpAgentOptions: getHttpAgentOptionsFromTls(exporter.otlp_http?.tls),
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
else if (exporter.otlp_grpc !== undefined) {
|
|
679
|
-
return new exporter_trace_otlp_grpc_1.OTLPTraceExporter({
|
|
680
|
-
compression: exporter.otlp_grpc?.compression === 'gzip'
|
|
681
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
682
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
683
|
-
url: exporter.otlp_grpc?.endpoint ?? undefined,
|
|
684
|
-
timeoutMillis: validateExporterTimeout(exporter.otlp_grpc?.timeout),
|
|
685
|
-
credentials: getGrpcCredentialsFromTls(exporter.otlp_grpc?.tls),
|
|
686
|
-
metadata: getGrpcMetadataFromHeaders(exporter.otlp_grpc?.headers),
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
else if (exporter.console !== undefined) {
|
|
690
|
-
return new sdk_trace_1.ConsoleSpanExporter();
|
|
691
|
-
}
|
|
692
|
-
api_1.diag.warn('Unsupported Exporter value. No Span Exporter registered');
|
|
693
|
-
return undefined;
|
|
694
|
-
}
|
|
695
|
-
exports.getSpanExporter = getSpanExporter;
|
|
696
|
-
function getSpanProcessorsFromConfiguration(config) {
|
|
697
|
-
const spanProcessors = [];
|
|
698
|
-
config.tracer_provider?.processors?.forEach(processor => {
|
|
699
|
-
if (processor.batch) {
|
|
700
|
-
const exporter = getSpanExporter(processor.batch.exporter);
|
|
701
|
-
if (exporter) {
|
|
702
|
-
spanProcessors.push(new sdk_trace_1.BatchSpanProcessor({
|
|
703
|
-
exporter,
|
|
704
|
-
maxQueueSize: processor.batch.max_queue_size ?? undefined,
|
|
705
|
-
maxExportBatchSize: processor.batch.max_export_batch_size ?? undefined,
|
|
706
|
-
scheduledDelayMillis: processor.batch.schedule_delay ?? undefined,
|
|
707
|
-
exportTimeoutMillis: processor.batch.export_timeout ?? undefined,
|
|
708
|
-
}));
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
if (processor.simple) {
|
|
712
|
-
const exporter = getSpanExporter(processor.simple.exporter);
|
|
713
|
-
if (exporter) {
|
|
714
|
-
spanProcessors.push(new sdk_trace_1.SimpleSpanProcessor({ exporter }));
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
});
|
|
718
|
-
if (spanProcessors.length > 0) {
|
|
719
|
-
return spanProcessors;
|
|
720
|
-
}
|
|
721
|
-
return undefined;
|
|
722
|
-
}
|
|
723
|
-
exports.getSpanProcessorsFromConfiguration = getSpanProcessorsFromConfiguration;
|
|
724
|
-
function getIdGeneratorFromConfiguration(config) {
|
|
725
|
-
const idGenerator = config.tracer_provider?.id_generator;
|
|
726
|
-
if (!idGenerator) {
|
|
727
|
-
return undefined;
|
|
728
|
-
}
|
|
729
|
-
if (idGenerator.random !== undefined) {
|
|
730
|
-
return new sdk_trace_1.RandomIdGenerator();
|
|
731
|
-
}
|
|
732
|
-
// Any other key is a third-party / custom id_generator type which we
|
|
733
|
-
// don't currently support. Warn and fall back to SDK default.
|
|
734
|
-
const unknownKeys = Object.keys(idGenerator).filter(k => k !== 'random');
|
|
735
|
-
if (unknownKeys.length > 0) {
|
|
736
|
-
api_1.diag.warn(`Unsupported id_generator type(s): ${unknownKeys.join(', ')}. Using default.`);
|
|
737
|
-
}
|
|
738
|
-
return undefined;
|
|
739
|
-
}
|
|
740
|
-
exports.getIdGeneratorFromConfiguration = getIdGeneratorFromConfiguration;
|
|
741
|
-
function getMeterReadersFromConfiguration(config) {
|
|
742
|
-
const metricReaders = [];
|
|
743
|
-
config.meter_provider?.readers?.forEach(reader => {
|
|
744
|
-
if (reader.periodic) {
|
|
745
|
-
const periodicReader = getPeriodicMetricReaderFromConfiguration(reader.periodic);
|
|
746
|
-
if (periodicReader) {
|
|
747
|
-
metricReaders.push(periodicReader);
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
});
|
|
751
|
-
if (metricReaders.length > 0) {
|
|
752
|
-
return metricReaders;
|
|
753
|
-
}
|
|
754
|
-
return undefined;
|
|
755
|
-
}
|
|
756
|
-
exports.getMeterReadersFromConfiguration = getMeterReadersFromConfiguration;
|
|
757
|
-
function getInstrumentType(instrument) {
|
|
758
|
-
switch (instrument) {
|
|
759
|
-
case 'counter':
|
|
760
|
-
return sdk_metrics_1.InstrumentType.COUNTER;
|
|
761
|
-
case 'gauge':
|
|
762
|
-
return sdk_metrics_1.InstrumentType.GAUGE;
|
|
763
|
-
case 'histogram':
|
|
764
|
-
return sdk_metrics_1.InstrumentType.HISTOGRAM;
|
|
765
|
-
case 'observable_counter':
|
|
766
|
-
return sdk_metrics_1.InstrumentType.OBSERVABLE_COUNTER;
|
|
767
|
-
case 'observable_gauge':
|
|
768
|
-
return sdk_metrics_1.InstrumentType.OBSERVABLE_GAUGE;
|
|
769
|
-
case 'observable_up_down_counter':
|
|
770
|
-
return sdk_metrics_1.InstrumentType.OBSERVABLE_UP_DOWN_COUNTER;
|
|
771
|
-
case 'up_down_counter':
|
|
772
|
-
return sdk_metrics_1.InstrumentType.UP_DOWN_COUNTER;
|
|
773
|
-
default:
|
|
774
|
-
api_1.diag.warn(`Unsupported instrument type: ${instrument}`);
|
|
775
|
-
return undefined;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
exports.getInstrumentType = getInstrumentType;
|
|
779
|
-
function getAggregationType(aggregation) {
|
|
780
|
-
if (aggregation.default) {
|
|
781
|
-
return {
|
|
782
|
-
type: sdk_metrics_1.AggregationType.DEFAULT,
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
|
-
if (aggregation.drop) {
|
|
786
|
-
return {
|
|
787
|
-
type: sdk_metrics_1.AggregationType.DROP,
|
|
788
|
-
};
|
|
789
|
-
}
|
|
790
|
-
if (aggregation.explicit_bucket_histogram) {
|
|
791
|
-
return {
|
|
792
|
-
type: sdk_metrics_1.AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
|
|
793
|
-
options: {
|
|
794
|
-
recordMinMax: aggregation.explicit_bucket_histogram.record_min_max ?? true,
|
|
795
|
-
boundaries: aggregation.explicit_bucket_histogram.boundaries ?? [
|
|
796
|
-
0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500,
|
|
797
|
-
10000,
|
|
798
|
-
],
|
|
799
|
-
},
|
|
800
|
-
};
|
|
801
|
-
}
|
|
802
|
-
if (aggregation.base2_exponential_bucket_histogram) {
|
|
803
|
-
return {
|
|
804
|
-
type: sdk_metrics_1.AggregationType.EXPONENTIAL_HISTOGRAM,
|
|
805
|
-
options: {
|
|
806
|
-
recordMinMax: aggregation.base2_exponential_bucket_histogram.record_min_max ??
|
|
807
|
-
undefined,
|
|
808
|
-
maxSize: aggregation.base2_exponential_bucket_histogram.max_size ?? undefined,
|
|
809
|
-
},
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
if (aggregation.last_value) {
|
|
813
|
-
return {
|
|
814
|
-
type: sdk_metrics_1.AggregationType.LAST_VALUE,
|
|
815
|
-
};
|
|
816
|
-
}
|
|
817
|
-
if (aggregation.sum) {
|
|
818
|
-
return {
|
|
819
|
-
type: sdk_metrics_1.AggregationType.SUM,
|
|
820
|
-
};
|
|
821
|
-
}
|
|
822
|
-
api_1.diag.warn('Unsupported aggregation type');
|
|
823
|
-
return undefined;
|
|
824
|
-
}
|
|
825
|
-
exports.getAggregationType = getAggregationType;
|
|
826
|
-
function getMeterViewsFromConfiguration(config) {
|
|
827
|
-
const metricViews = [];
|
|
828
|
-
config.meter_provider?.views?.forEach(view => {
|
|
829
|
-
const viewOption = {};
|
|
830
|
-
if (view.selector) {
|
|
831
|
-
if (view.selector.instrument_name) {
|
|
832
|
-
viewOption.instrumentName = view.selector.instrument_name;
|
|
833
|
-
}
|
|
834
|
-
if (view.selector.instrument_type) {
|
|
835
|
-
const instrumentType = getInstrumentType(view.selector.instrument_type);
|
|
836
|
-
if (instrumentType) {
|
|
837
|
-
viewOption.instrumentType = instrumentType;
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
if (view.selector.unit) {
|
|
841
|
-
viewOption.instrumentUnit = view.selector.unit;
|
|
842
|
-
}
|
|
843
|
-
if (view.selector.meter_name) {
|
|
844
|
-
viewOption.meterName = view.selector.meter_name;
|
|
845
|
-
}
|
|
846
|
-
if (view.selector.meter_version) {
|
|
847
|
-
viewOption.meterVersion = view.selector.meter_version;
|
|
848
|
-
}
|
|
849
|
-
if (view.selector.meter_schema_url) {
|
|
850
|
-
viewOption.meterSchemaUrl = view.selector.meter_schema_url;
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
if (view.stream) {
|
|
854
|
-
if (view.stream.name) {
|
|
855
|
-
viewOption.name = view.stream.name;
|
|
856
|
-
}
|
|
857
|
-
viewOption.aggregationCardinalityLimit =
|
|
858
|
-
view.stream.aggregation_cardinality_limit ?? 2000;
|
|
859
|
-
if (view.stream.description) {
|
|
860
|
-
viewOption.description = view.stream.description;
|
|
861
|
-
}
|
|
862
|
-
if (view.stream.aggregation) {
|
|
863
|
-
const aggregationType = getAggregationType(view.stream.aggregation);
|
|
864
|
-
if (aggregationType) {
|
|
865
|
-
viewOption.aggregation = aggregationType;
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
if (view.stream.attribute_keys) {
|
|
869
|
-
const processors = [];
|
|
870
|
-
if (view.stream.attribute_keys.included &&
|
|
871
|
-
view.stream.attribute_keys.included.length > 0) {
|
|
872
|
-
processors.push((0, sdk_metrics_1.createAllowListAttributesProcessor)(view.stream.attribute_keys.included));
|
|
873
|
-
}
|
|
874
|
-
if (view.stream.attribute_keys.excluded &&
|
|
875
|
-
view.stream.attribute_keys.excluded.length > 0) {
|
|
876
|
-
processors.push((0, sdk_metrics_1.createDenyListAttributesProcessor)(view.stream.attribute_keys.excluded));
|
|
877
|
-
}
|
|
878
|
-
if (processors.length > 0) {
|
|
879
|
-
viewOption.attributesProcessors = processors;
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
if (Object.keys(viewOption).length > 0) {
|
|
884
|
-
metricViews.push(viewOption);
|
|
885
|
-
}
|
|
886
|
-
});
|
|
887
|
-
if (metricViews.length > 0) {
|
|
888
|
-
return metricViews;
|
|
889
|
-
}
|
|
890
|
-
return undefined;
|
|
891
|
-
}
|
|
892
|
-
exports.getMeterViewsFromConfiguration = getMeterViewsFromConfiguration;
|
|
893
315
|
function getInstanceID(config) {
|
|
894
316
|
if (config.resource?.attributes) {
|
|
895
317
|
for (let i = 0; i < config.resource.attributes.length; i++) {
|
|
@@ -902,54 +324,4 @@ function getInstanceID(config) {
|
|
|
902
324
|
return undefined;
|
|
903
325
|
}
|
|
904
326
|
exports.getInstanceID = getInstanceID;
|
|
905
|
-
const DEFAULT_RATIO = 1;
|
|
906
|
-
/**
|
|
907
|
-
* Returns the {@link Sampler} configured under `tracer_provider.sampler` in
|
|
908
|
-
* the declarative configuration, or `undefined` if none is set (in which case
|
|
909
|
-
* the SDK applies its default sampler).
|
|
910
|
-
*/
|
|
911
|
-
function getSamplerFromConfiguration(config) {
|
|
912
|
-
const samplerConfig = config.tracer_provider?.sampler;
|
|
913
|
-
if (!samplerConfig) {
|
|
914
|
-
return undefined;
|
|
915
|
-
}
|
|
916
|
-
return buildSamplerFromConfig(samplerConfig);
|
|
917
|
-
}
|
|
918
|
-
exports.getSamplerFromConfiguration = getSamplerFromConfiguration;
|
|
919
|
-
/**
|
|
920
|
-
* Builds a {@link Sampler} from a {@link SamplerConfigModel} data model.
|
|
921
|
-
* This allows sampler construction from declarative configuration.
|
|
922
|
-
*/
|
|
923
|
-
function buildSamplerFromConfig(samplerConfig) {
|
|
924
|
-
if (samplerConfig.always_on !== undefined) {
|
|
925
|
-
return new sdk_trace_1.AlwaysOnSampler();
|
|
926
|
-
}
|
|
927
|
-
if (samplerConfig.always_off !== undefined) {
|
|
928
|
-
return new sdk_trace_1.AlwaysOffSampler();
|
|
929
|
-
}
|
|
930
|
-
if (samplerConfig.trace_id_ratio_based !== undefined) {
|
|
931
|
-
return new sdk_trace_1.TraceIdRatioBasedSampler(samplerConfig.trace_id_ratio_based?.ratio ?? DEFAULT_RATIO);
|
|
932
|
-
}
|
|
933
|
-
if (samplerConfig.parent_based !== undefined) {
|
|
934
|
-
const pb = samplerConfig.parent_based ?? {};
|
|
935
|
-
return new sdk_trace_1.ParentBasedSampler({
|
|
936
|
-
root: pb.root ? buildSamplerFromConfig(pb.root) : new sdk_trace_1.AlwaysOnSampler(),
|
|
937
|
-
remoteParentSampled: pb.remote_parent_sampled
|
|
938
|
-
? buildSamplerFromConfig(pb.remote_parent_sampled)
|
|
939
|
-
: undefined,
|
|
940
|
-
remoteParentNotSampled: pb.remote_parent_not_sampled
|
|
941
|
-
? buildSamplerFromConfig(pb.remote_parent_not_sampled)
|
|
942
|
-
: undefined,
|
|
943
|
-
localParentSampled: pb.local_parent_sampled
|
|
944
|
-
? buildSamplerFromConfig(pb.local_parent_sampled)
|
|
945
|
-
: undefined,
|
|
946
|
-
localParentNotSampled: pb.local_parent_not_sampled
|
|
947
|
-
? buildSamplerFromConfig(pb.local_parent_not_sampled)
|
|
948
|
-
: undefined,
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
api_1.diag.warn('Unknown sampler config, defaulting to ParentBased(AlwaysOn).');
|
|
952
|
-
return new sdk_trace_1.ParentBasedSampler({ root: new sdk_trace_1.AlwaysOnSampler() });
|
|
953
|
-
}
|
|
954
|
-
exports.buildSamplerFromConfig = buildSamplerFromConfig;
|
|
955
327
|
//# sourceMappingURL=utils.js.map
|