@opentelemetry/sdk-node 0.220.0 → 0.222.0-development.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 +26 -5
- package/build/src/create-from-config.js +1011 -1
- 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/sdk.js +9 -6
- package/build/src/sdk.js.map +1 -1
- package/build/src/start.d.ts +0 -3
- package/build/src/start.js +15 -62
- 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 +7 -45
- package/build/src/utils.js +10 -763
- 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 +32 -31
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,46 +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 exporter_logs_otlp_http_1 = require("@opentelemetry/exporter-logs-otlp-http");
|
|
20
|
-
const exporter_logs_otlp_grpc_1 = require("@opentelemetry/exporter-logs-otlp-grpc");
|
|
21
|
-
const exporter_logs_otlp_proto_1 = require("@opentelemetry/exporter-logs-otlp-proto");
|
|
22
|
-
const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
|
|
23
|
-
const otlp_grpc_exporter_base_1 = require("@opentelemetry/otlp-grpc-exporter-base");
|
|
24
|
-
const configuration_1 = require("@opentelemetry/configuration");
|
|
25
19
|
const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
|
|
26
20
|
const exporter_metrics_otlp_grpc_1 = require("@opentelemetry/exporter-metrics-otlp-grpc");
|
|
27
21
|
const exporter_metrics_otlp_http_1 = require("@opentelemetry/exporter-metrics-otlp-http");
|
|
28
|
-
const exporter_metrics_otlp_http_2 = require("@opentelemetry/exporter-metrics-otlp-http");
|
|
29
22
|
const exporter_metrics_otlp_proto_1 = require("@opentelemetry/exporter-metrics-otlp-proto");
|
|
30
23
|
const sdk_logs_1 = require("@opentelemetry/sdk-logs");
|
|
31
|
-
const fs = require("fs");
|
|
32
|
-
const util_1 = require("util");
|
|
33
24
|
const create_from_env_1 = require("./create-from-env");
|
|
34
25
|
const RESOURCE_DETECTOR_ENVIRONMENT = 'env';
|
|
35
26
|
const RESOURCE_DETECTOR_HOST = 'host';
|
|
36
27
|
const RESOURCE_DETECTOR_OS = 'os';
|
|
37
28
|
const RESOURCE_DETECTOR_PROCESS = 'process';
|
|
38
29
|
const RESOURCE_DETECTOR_SERVICE_INSTANCE_ID = 'serviceinstance';
|
|
39
|
-
function getResourceFromConfiguration(config) {
|
|
40
|
-
if (!config.resource) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
const configAttrs = (0, configuration_1.mergeResourceAttributesConfig)(config.resource.attributes, config.resource.attributes_list);
|
|
44
|
-
if (!configAttrs) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
const attrs = {};
|
|
48
|
-
for (let i = 0; i < configAttrs.length; i++) {
|
|
49
|
-
const a = configAttrs[i];
|
|
50
|
-
if (a.value !== null) {
|
|
51
|
-
attrs[a.name] = a.value;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return (0, resources_1.resourceFromAttributes)(attrs, {
|
|
55
|
-
schemaUrl: config.resource.schema_url ?? undefined,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
exports.getResourceFromConfiguration = getResourceFromConfiguration;
|
|
59
30
|
function getResourceDetectorsFromEnv() {
|
|
60
31
|
// When updating this list, make sure to also update the section `resourceDetectors` on README.
|
|
61
32
|
const resourceDetectors = new Map([
|
|
@@ -81,24 +52,6 @@ function getResourceDetectorsFromEnv() {
|
|
|
81
52
|
});
|
|
82
53
|
}
|
|
83
54
|
exports.getResourceDetectorsFromEnv = getResourceDetectorsFromEnv;
|
|
84
|
-
function getResourceDetectorsFromConfiguration(config) {
|
|
85
|
-
const detectors = config.resource?.['detection/development']?.detectors ?? [];
|
|
86
|
-
return detectors.flatMap(detector => {
|
|
87
|
-
const result = [];
|
|
88
|
-
if (detector.host !== undefined)
|
|
89
|
-
result.push(resources_1.hostDetector);
|
|
90
|
-
if (detector.os !== undefined)
|
|
91
|
-
result.push(resources_1.osDetector);
|
|
92
|
-
if (detector.process !== undefined)
|
|
93
|
-
result.push(resources_1.processDetector);
|
|
94
|
-
if (detector.service !== undefined)
|
|
95
|
-
result.push(resources_1.serviceInstanceIdDetector);
|
|
96
|
-
if (detector.env !== undefined)
|
|
97
|
-
result.push(resources_1.envDetector);
|
|
98
|
-
return result;
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
exports.getResourceDetectorsFromConfiguration = getResourceDetectorsFromConfiguration;
|
|
102
55
|
function getOtlpProtocolFromEnv() {
|
|
103
56
|
return ((0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_TRACES_PROTOCOL') ??
|
|
104
57
|
(0, core_1.getStringFromEnv)('OTEL_EXPORTER_OTLP_PROTOCOL') ??
|
|
@@ -187,7 +140,13 @@ function getPropagatorFromEnv() {
|
|
|
187
140
|
'b3multi',
|
|
188
141
|
() => new propagator_b3_1.B3Propagator({ injectEncoding: propagator_b3_1.B3InjectEncoding.MULTI_HEADER }),
|
|
189
142
|
],
|
|
190
|
-
[
|
|
143
|
+
[
|
|
144
|
+
'jaeger',
|
|
145
|
+
() => {
|
|
146
|
+
api_1.diag.warn('The Jaeger propagator is deprecated and will be removed in a future release. Use the W3C TraceContext propagator ("tracecontext") instead.');
|
|
147
|
+
return new propagator_jaeger_1.JaegerPropagator();
|
|
148
|
+
},
|
|
149
|
+
],
|
|
191
150
|
]);
|
|
192
151
|
// Values MUST be deduplicated in order to register a Propagator only once.
|
|
193
152
|
const uniquePropagatorNames = Array.from(new Set(propagatorsEnvVarValue));
|
|
@@ -214,89 +173,6 @@ function getPropagatorFromEnv() {
|
|
|
214
173
|
}
|
|
215
174
|
}
|
|
216
175
|
exports.getPropagatorFromEnv = getPropagatorFromEnv;
|
|
217
|
-
/**
|
|
218
|
-
* Get a propagator as defined by configuration model from configuration
|
|
219
|
-
*/
|
|
220
|
-
function getPropagatorFromConfiguration(config) {
|
|
221
|
-
if (!config.propagator) {
|
|
222
|
-
return undefined;
|
|
223
|
-
}
|
|
224
|
-
const configComposite = (0, configuration_1.mergePropagatorCompositeConfig)(config.propagator.composite, config.propagator.composite_list);
|
|
225
|
-
if (!configComposite) {
|
|
226
|
-
return undefined;
|
|
227
|
-
}
|
|
228
|
-
// TextMapPropagator config items are objects with a single key (the name).
|
|
229
|
-
// Transform this into a more convenient `(name, value)` 2-tuple.
|
|
230
|
-
//
|
|
231
|
-
// As well, guard against two cases where the TypeScript type
|
|
232
|
-
// `TextMapPropagatorConfigModel` does not exactly represent the JSON schema:
|
|
233
|
-
// 1. `"minProperties": 1, "maxProperties": 1,`
|
|
234
|
-
// 2. The type allows keys with an `undefined` value, but the JSON schema
|
|
235
|
-
// does not.
|
|
236
|
-
const kvFromItem = (item) => {
|
|
237
|
-
const keys = [];
|
|
238
|
-
let value = undefined;
|
|
239
|
-
for (const key of Object.keys(item)) {
|
|
240
|
-
value = item[key];
|
|
241
|
-
if (value === undefined) {
|
|
242
|
-
continue;
|
|
243
|
-
}
|
|
244
|
-
keys.push(key);
|
|
245
|
-
}
|
|
246
|
-
if (keys.length !== 1) {
|
|
247
|
-
throw new Error(`invalid "propagator" entry in configuration, there must be exactly one key (with a non-undefined value): ${(0, util_1.inspect)(item)}`);
|
|
248
|
-
}
|
|
249
|
-
return [keys[0], value];
|
|
250
|
-
};
|
|
251
|
-
// First pass: handle 'none', remove dupes.
|
|
252
|
-
const names = new Set();
|
|
253
|
-
const kvs = [];
|
|
254
|
-
for (const item of configComposite) {
|
|
255
|
-
const kv = kvFromItem(item);
|
|
256
|
-
const k = kv[0];
|
|
257
|
-
if (names.has(k)) {
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
names.add(k);
|
|
261
|
-
kvs.push(kv);
|
|
262
|
-
if (k === 'none') {
|
|
263
|
-
return undefined;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
// Implementation note: this only contains specification required propagators that are actually hosted in this repo.
|
|
267
|
-
// Any other propagators (like aws, aws-lambda, should go into `@opentelemetry/auto-configuration-propagators` instead).
|
|
268
|
-
const propagatorsFactory = new Map([
|
|
269
|
-
['tracecontext', () => new core_1.W3CTraceContextPropagator()],
|
|
270
|
-
['baggage', () => new core_1.W3CBaggagePropagator()],
|
|
271
|
-
['b3', () => new propagator_b3_1.B3Propagator()],
|
|
272
|
-
[
|
|
273
|
-
'b3multi',
|
|
274
|
-
() => new propagator_b3_1.B3Propagator({ injectEncoding: propagator_b3_1.B3InjectEncoding.MULTI_HEADER }),
|
|
275
|
-
],
|
|
276
|
-
['jaeger', () => new propagator_jaeger_1.JaegerPropagator()],
|
|
277
|
-
]);
|
|
278
|
-
const validPropagators = [];
|
|
279
|
-
for (const [name] of kvs) {
|
|
280
|
-
const propagator = propagatorsFactory.get(name)?.();
|
|
281
|
-
if (!propagator) {
|
|
282
|
-
api_1.diag.warn(`Propagator "${name}" requested through configuration is unavailable.`);
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
validPropagators.push(propagator);
|
|
286
|
-
}
|
|
287
|
-
if (validPropagators.length === 0) {
|
|
288
|
-
return undefined;
|
|
289
|
-
}
|
|
290
|
-
else if (validPropagators.length === 1) {
|
|
291
|
-
return validPropagators[0];
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
return new core_1.CompositePropagator({
|
|
295
|
-
propagators: validPropagators,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
exports.getPropagatorFromConfiguration = getPropagatorFromConfiguration;
|
|
300
176
|
function setupContextManager(contextManager) {
|
|
301
177
|
// null means 'do not register'
|
|
302
178
|
if (contextManager === null) {
|
|
@@ -403,127 +279,6 @@ function getOtlpMetricExporterFromEnv() {
|
|
|
403
279
|
return new exporter_metrics_otlp_proto_1.OTLPMetricExporter();
|
|
404
280
|
}
|
|
405
281
|
exports.getOtlpMetricExporterFromEnv = getOtlpMetricExporterFromEnv;
|
|
406
|
-
function getMetricProducersFromConfiguration(producers) {
|
|
407
|
-
if (!producers || producers.length === 0) {
|
|
408
|
-
return undefined;
|
|
409
|
-
}
|
|
410
|
-
const result = [];
|
|
411
|
-
for (const producer of producers) {
|
|
412
|
-
// Note: The "opencensus" MetricProducer is intentionally not supported.
|
|
413
|
-
// It is deprecated in OpenTelemetry Configuration v1.2.0.
|
|
414
|
-
api_1.diag.warn(`Unsupported metric producer in configuration: "${producer}". Skipping.`);
|
|
415
|
-
}
|
|
416
|
-
return result.length > 0 ? result : undefined;
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Map a declarative-config `temporality_preference` value to the enum the OTLP
|
|
420
|
-
* metric exporters expect. Returns undefined for an unspecified preference so
|
|
421
|
-
* the exporter falls back to its own default (cumulative).
|
|
422
|
-
*/
|
|
423
|
-
function getMetricTemporalityPreference(preference) {
|
|
424
|
-
switch (preference) {
|
|
425
|
-
case 'delta':
|
|
426
|
-
return exporter_metrics_otlp_http_2.AggregationTemporalityPreference.DELTA;
|
|
427
|
-
case 'low_memory':
|
|
428
|
-
return exporter_metrics_otlp_http_2.AggregationTemporalityPreference.LOWMEMORY;
|
|
429
|
-
case 'cumulative':
|
|
430
|
-
return exporter_metrics_otlp_http_2.AggregationTemporalityPreference.CUMULATIVE;
|
|
431
|
-
default:
|
|
432
|
-
return undefined;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* Map a declarative-config `default_histogram_aggregation` value to an
|
|
437
|
-
* AggregationSelector that applies the requested aggregation to histogram
|
|
438
|
-
* instruments and leaves all other instrument types at their default. Returns
|
|
439
|
-
* undefined for an unspecified value so the exporter uses its own default.
|
|
440
|
-
*/
|
|
441
|
-
function getMetricAggregationPreference(aggregation) {
|
|
442
|
-
let histogramAggregation;
|
|
443
|
-
switch (aggregation) {
|
|
444
|
-
case 'base2_exponential_bucket_histogram':
|
|
445
|
-
histogramAggregation = { type: sdk_metrics_1.AggregationType.EXPONENTIAL_HISTOGRAM };
|
|
446
|
-
break;
|
|
447
|
-
case 'explicit_bucket_histogram':
|
|
448
|
-
histogramAggregation = {
|
|
449
|
-
type: sdk_metrics_1.AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
|
|
450
|
-
};
|
|
451
|
-
break;
|
|
452
|
-
default:
|
|
453
|
-
return undefined;
|
|
454
|
-
}
|
|
455
|
-
return (instrumentType) => instrumentType === sdk_metrics_1.InstrumentType.HISTOGRAM
|
|
456
|
-
? histogramAggregation
|
|
457
|
-
: { type: sdk_metrics_1.AggregationType.DEFAULT };
|
|
458
|
-
}
|
|
459
|
-
function getOtlpHttpMetricExporter(otlpHttp) {
|
|
460
|
-
const encoding = otlpHttp?.encoding ?? 'protobuf';
|
|
461
|
-
const options = {
|
|
462
|
-
compression: otlpHttp?.compression === 'gzip'
|
|
463
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
464
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
465
|
-
url: otlpHttp?.endpoint ?? undefined,
|
|
466
|
-
headers: getHeadersFromConfiguration(otlpHttp?.headers),
|
|
467
|
-
timeoutMillis: validateExporterTimeout(otlpHttp?.timeout),
|
|
468
|
-
httpAgentOptions: getHttpAgentOptionsFromTls(otlpHttp?.tls),
|
|
469
|
-
temporalityPreference: getMetricTemporalityPreference(otlpHttp?.temporality_preference),
|
|
470
|
-
aggregationPreference: getMetricAggregationPreference(otlpHttp?.default_histogram_aggregation),
|
|
471
|
-
};
|
|
472
|
-
if (encoding === 'json') {
|
|
473
|
-
return new exporter_metrics_otlp_http_1.OTLPMetricExporter(options);
|
|
474
|
-
}
|
|
475
|
-
else if (encoding === 'protobuf') {
|
|
476
|
-
return new exporter_metrics_otlp_proto_1.OTLPMetricExporter(options);
|
|
477
|
-
}
|
|
478
|
-
api_1.diag.warn(`Unsupported OTLP metrics encoding: ${encoding}.`);
|
|
479
|
-
return undefined;
|
|
480
|
-
}
|
|
481
|
-
function getOtlpGrpcMetricExporter(otlpGrpc) {
|
|
482
|
-
return new exporter_metrics_otlp_grpc_1.OTLPMetricExporter({
|
|
483
|
-
compression: otlpGrpc?.compression === 'gzip'
|
|
484
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
485
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
486
|
-
url: otlpGrpc?.endpoint ?? undefined,
|
|
487
|
-
timeoutMillis: validateExporterTimeout(otlpGrpc?.timeout),
|
|
488
|
-
credentials: getGrpcCredentialsFromTls(otlpGrpc?.tls),
|
|
489
|
-
metadata: getGrpcMetadataFromHeaders(otlpGrpc?.headers),
|
|
490
|
-
temporalityPreference: getMetricTemporalityPreference(otlpGrpc?.temporality_preference),
|
|
491
|
-
aggregationPreference: getMetricAggregationPreference(otlpGrpc?.default_histogram_aggregation),
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
function getMetricExporter(exporter) {
|
|
495
|
-
if (exporter.otlp_http !== undefined) {
|
|
496
|
-
return getOtlpHttpMetricExporter(exporter.otlp_http);
|
|
497
|
-
}
|
|
498
|
-
if (exporter.otlp_grpc !== undefined) {
|
|
499
|
-
return getOtlpGrpcMetricExporter(exporter.otlp_grpc);
|
|
500
|
-
}
|
|
501
|
-
if (exporter.console !== undefined) {
|
|
502
|
-
return new sdk_metrics_1.ConsoleMetricExporter();
|
|
503
|
-
}
|
|
504
|
-
api_1.diag.warn('Unsupported Metric Exporter.');
|
|
505
|
-
return undefined;
|
|
506
|
-
}
|
|
507
|
-
exports.getMetricExporter = getMetricExporter;
|
|
508
|
-
function getPeriodicMetricReaderFromConfiguration(periodic) {
|
|
509
|
-
if (!periodic.exporter) {
|
|
510
|
-
api_1.diag.warn('Unsupported Metric Exporter.');
|
|
511
|
-
return undefined;
|
|
512
|
-
}
|
|
513
|
-
const exporter = getMetricExporter(periodic.exporter);
|
|
514
|
-
if (!exporter) {
|
|
515
|
-
return undefined;
|
|
516
|
-
}
|
|
517
|
-
const metricProducers = getMetricProducersFromConfiguration(periodic.producers);
|
|
518
|
-
// TODO(6425): add cardinality_limits
|
|
519
|
-
return new sdk_metrics_1.PeriodicExportingMetricReader({
|
|
520
|
-
exportIntervalMillis: periodic.interval ?? 60000,
|
|
521
|
-
exportTimeoutMillis: periodic.timeout ?? 30000,
|
|
522
|
-
exporter,
|
|
523
|
-
metricProducers,
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
exports.getPeriodicMetricReaderFromConfiguration = getPeriodicMetricReaderFromConfiguration;
|
|
527
282
|
/**
|
|
528
283
|
* Get LoggerProviderConfig from environment variables.
|
|
529
284
|
*/
|
|
@@ -549,425 +304,14 @@ function getBatchLogRecordProcessorConfigFromEnv() {
|
|
|
549
304
|
};
|
|
550
305
|
}
|
|
551
306
|
exports.getBatchLogRecordProcessorConfigFromEnv = getBatchLogRecordProcessorConfigFromEnv;
|
|
552
|
-
function getBatchLogRecordProcessorFromEnv(exporter) {
|
|
307
|
+
function getBatchLogRecordProcessorFromEnv(exporter, selfObsMeterProvider) {
|
|
553
308
|
return new sdk_logs_1.BatchLogRecordProcessor({
|
|
554
309
|
exporter,
|
|
310
|
+
selfObsMeterProvider,
|
|
555
311
|
...getBatchLogRecordProcessorConfigFromEnv(),
|
|
556
312
|
});
|
|
557
313
|
}
|
|
558
314
|
exports.getBatchLogRecordProcessorFromEnv = getBatchLogRecordProcessorFromEnv;
|
|
559
|
-
function createLogRecordLimitsFromConfig(limits, attribute_limits) {
|
|
560
|
-
return {
|
|
561
|
-
attributeValueLengthLimit: limits?.attribute_value_length_limit ??
|
|
562
|
-
attribute_limits?.attribute_value_length_limit ??
|
|
563
|
-
undefined,
|
|
564
|
-
attributeCountLimit: limits?.attribute_count_limit ??
|
|
565
|
-
attribute_limits?.attribute_count_limit ??
|
|
566
|
-
undefined,
|
|
567
|
-
};
|
|
568
|
-
}
|
|
569
|
-
function createLoggerProviderFromConfig(resource, logger_provider, attribute_limits) {
|
|
570
|
-
const processors = logger_provider.processors.map(p => createLogRecordProcessorFromConfig(p));
|
|
571
|
-
const logRecordLimits = createLogRecordLimitsFromConfig(logger_provider.limits, attribute_limits);
|
|
572
|
-
checkConfigUse('LoggerProvider', logger_provider, ['processors', 'limits']);
|
|
573
|
-
return new sdk_logs_1.LoggerProvider({
|
|
574
|
-
resource,
|
|
575
|
-
processors,
|
|
576
|
-
logRecordLimits,
|
|
577
|
-
// TODO: loggerConfigurator
|
|
578
|
-
// TODO: meterProvider
|
|
579
|
-
// Note: forceFlushTimeoutMillis not configurable via decl conf.
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
exports.createLoggerProviderFromConfig = createLoggerProviderFromConfig;
|
|
583
|
-
function createLogRecordExporterFromConfig(exporter) {
|
|
584
|
-
const [name, properties] = mustSingleEntry(exporter, 'LogRecordExporter');
|
|
585
|
-
switch (name) {
|
|
586
|
-
case 'otlp_http': {
|
|
587
|
-
const props = properties;
|
|
588
|
-
const commonOpts = {
|
|
589
|
-
compression: props?.compression === 'gzip'
|
|
590
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
591
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
592
|
-
url: props?.endpoint ?? undefined,
|
|
593
|
-
headers: getHeadersFromConfiguration(props?.headers),
|
|
594
|
-
timeoutMillis: validateExporterTimeout(props?.timeout),
|
|
595
|
-
httpAgentOptions: getHttpAgentOptionsFromTls(props?.tls),
|
|
596
|
-
};
|
|
597
|
-
const encoding = props?.encoding ?? 'protobuf';
|
|
598
|
-
switch (encoding) {
|
|
599
|
-
case 'json':
|
|
600
|
-
return new exporter_logs_otlp_http_1.OTLPLogExporter(commonOpts);
|
|
601
|
-
case 'protobuf':
|
|
602
|
-
return new exporter_logs_otlp_proto_1.OTLPLogExporter(commonOpts);
|
|
603
|
-
default:
|
|
604
|
-
throw new Error(`unknown OtlpHttpExporter encoding in configuration: "${encoding}"`);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
case 'otlp_grpc': {
|
|
608
|
-
const props = properties;
|
|
609
|
-
return new exporter_logs_otlp_grpc_1.OTLPLogExporter({
|
|
610
|
-
compression: props?.compression === 'gzip'
|
|
611
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
612
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
613
|
-
url: props?.endpoint ?? undefined,
|
|
614
|
-
timeoutMillis: validateExporterTimeout(props?.timeout),
|
|
615
|
-
credentials: getGrpcCredentialsFromTls(props?.tls),
|
|
616
|
-
metadata: getGrpcMetadataFromHeaders(props?.headers),
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
|
-
case 'console':
|
|
620
|
-
return new sdk_logs_1.ConsoleLogRecordExporter();
|
|
621
|
-
default:
|
|
622
|
-
throw new Error(`unknown LogRecordExporter name in configuration: "${name}"`);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
exports.createLogRecordExporterFromConfig = createLogRecordExporterFromConfig;
|
|
626
|
-
function createLogRecordProcessorFromConfig(processor) {
|
|
627
|
-
const [name, properties] = mustSingleEntry(processor, 'LogRecordProcessor');
|
|
628
|
-
switch (name) {
|
|
629
|
-
case 'batch': {
|
|
630
|
-
const props = properties;
|
|
631
|
-
const exporter = createLogRecordExporterFromConfig(props.exporter);
|
|
632
|
-
return new sdk_logs_1.BatchLogRecordProcessor({
|
|
633
|
-
exporter,
|
|
634
|
-
maxQueueSize: props.max_queue_size ?? undefined,
|
|
635
|
-
maxExportBatchSize: props.max_export_batch_size ?? undefined,
|
|
636
|
-
scheduledDelayMillis: props.schedule_delay ?? undefined,
|
|
637
|
-
exportTimeoutMillis: props.export_timeout ?? undefined,
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
case 'simple': {
|
|
641
|
-
const props = properties;
|
|
642
|
-
const exporter = createLogRecordExporterFromConfig(props.exporter);
|
|
643
|
-
return new sdk_logs_1.SimpleLogRecordProcessor({ exporter });
|
|
644
|
-
}
|
|
645
|
-
default:
|
|
646
|
-
throw new Error(`unknown LogRecordProcessor name: "${name}"`);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
exports.createLogRecordProcessorFromConfig = createLogRecordProcessorFromConfig;
|
|
650
|
-
function getHeadersFromConfiguration(headers) {
|
|
651
|
-
if (!headers) {
|
|
652
|
-
return undefined;
|
|
653
|
-
}
|
|
654
|
-
const result = {};
|
|
655
|
-
headers.forEach(header => {
|
|
656
|
-
if (header.value !== null) {
|
|
657
|
-
result[header.name] = header.value;
|
|
658
|
-
}
|
|
659
|
-
});
|
|
660
|
-
return result;
|
|
661
|
-
}
|
|
662
|
-
exports.getHeadersFromConfiguration = getHeadersFromConfiguration;
|
|
663
|
-
/**
|
|
664
|
-
* Validate an exporter timeout value. The spec says 0 means "no limit
|
|
665
|
-
* (infinity)" but the JS exporters don't support that yet (see #6617).
|
|
666
|
-
* Warn and return undefined so the exporter falls back to its default.
|
|
667
|
-
*/
|
|
668
|
-
function validateExporterTimeout(timeout) {
|
|
669
|
-
if (timeout === null) {
|
|
670
|
-
return undefined;
|
|
671
|
-
}
|
|
672
|
-
else if (timeout === 0) {
|
|
673
|
-
api_1.diag.warn('Exporter timeout of 0 (infinite) is not supported. Using default timeout.');
|
|
674
|
-
return undefined;
|
|
675
|
-
}
|
|
676
|
-
return timeout;
|
|
677
|
-
}
|
|
678
|
-
function getHttpAgentOptionsFromTls(tls) {
|
|
679
|
-
if (tls && (tls.ca_file || tls.cert_file || tls.key_file)) {
|
|
680
|
-
return {
|
|
681
|
-
ca: readFileOrWarn(tls.ca_file, 'TLS CA'),
|
|
682
|
-
cert: readFileOrWarn(tls.cert_file, 'TLS cert'),
|
|
683
|
-
key: readFileOrWarn(tls.key_file, 'TLS key'),
|
|
684
|
-
};
|
|
685
|
-
}
|
|
686
|
-
return undefined;
|
|
687
|
-
}
|
|
688
|
-
exports.getHttpAgentOptionsFromTls = getHttpAgentOptionsFromTls;
|
|
689
|
-
function getGrpcCredentialsFromTls(tls) {
|
|
690
|
-
if (tls?.insecure) {
|
|
691
|
-
return (0, otlp_grpc_exporter_base_1.createInsecureCredentials)();
|
|
692
|
-
}
|
|
693
|
-
const rootCert = readFileOrWarn(tls?.ca_file, 'TLS CA');
|
|
694
|
-
const privateKey = readFileOrWarn(tls?.key_file, 'TLS key');
|
|
695
|
-
const certChain = readFileOrWarn(tls?.cert_file, 'TLS cert');
|
|
696
|
-
if (rootCert || privateKey || certChain) {
|
|
697
|
-
try {
|
|
698
|
-
return (0, otlp_grpc_exporter_base_1.createSslCredentials)(rootCert, privateKey, certChain);
|
|
699
|
-
}
|
|
700
|
-
catch (e) {
|
|
701
|
-
api_1.diag.warn(`Failed to create gRPC SSL credentials: ${e}`);
|
|
702
|
-
return undefined;
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
return undefined;
|
|
706
|
-
}
|
|
707
|
-
function getGrpcMetadataFromHeaders(headers) {
|
|
708
|
-
if (!headers || headers.length === 0) {
|
|
709
|
-
return undefined;
|
|
710
|
-
}
|
|
711
|
-
const metadata = (0, otlp_grpc_exporter_base_1.createEmptyMetadata)();
|
|
712
|
-
for (const header of headers) {
|
|
713
|
-
if (header.value !== null) {
|
|
714
|
-
metadata.set(header.name, header.value);
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
return metadata;
|
|
718
|
-
}
|
|
719
|
-
function readFileOrWarn(filePath, label) {
|
|
720
|
-
if (!filePath)
|
|
721
|
-
return undefined;
|
|
722
|
-
try {
|
|
723
|
-
return fs.readFileSync(filePath);
|
|
724
|
-
}
|
|
725
|
-
catch (e) {
|
|
726
|
-
api_1.diag.warn(`Failed to read ${label} file at ${filePath}: ${e}`);
|
|
727
|
-
return undefined;
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
function getSpanExporter(exporter) {
|
|
731
|
-
if (exporter.otlp_http !== undefined) {
|
|
732
|
-
const encoding = exporter.otlp_http?.encoding ?? 'protobuf';
|
|
733
|
-
if (encoding === 'json') {
|
|
734
|
-
return new exporter_trace_otlp_http_1.OTLPTraceExporter({
|
|
735
|
-
compression: exporter.otlp_http?.compression === 'gzip'
|
|
736
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
737
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
738
|
-
url: exporter.otlp_http?.endpoint ?? undefined,
|
|
739
|
-
headers: getHeadersFromConfiguration(exporter.otlp_http?.headers),
|
|
740
|
-
timeoutMillis: validateExporterTimeout(exporter.otlp_http?.timeout),
|
|
741
|
-
httpAgentOptions: getHttpAgentOptionsFromTls(exporter.otlp_http?.tls),
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
else {
|
|
745
|
-
return new exporter_trace_otlp_proto_1.OTLPTraceExporter({
|
|
746
|
-
compression: exporter.otlp_http?.compression === 'gzip'
|
|
747
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
748
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
749
|
-
url: exporter.otlp_http?.endpoint ?? undefined,
|
|
750
|
-
headers: getHeadersFromConfiguration(exporter.otlp_http?.headers),
|
|
751
|
-
timeoutMillis: validateExporterTimeout(exporter.otlp_http?.timeout),
|
|
752
|
-
httpAgentOptions: getHttpAgentOptionsFromTls(exporter.otlp_http?.tls),
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
else if (exporter.otlp_grpc !== undefined) {
|
|
757
|
-
return new exporter_trace_otlp_grpc_1.OTLPTraceExporter({
|
|
758
|
-
compression: exporter.otlp_grpc?.compression === 'gzip'
|
|
759
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
760
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
761
|
-
url: exporter.otlp_grpc?.endpoint ?? undefined,
|
|
762
|
-
timeoutMillis: validateExporterTimeout(exporter.otlp_grpc?.timeout),
|
|
763
|
-
credentials: getGrpcCredentialsFromTls(exporter.otlp_grpc?.tls),
|
|
764
|
-
metadata: getGrpcMetadataFromHeaders(exporter.otlp_grpc?.headers),
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
else if (exporter.console !== undefined) {
|
|
768
|
-
return new sdk_trace_1.ConsoleSpanExporter();
|
|
769
|
-
}
|
|
770
|
-
api_1.diag.warn('Unsupported Exporter value. No Span Exporter registered');
|
|
771
|
-
return undefined;
|
|
772
|
-
}
|
|
773
|
-
exports.getSpanExporter = getSpanExporter;
|
|
774
|
-
function getSpanProcessorsFromConfiguration(config) {
|
|
775
|
-
const spanProcessors = [];
|
|
776
|
-
config.tracer_provider?.processors?.forEach(processor => {
|
|
777
|
-
if (processor.batch) {
|
|
778
|
-
const exporter = getSpanExporter(processor.batch.exporter);
|
|
779
|
-
if (exporter) {
|
|
780
|
-
spanProcessors.push(new sdk_trace_1.BatchSpanProcessor({
|
|
781
|
-
exporter,
|
|
782
|
-
maxQueueSize: processor.batch.max_queue_size ?? undefined,
|
|
783
|
-
maxExportBatchSize: processor.batch.max_export_batch_size ?? undefined,
|
|
784
|
-
scheduledDelayMillis: processor.batch.schedule_delay ?? undefined,
|
|
785
|
-
exportTimeoutMillis: processor.batch.export_timeout ?? undefined,
|
|
786
|
-
}));
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
if (processor.simple) {
|
|
790
|
-
const exporter = getSpanExporter(processor.simple.exporter);
|
|
791
|
-
if (exporter) {
|
|
792
|
-
spanProcessors.push(new sdk_trace_1.SimpleSpanProcessor({ exporter }));
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
});
|
|
796
|
-
if (spanProcessors.length > 0) {
|
|
797
|
-
return spanProcessors;
|
|
798
|
-
}
|
|
799
|
-
return undefined;
|
|
800
|
-
}
|
|
801
|
-
exports.getSpanProcessorsFromConfiguration = getSpanProcessorsFromConfiguration;
|
|
802
|
-
function getIdGeneratorFromConfiguration(config) {
|
|
803
|
-
const idGenerator = config.tracer_provider?.id_generator;
|
|
804
|
-
if (!idGenerator) {
|
|
805
|
-
return undefined;
|
|
806
|
-
}
|
|
807
|
-
if (idGenerator.random !== undefined) {
|
|
808
|
-
return new sdk_trace_1.RandomIdGenerator();
|
|
809
|
-
}
|
|
810
|
-
// Any other key is a third-party / custom id_generator type which we
|
|
811
|
-
// don't currently support. Warn and fall back to SDK default.
|
|
812
|
-
const unknownKeys = Object.keys(idGenerator).filter(k => k !== 'random');
|
|
813
|
-
if (unknownKeys.length > 0) {
|
|
814
|
-
api_1.diag.warn(`Unsupported id_generator type(s): ${unknownKeys.join(', ')}. Using default.`);
|
|
815
|
-
}
|
|
816
|
-
return undefined;
|
|
817
|
-
}
|
|
818
|
-
exports.getIdGeneratorFromConfiguration = getIdGeneratorFromConfiguration;
|
|
819
|
-
function getMeterReadersFromConfiguration(config) {
|
|
820
|
-
const metricReaders = [];
|
|
821
|
-
config.meter_provider?.readers?.forEach(reader => {
|
|
822
|
-
if (reader.periodic) {
|
|
823
|
-
const periodicReader = getPeriodicMetricReaderFromConfiguration(reader.periodic);
|
|
824
|
-
if (periodicReader) {
|
|
825
|
-
metricReaders.push(periodicReader);
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
});
|
|
829
|
-
if (metricReaders.length > 0) {
|
|
830
|
-
return metricReaders;
|
|
831
|
-
}
|
|
832
|
-
return undefined;
|
|
833
|
-
}
|
|
834
|
-
exports.getMeterReadersFromConfiguration = getMeterReadersFromConfiguration;
|
|
835
|
-
function getInstrumentType(instrument) {
|
|
836
|
-
switch (instrument) {
|
|
837
|
-
case 'counter':
|
|
838
|
-
return sdk_metrics_1.InstrumentType.COUNTER;
|
|
839
|
-
case 'gauge':
|
|
840
|
-
return sdk_metrics_1.InstrumentType.GAUGE;
|
|
841
|
-
case 'histogram':
|
|
842
|
-
return sdk_metrics_1.InstrumentType.HISTOGRAM;
|
|
843
|
-
case 'observable_counter':
|
|
844
|
-
return sdk_metrics_1.InstrumentType.OBSERVABLE_COUNTER;
|
|
845
|
-
case 'observable_gauge':
|
|
846
|
-
return sdk_metrics_1.InstrumentType.OBSERVABLE_GAUGE;
|
|
847
|
-
case 'observable_up_down_counter':
|
|
848
|
-
return sdk_metrics_1.InstrumentType.OBSERVABLE_UP_DOWN_COUNTER;
|
|
849
|
-
case 'up_down_counter':
|
|
850
|
-
return sdk_metrics_1.InstrumentType.UP_DOWN_COUNTER;
|
|
851
|
-
default:
|
|
852
|
-
api_1.diag.warn(`Unsupported instrument type: ${instrument}`);
|
|
853
|
-
return undefined;
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
exports.getInstrumentType = getInstrumentType;
|
|
857
|
-
function getAggregationType(aggregation) {
|
|
858
|
-
if (aggregation.default) {
|
|
859
|
-
return {
|
|
860
|
-
type: sdk_metrics_1.AggregationType.DEFAULT,
|
|
861
|
-
};
|
|
862
|
-
}
|
|
863
|
-
if (aggregation.drop) {
|
|
864
|
-
return {
|
|
865
|
-
type: sdk_metrics_1.AggregationType.DROP,
|
|
866
|
-
};
|
|
867
|
-
}
|
|
868
|
-
if (aggregation.explicit_bucket_histogram) {
|
|
869
|
-
return {
|
|
870
|
-
type: sdk_metrics_1.AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
|
|
871
|
-
options: {
|
|
872
|
-
recordMinMax: aggregation.explicit_bucket_histogram.record_min_max ?? true,
|
|
873
|
-
boundaries: aggregation.explicit_bucket_histogram.boundaries ?? [
|
|
874
|
-
0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500,
|
|
875
|
-
10000,
|
|
876
|
-
],
|
|
877
|
-
},
|
|
878
|
-
};
|
|
879
|
-
}
|
|
880
|
-
if (aggregation.base2_exponential_bucket_histogram) {
|
|
881
|
-
return {
|
|
882
|
-
type: sdk_metrics_1.AggregationType.EXPONENTIAL_HISTOGRAM,
|
|
883
|
-
options: {
|
|
884
|
-
recordMinMax: aggregation.base2_exponential_bucket_histogram.record_min_max ??
|
|
885
|
-
undefined,
|
|
886
|
-
maxSize: aggregation.base2_exponential_bucket_histogram.max_size ?? undefined,
|
|
887
|
-
},
|
|
888
|
-
};
|
|
889
|
-
}
|
|
890
|
-
if (aggregation.last_value) {
|
|
891
|
-
return {
|
|
892
|
-
type: sdk_metrics_1.AggregationType.LAST_VALUE,
|
|
893
|
-
};
|
|
894
|
-
}
|
|
895
|
-
if (aggregation.sum) {
|
|
896
|
-
return {
|
|
897
|
-
type: sdk_metrics_1.AggregationType.SUM,
|
|
898
|
-
};
|
|
899
|
-
}
|
|
900
|
-
api_1.diag.warn('Unsupported aggregation type');
|
|
901
|
-
return undefined;
|
|
902
|
-
}
|
|
903
|
-
exports.getAggregationType = getAggregationType;
|
|
904
|
-
function getMeterViewsFromConfiguration(config) {
|
|
905
|
-
const metricViews = [];
|
|
906
|
-
config.meter_provider?.views?.forEach(view => {
|
|
907
|
-
const viewOption = {};
|
|
908
|
-
if (view.selector) {
|
|
909
|
-
if (view.selector.instrument_name) {
|
|
910
|
-
viewOption.instrumentName = view.selector.instrument_name;
|
|
911
|
-
}
|
|
912
|
-
if (view.selector.instrument_type) {
|
|
913
|
-
const instrumentType = getInstrumentType(view.selector.instrument_type);
|
|
914
|
-
if (instrumentType) {
|
|
915
|
-
viewOption.instrumentType = instrumentType;
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
if (view.selector.unit) {
|
|
919
|
-
viewOption.instrumentUnit = view.selector.unit;
|
|
920
|
-
}
|
|
921
|
-
if (view.selector.meter_name) {
|
|
922
|
-
viewOption.meterName = view.selector.meter_name;
|
|
923
|
-
}
|
|
924
|
-
if (view.selector.meter_version) {
|
|
925
|
-
viewOption.meterVersion = view.selector.meter_version;
|
|
926
|
-
}
|
|
927
|
-
if (view.selector.meter_schema_url) {
|
|
928
|
-
viewOption.meterSchemaUrl = view.selector.meter_schema_url;
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
if (view.stream) {
|
|
932
|
-
if (view.stream.name) {
|
|
933
|
-
viewOption.name = view.stream.name;
|
|
934
|
-
}
|
|
935
|
-
viewOption.aggregationCardinalityLimit =
|
|
936
|
-
view.stream.aggregation_cardinality_limit ?? 2000;
|
|
937
|
-
if (view.stream.description) {
|
|
938
|
-
viewOption.description = view.stream.description;
|
|
939
|
-
}
|
|
940
|
-
if (view.stream.aggregation) {
|
|
941
|
-
const aggregationType = getAggregationType(view.stream.aggregation);
|
|
942
|
-
if (aggregationType) {
|
|
943
|
-
viewOption.aggregation = aggregationType;
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
if (view.stream.attribute_keys) {
|
|
947
|
-
const processors = [];
|
|
948
|
-
if (view.stream.attribute_keys.included &&
|
|
949
|
-
view.stream.attribute_keys.included.length > 0) {
|
|
950
|
-
processors.push((0, sdk_metrics_1.createAllowListAttributesProcessor)(view.stream.attribute_keys.included));
|
|
951
|
-
}
|
|
952
|
-
if (view.stream.attribute_keys.excluded &&
|
|
953
|
-
view.stream.attribute_keys.excluded.length > 0) {
|
|
954
|
-
processors.push((0, sdk_metrics_1.createDenyListAttributesProcessor)(view.stream.attribute_keys.excluded));
|
|
955
|
-
}
|
|
956
|
-
if (processors.length > 0) {
|
|
957
|
-
viewOption.attributesProcessors = processors;
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
if (Object.keys(viewOption).length > 0) {
|
|
962
|
-
metricViews.push(viewOption);
|
|
963
|
-
}
|
|
964
|
-
});
|
|
965
|
-
if (metricViews.length > 0) {
|
|
966
|
-
return metricViews;
|
|
967
|
-
}
|
|
968
|
-
return undefined;
|
|
969
|
-
}
|
|
970
|
-
exports.getMeterViewsFromConfiguration = getMeterViewsFromConfiguration;
|
|
971
315
|
function getInstanceID(config) {
|
|
972
316
|
if (config.resource?.attributes) {
|
|
973
317
|
for (let i = 0; i < config.resource.attributes.length; i++) {
|
|
@@ -980,101 +324,4 @@ function getInstanceID(config) {
|
|
|
980
324
|
return undefined;
|
|
981
325
|
}
|
|
982
326
|
exports.getInstanceID = getInstanceID;
|
|
983
|
-
const DEFAULT_RATIO = 1;
|
|
984
|
-
/**
|
|
985
|
-
* Returns the {@link Sampler} configured under `tracer_provider.sampler` in
|
|
986
|
-
* the declarative configuration, or `undefined` if none is set (in which case
|
|
987
|
-
* the SDK applies its default sampler).
|
|
988
|
-
*/
|
|
989
|
-
function getSamplerFromConfiguration(config) {
|
|
990
|
-
const samplerConfig = config.tracer_provider?.sampler;
|
|
991
|
-
if (!samplerConfig) {
|
|
992
|
-
return undefined;
|
|
993
|
-
}
|
|
994
|
-
return buildSamplerFromConfig(samplerConfig);
|
|
995
|
-
}
|
|
996
|
-
exports.getSamplerFromConfiguration = getSamplerFromConfiguration;
|
|
997
|
-
/**
|
|
998
|
-
* Builds a {@link Sampler} from a {@link SamplerConfigModel} data model.
|
|
999
|
-
* This allows sampler construction from declarative configuration.
|
|
1000
|
-
*/
|
|
1001
|
-
function buildSamplerFromConfig(samplerConfig) {
|
|
1002
|
-
if (samplerConfig.always_on !== undefined) {
|
|
1003
|
-
return new sdk_trace_1.AlwaysOnSampler();
|
|
1004
|
-
}
|
|
1005
|
-
if (samplerConfig.always_off !== undefined) {
|
|
1006
|
-
return new sdk_trace_1.AlwaysOffSampler();
|
|
1007
|
-
}
|
|
1008
|
-
if (samplerConfig.trace_id_ratio_based !== undefined) {
|
|
1009
|
-
return new sdk_trace_1.TraceIdRatioBasedSampler(samplerConfig.trace_id_ratio_based?.ratio ?? DEFAULT_RATIO);
|
|
1010
|
-
}
|
|
1011
|
-
if (samplerConfig.parent_based !== undefined) {
|
|
1012
|
-
const pb = samplerConfig.parent_based ?? {};
|
|
1013
|
-
return new sdk_trace_1.ParentBasedSampler({
|
|
1014
|
-
root: pb.root ? buildSamplerFromConfig(pb.root) : new sdk_trace_1.AlwaysOnSampler(),
|
|
1015
|
-
remoteParentSampled: pb.remote_parent_sampled
|
|
1016
|
-
? buildSamplerFromConfig(pb.remote_parent_sampled)
|
|
1017
|
-
: undefined,
|
|
1018
|
-
remoteParentNotSampled: pb.remote_parent_not_sampled
|
|
1019
|
-
? buildSamplerFromConfig(pb.remote_parent_not_sampled)
|
|
1020
|
-
: undefined,
|
|
1021
|
-
localParentSampled: pb.local_parent_sampled
|
|
1022
|
-
? buildSamplerFromConfig(pb.local_parent_sampled)
|
|
1023
|
-
: undefined,
|
|
1024
|
-
localParentNotSampled: pb.local_parent_not_sampled
|
|
1025
|
-
? buildSamplerFromConfig(pb.local_parent_not_sampled)
|
|
1026
|
-
: undefined,
|
|
1027
|
-
});
|
|
1028
|
-
}
|
|
1029
|
-
api_1.diag.warn('Unknown sampler config, defaulting to ParentBased(AlwaysOn).');
|
|
1030
|
-
return new sdk_trace_1.ParentBasedSampler({ root: new sdk_trace_1.AlwaysOnSampler() });
|
|
1031
|
-
}
|
|
1032
|
-
exports.buildSamplerFromConfig = buildSamplerFromConfig;
|
|
1033
|
-
/**
|
|
1034
|
-
* Warn if some props from a declarative config object have not been handled.
|
|
1035
|
-
*
|
|
1036
|
-
* This is intended to be used by `create*FromConfig()` functions. It is a low
|
|
1037
|
-
* tech mechanism to add awareness when a given valid config is not being
|
|
1038
|
-
* completely handled. This could help when properties are added to the
|
|
1039
|
-
* configuration schema. (A higher tech mechanism that wraps the parsed
|
|
1040
|
-
* configuration during `create()` and watches for untouched properties
|
|
1041
|
-
* might be nice.)
|
|
1042
|
-
*/
|
|
1043
|
-
function checkConfigUse(name, props, handledProps) {
|
|
1044
|
-
if (!props)
|
|
1045
|
-
return;
|
|
1046
|
-
// Dev note: I'd use Set#difference, but that requires Node.js v22.
|
|
1047
|
-
const unhandledProps = Object.keys(props).filter(k => !handledProps.includes(k));
|
|
1048
|
-
if (unhandledProps.length > 0) {
|
|
1049
|
-
api_1.diag.warn(`Config warning: some specified ${name} configuration properties were not handled by SDK setup: ${JSON.stringify(unhandledProps)}`);
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
/**
|
|
1053
|
-
* Return the single non-undefined entry in the given config object, or throw.
|
|
1054
|
-
*
|
|
1055
|
-
* It is common for Declarative Configuration to have config objects with
|
|
1056
|
-
* a single entry, e.g.
|
|
1057
|
-
*
|
|
1058
|
-
* "LogRecordProcessor": {
|
|
1059
|
-
* "type": "object",
|
|
1060
|
-
* "additionalProperties": {
|
|
1061
|
-
* "type": [
|
|
1062
|
-
* "object",
|
|
1063
|
-
* "null"
|
|
1064
|
-
* ]
|
|
1065
|
-
* },
|
|
1066
|
-
* "minProperties": 1,
|
|
1067
|
-
* "maxProperties": 1,
|
|
1068
|
-
*
|
|
1069
|
-
* The TypeScript types cannot express the minProperties/maxProperties from the
|
|
1070
|
-
* JSON schema. We guard against that here.
|
|
1071
|
-
*/
|
|
1072
|
-
function mustSingleEntry(configObj, configTypeName) {
|
|
1073
|
-
const entries = Object.entries(configObj).filter(([_name, properties]) => properties !== undefined);
|
|
1074
|
-
if (entries.length !== 1) {
|
|
1075
|
-
const entryNames = entries.map(e => e[0]);
|
|
1076
|
-
throw Error(`invalid ${configTypeName} in configuration: must have exactly one entry: entries=${JSON.stringify(entryNames)}`);
|
|
1077
|
-
}
|
|
1078
|
-
return entries[0];
|
|
1079
|
-
}
|
|
1080
327
|
//# sourceMappingURL=utils.js.map
|