@opentelemetry/sdk-node 0.219.0 → 0.221.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/README.md +31 -9
- package/build/src/create-from-config.d.ts +11 -0
- package/build/src/create-from-config.js +207 -0
- package/build/src/create-from-config.js.map +1 -0
- package/build/src/create-from-env.d.ts +11 -0
- package/build/src/create-from-env.js +80 -0
- package/build/src/create-from-env.js.map +1 -0
- package/build/src/index.d.ts +7 -1
- package/build/src/index.js +8 -2
- package/build/src/index.js.map +1 -1
- package/build/src/sdk.d.ts +0 -1
- package/build/src/sdk.js +36 -38
- package/build/src/sdk.js.map +1 -1
- package/build/src/start.js +65 -51
- package/build/src/start.js.map +1 -1
- package/build/src/types.d.ts +12 -4
- package/build/src/types.js.map +1 -1
- package/build/src/utils.d.ts +24 -11
- package/build/src/utils.js +241 -195
- 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 +30 -29
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.buildSamplerFromConfig = exports.getInstanceID = exports.getMeterViewsFromConfiguration = exports.getAggregationType = exports.getInstrumentType = exports.getMeterReadersFromConfiguration = exports.
|
|
7
|
+
exports.buildSamplerFromConfig = exports.getSamplerFromConfiguration = exports.getInstanceID = exports.getMeterViewsFromConfiguration = exports.getAggregationType = exports.getInstrumentType = exports.getMeterReadersFromConfiguration = exports.getIdGeneratorFromConfiguration = exports.getSpanProcessorsFromConfiguration = exports.getSpanExporter = exports.getGrpcMetadataFromHeaders = exports.getGrpcCredentialsFromTls = exports.getHttpAgentOptionsFromTls = exports.validateExporterTimeout = exports.getHeadersFromConfiguration = exports.getBatchLogRecordProcessorFromEnv = exports.getBatchLogRecordProcessorConfigFromEnv = exports.getLoggerProviderConfigFromEnv = exports.getPeriodicMetricReaderFromConfiguration = exports.getMetricExporter = exports.getOtlpMetricExporterFromEnv = exports.getPeriodicExportingMetricReaderFromEnv = exports.getNonNegativeNumberFromEnv = exports.getKeyListFromObjectArray = exports.setupPropagator = exports.setupContextManager = exports.getPropagatorFromConfiguration = exports.getPropagatorFromEnv = exports.getSpanProcessorsFromEnv = exports.getOtlpProtocolFromEnv = exports.getResourceDetectorsFromConfiguration = exports.getResourceDetectorsFromEnv = exports.getResourceFromConfiguration = 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");
|
|
@@ -12,42 +12,45 @@ const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-h
|
|
|
12
12
|
const exporter_trace_otlp_grpc_1 = require("@opentelemetry/exporter-trace-otlp-grpc");
|
|
13
13
|
const exporter_zipkin_1 = require("@opentelemetry/exporter-zipkin");
|
|
14
14
|
const resources_1 = require("@opentelemetry/resources");
|
|
15
|
-
const
|
|
15
|
+
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
19
|
const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
|
|
23
20
|
const otlp_grpc_exporter_base_1 = require("@opentelemetry/otlp-grpc-exporter-base");
|
|
21
|
+
const configuration_1 = require("@opentelemetry/configuration");
|
|
24
22
|
const sdk_metrics_1 = require("@opentelemetry/sdk-metrics");
|
|
25
23
|
const exporter_metrics_otlp_grpc_1 = require("@opentelemetry/exporter-metrics-otlp-grpc");
|
|
26
24
|
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");
|
|
27
26
|
const exporter_metrics_otlp_proto_1 = require("@opentelemetry/exporter-metrics-otlp-proto");
|
|
28
27
|
const sdk_logs_1 = require("@opentelemetry/sdk-logs");
|
|
29
28
|
const fs = require("fs");
|
|
29
|
+
const util_1 = require("util");
|
|
30
|
+
const create_from_env_1 = require("./create-from-env");
|
|
30
31
|
const RESOURCE_DETECTOR_ENVIRONMENT = 'env';
|
|
31
32
|
const RESOURCE_DETECTOR_HOST = 'host';
|
|
32
33
|
const RESOURCE_DETECTOR_OS = 'os';
|
|
33
34
|
const RESOURCE_DETECTOR_PROCESS = 'process';
|
|
34
35
|
const RESOURCE_DETECTOR_SERVICE_INSTANCE_ID = 'serviceinstance';
|
|
35
36
|
function getResourceFromConfiguration(config) {
|
|
36
|
-
if (config.resource
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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;
|
|
45
49
|
}
|
|
46
|
-
return (0, resources_1.resourceFromAttributes)(attrs, {
|
|
47
|
-
schemaUrl: config.resource.schema_url ?? undefined,
|
|
48
|
-
});
|
|
49
50
|
}
|
|
50
|
-
return
|
|
51
|
+
return (0, resources_1.resourceFromAttributes)(attrs, {
|
|
52
|
+
schemaUrl: config.resource.schema_url ?? undefined,
|
|
53
|
+
});
|
|
51
54
|
}
|
|
52
55
|
exports.getResourceFromConfiguration = getResourceFromConfiguration;
|
|
53
56
|
function getResourceDetectorsFromEnv() {
|
|
@@ -113,11 +116,11 @@ function getOtlpExporterFromEnv() {
|
|
|
113
116
|
return new exporter_trace_otlp_proto_1.OTLPTraceExporter();
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
|
-
function getSpanProcessorsFromEnv() {
|
|
119
|
+
function getSpanProcessorsFromEnv(selfObsMeterProvider) {
|
|
117
120
|
const exportersMap = new Map([
|
|
118
121
|
['otlp', () => getOtlpExporterFromEnv()],
|
|
119
122
|
['zipkin', () => new exporter_zipkin_1.ZipkinExporter()],
|
|
120
|
-
['console', () => new
|
|
123
|
+
['console', () => new sdk_trace_1.ConsoleSpanExporter()],
|
|
121
124
|
]);
|
|
122
125
|
const exporters = [];
|
|
123
126
|
const processors = [];
|
|
@@ -145,11 +148,11 @@ function getSpanProcessorsFromEnv() {
|
|
|
145
148
|
}
|
|
146
149
|
}
|
|
147
150
|
for (const exp of exporters) {
|
|
148
|
-
if (exp instanceof
|
|
149
|
-
processors.push(new
|
|
151
|
+
if (exp instanceof sdk_trace_1.ConsoleSpanExporter) {
|
|
152
|
+
processors.push(new sdk_trace_1.SimpleSpanProcessor({ exporter: exp, selfObsMeterProvider }));
|
|
150
153
|
}
|
|
151
154
|
else {
|
|
152
|
-
processors.push(
|
|
155
|
+
processors.push((0, create_from_env_1.createBatchSpanProcessorFromEnv)(exp, selfObsMeterProvider));
|
|
153
156
|
}
|
|
154
157
|
}
|
|
155
158
|
if (exporters.length === 0) {
|
|
@@ -181,7 +184,13 @@ function getPropagatorFromEnv() {
|
|
|
181
184
|
'b3multi',
|
|
182
185
|
() => new propagator_b3_1.B3Propagator({ injectEncoding: propagator_b3_1.B3InjectEncoding.MULTI_HEADER }),
|
|
183
186
|
],
|
|
184
|
-
[
|
|
187
|
+
[
|
|
188
|
+
'jaeger',
|
|
189
|
+
() => {
|
|
190
|
+
api_1.diag.warn('The Jaeger propagator is deprecated and will be removed in a future release. Use the W3C TraceContext propagator ("tracecontext") instead.');
|
|
191
|
+
return new propagator_jaeger_1.JaegerPropagator();
|
|
192
|
+
},
|
|
193
|
+
],
|
|
185
194
|
]);
|
|
186
195
|
// Values MUST be deduplicated in order to register a Propagator only once.
|
|
187
196
|
const uniquePropagatorNames = Array.from(new Set(propagatorsEnvVarValue));
|
|
@@ -212,13 +221,50 @@ exports.getPropagatorFromEnv = getPropagatorFromEnv;
|
|
|
212
221
|
* Get a propagator as defined by configuration model from configuration
|
|
213
222
|
*/
|
|
214
223
|
function getPropagatorFromConfiguration(config) {
|
|
215
|
-
|
|
216
|
-
if (propagatorsValue == null) {
|
|
217
|
-
// return undefined to fall back to default
|
|
224
|
+
if (!config.propagator) {
|
|
218
225
|
return undefined;
|
|
219
226
|
}
|
|
220
|
-
|
|
221
|
-
|
|
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
|
+
}
|
|
222
268
|
}
|
|
223
269
|
// Implementation note: this only contains specification required propagators that are actually hosted in this repo.
|
|
224
270
|
// Any other propagators (like aws, aws-lambda, should go into `@opentelemetry/auto-configuration-propagators` instead).
|
|
@@ -230,24 +276,27 @@ function getPropagatorFromConfiguration(config) {
|
|
|
230
276
|
'b3multi',
|
|
231
277
|
() => new propagator_b3_1.B3Propagator({ injectEncoding: propagator_b3_1.B3InjectEncoding.MULTI_HEADER }),
|
|
232
278
|
],
|
|
233
|
-
[
|
|
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
|
+
],
|
|
234
286
|
]);
|
|
235
|
-
// Values MUST be deduplicated in order to register a Propagator only once.
|
|
236
|
-
const uniquePropagatorNames = Array.from(new Set(propagatorsValue));
|
|
237
287
|
const validPropagators = [];
|
|
238
|
-
|
|
288
|
+
for (const [name] of kvs) {
|
|
239
289
|
const propagator = propagatorsFactory.get(name)?.();
|
|
240
290
|
if (!propagator) {
|
|
241
291
|
api_1.diag.warn(`Propagator "${name}" requested through configuration is unavailable.`);
|
|
242
|
-
|
|
292
|
+
continue;
|
|
243
293
|
}
|
|
244
294
|
validPropagators.push(propagator);
|
|
245
|
-
}
|
|
295
|
+
}
|
|
246
296
|
if (validPropagators.length === 0) {
|
|
247
|
-
|
|
248
|
-
return null;
|
|
297
|
+
return undefined;
|
|
249
298
|
}
|
|
250
|
-
else if (
|
|
299
|
+
else if (validPropagators.length === 1) {
|
|
251
300
|
return validPropagators[0];
|
|
252
301
|
}
|
|
253
302
|
else {
|
|
@@ -369,73 +418,120 @@ function getMetricProducersFromConfiguration(producers) {
|
|
|
369
418
|
}
|
|
370
419
|
const result = [];
|
|
371
420
|
for (const producer of producers) {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
376
|
-
} = require('@opentelemetry/shim-opencensus');
|
|
377
|
-
result.push(new OpenCensusMetricProducer());
|
|
378
|
-
}
|
|
379
|
-
catch {
|
|
380
|
-
api_1.diag.warn('OpenCensus metric producer configured but @opentelemetry/shim-opencensus is not installed.');
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
api_1.diag.warn('Unsupported metric producer configured.');
|
|
385
|
-
}
|
|
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.`);
|
|
386
424
|
}
|
|
387
425
|
return result.length > 0 ? result : undefined;
|
|
388
426
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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();
|
|
435
512
|
}
|
|
436
513
|
api_1.diag.warn('Unsupported Metric Exporter.');
|
|
437
514
|
return undefined;
|
|
438
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
|
+
}
|
|
439
535
|
exports.getPeriodicMetricReaderFromConfiguration = getPeriodicMetricReaderFromConfiguration;
|
|
440
536
|
/**
|
|
441
537
|
* Get LoggerProviderConfig from environment variables.
|
|
@@ -462,78 +558,14 @@ function getBatchLogRecordProcessorConfigFromEnv() {
|
|
|
462
558
|
};
|
|
463
559
|
}
|
|
464
560
|
exports.getBatchLogRecordProcessorConfigFromEnv = getBatchLogRecordProcessorConfigFromEnv;
|
|
465
|
-
function getBatchLogRecordProcessorFromEnv(exporter) {
|
|
466
|
-
return new sdk_logs_1.BatchLogRecordProcessor(
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
if (exporter.otlp_http !== undefined) {
|
|
471
|
-
const cfg = exporter.otlp_http;
|
|
472
|
-
const commonOpts = {
|
|
473
|
-
compression: cfg?.compression === 'gzip'
|
|
474
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
475
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
476
|
-
url: cfg?.endpoint ?? undefined,
|
|
477
|
-
headers: getHeadersFromConfiguration(cfg?.headers),
|
|
478
|
-
timeoutMillis: validateExporterTimeout(cfg?.timeout),
|
|
479
|
-
httpAgentOptions: getHttpAgentOptionsFromTls(cfg?.tls),
|
|
480
|
-
};
|
|
481
|
-
const encoding = cfg?.encoding ?? 'protobuf';
|
|
482
|
-
if (encoding === 'json') {
|
|
483
|
-
return new exporter_logs_otlp_http_1.OTLPLogExporter(commonOpts);
|
|
484
|
-
}
|
|
485
|
-
if (encoding === 'protobuf') {
|
|
486
|
-
return new exporter_logs_otlp_proto_1.OTLPLogExporter(commonOpts);
|
|
487
|
-
}
|
|
488
|
-
api_1.diag.warn(`Unsupported OTLP logs encoding: ${encoding}. Using http/protobuf.`);
|
|
489
|
-
return new exporter_logs_otlp_proto_1.OTLPLogExporter(commonOpts);
|
|
490
|
-
}
|
|
491
|
-
else if (exporter.otlp_grpc !== undefined) {
|
|
492
|
-
const cfg = exporter.otlp_grpc;
|
|
493
|
-
return new exporter_logs_otlp_grpc_1.OTLPLogExporter({
|
|
494
|
-
compression: cfg?.compression === 'gzip'
|
|
495
|
-
? otlp_exporter_base_1.CompressionAlgorithm.GZIP
|
|
496
|
-
: otlp_exporter_base_1.CompressionAlgorithm.NONE,
|
|
497
|
-
url: cfg?.endpoint ?? undefined,
|
|
498
|
-
timeoutMillis: validateExporterTimeout(cfg?.timeout),
|
|
499
|
-
credentials: getGrpcCredentialsFromTls(cfg?.tls),
|
|
500
|
-
metadata: getGrpcMetadataFromHeaders(cfg?.headers),
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
else if (exporter.console !== undefined) {
|
|
504
|
-
return new sdk_logs_1.ConsoleLogRecordExporter();
|
|
505
|
-
}
|
|
506
|
-
api_1.diag.warn('Unsupported Exporter value. No Log Record Exporter registered');
|
|
507
|
-
return undefined;
|
|
508
|
-
}
|
|
509
|
-
exports.getLogRecordExporter = getLogRecordExporter;
|
|
510
|
-
function getLogRecordProcessorsFromConfiguration(config) {
|
|
511
|
-
const logRecordProcessors = [];
|
|
512
|
-
config.logger_provider?.processors?.forEach(processor => {
|
|
513
|
-
if (processor.batch) {
|
|
514
|
-
const exporter = getLogRecordExporter(processor.batch.exporter);
|
|
515
|
-
if (exporter) {
|
|
516
|
-
logRecordProcessors.push(new sdk_logs_1.BatchLogRecordProcessor(exporter, {
|
|
517
|
-
maxQueueSize: processor.batch.max_queue_size ?? undefined,
|
|
518
|
-
maxExportBatchSize: processor.batch.max_export_batch_size ?? undefined,
|
|
519
|
-
scheduledDelayMillis: processor.batch.schedule_delay ?? undefined,
|
|
520
|
-
exportTimeoutMillis: processor.batch.export_timeout ?? undefined,
|
|
521
|
-
}));
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
if (processor.simple) {
|
|
525
|
-
const exporter = getLogRecordExporter(processor.simple.exporter);
|
|
526
|
-
if (exporter) {
|
|
527
|
-
logRecordProcessors.push(new sdk_logs_1.SimpleLogRecordProcessor(exporter));
|
|
528
|
-
}
|
|
529
|
-
}
|
|
561
|
+
function getBatchLogRecordProcessorFromEnv(exporter, selfObsMeterProvider) {
|
|
562
|
+
return new sdk_logs_1.BatchLogRecordProcessor({
|
|
563
|
+
exporter,
|
|
564
|
+
selfObsMeterProvider,
|
|
565
|
+
...getBatchLogRecordProcessorConfigFromEnv(),
|
|
530
566
|
});
|
|
531
|
-
if (logRecordProcessors.length > 0) {
|
|
532
|
-
return logRecordProcessors;
|
|
533
|
-
}
|
|
534
|
-
return undefined;
|
|
535
567
|
}
|
|
536
|
-
exports.
|
|
568
|
+
exports.getBatchLogRecordProcessorFromEnv = getBatchLogRecordProcessorFromEnv;
|
|
537
569
|
function getHeadersFromConfiguration(headers) {
|
|
538
570
|
if (!headers) {
|
|
539
571
|
return undefined;
|
|
@@ -562,6 +594,7 @@ function validateExporterTimeout(timeout) {
|
|
|
562
594
|
}
|
|
563
595
|
return timeout;
|
|
564
596
|
}
|
|
597
|
+
exports.validateExporterTimeout = validateExporterTimeout;
|
|
565
598
|
function getHttpAgentOptionsFromTls(tls) {
|
|
566
599
|
if (tls && (tls.ca_file || tls.cert_file || tls.key_file)) {
|
|
567
600
|
return {
|
|
@@ -591,6 +624,7 @@ function getGrpcCredentialsFromTls(tls) {
|
|
|
591
624
|
}
|
|
592
625
|
return undefined;
|
|
593
626
|
}
|
|
627
|
+
exports.getGrpcCredentialsFromTls = getGrpcCredentialsFromTls;
|
|
594
628
|
function getGrpcMetadataFromHeaders(headers) {
|
|
595
629
|
if (!headers || headers.length === 0) {
|
|
596
630
|
return undefined;
|
|
@@ -603,6 +637,7 @@ function getGrpcMetadataFromHeaders(headers) {
|
|
|
603
637
|
}
|
|
604
638
|
return metadata;
|
|
605
639
|
}
|
|
640
|
+
exports.getGrpcMetadataFromHeaders = getGrpcMetadataFromHeaders;
|
|
606
641
|
function readFileOrWarn(filePath, label) {
|
|
607
642
|
if (!filePath)
|
|
608
643
|
return undefined;
|
|
@@ -652,7 +687,7 @@ function getSpanExporter(exporter) {
|
|
|
652
687
|
});
|
|
653
688
|
}
|
|
654
689
|
else if (exporter.console !== undefined) {
|
|
655
|
-
return new
|
|
690
|
+
return new sdk_trace_1.ConsoleSpanExporter();
|
|
656
691
|
}
|
|
657
692
|
api_1.diag.warn('Unsupported Exporter value. No Span Exporter registered');
|
|
658
693
|
return undefined;
|
|
@@ -664,7 +699,8 @@ function getSpanProcessorsFromConfiguration(config) {
|
|
|
664
699
|
if (processor.batch) {
|
|
665
700
|
const exporter = getSpanExporter(processor.batch.exporter);
|
|
666
701
|
if (exporter) {
|
|
667
|
-
spanProcessors.push(new
|
|
702
|
+
spanProcessors.push(new sdk_trace_1.BatchSpanProcessor({
|
|
703
|
+
exporter,
|
|
668
704
|
maxQueueSize: processor.batch.max_queue_size ?? undefined,
|
|
669
705
|
maxExportBatchSize: processor.batch.max_export_batch_size ?? undefined,
|
|
670
706
|
scheduledDelayMillis: processor.batch.schedule_delay ?? undefined,
|
|
@@ -675,7 +711,7 @@ function getSpanProcessorsFromConfiguration(config) {
|
|
|
675
711
|
if (processor.simple) {
|
|
676
712
|
const exporter = getSpanExporter(processor.simple.exporter);
|
|
677
713
|
if (exporter) {
|
|
678
|
-
spanProcessors.push(new
|
|
714
|
+
spanProcessors.push(new sdk_trace_1.SimpleSpanProcessor({ exporter }));
|
|
679
715
|
}
|
|
680
716
|
}
|
|
681
717
|
});
|
|
@@ -685,26 +721,23 @@ function getSpanProcessorsFromConfiguration(config) {
|
|
|
685
721
|
return undefined;
|
|
686
722
|
}
|
|
687
723
|
exports.getSpanProcessorsFromConfiguration = getSpanProcessorsFromConfiguration;
|
|
688
|
-
function
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
limitsConfig.attribute_value_length_limit;
|
|
702
|
-
}
|
|
703
|
-
return spanLimits;
|
|
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.`);
|
|
704
737
|
}
|
|
705
738
|
return undefined;
|
|
706
739
|
}
|
|
707
|
-
exports.
|
|
740
|
+
exports.getIdGeneratorFromConfiguration = getIdGeneratorFromConfiguration;
|
|
708
741
|
function getMeterReadersFromConfiguration(config) {
|
|
709
742
|
const metricReaders = [];
|
|
710
743
|
config.meter_provider?.readers?.forEach(reader => {
|
|
@@ -870,24 +903,37 @@ function getInstanceID(config) {
|
|
|
870
903
|
}
|
|
871
904
|
exports.getInstanceID = getInstanceID;
|
|
872
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;
|
|
873
919
|
/**
|
|
874
920
|
* Builds a {@link Sampler} from a {@link SamplerConfigModel} data model.
|
|
875
921
|
* This allows sampler construction from declarative configuration.
|
|
876
922
|
*/
|
|
877
923
|
function buildSamplerFromConfig(samplerConfig) {
|
|
878
924
|
if (samplerConfig.always_on !== undefined) {
|
|
879
|
-
return new
|
|
925
|
+
return new sdk_trace_1.AlwaysOnSampler();
|
|
880
926
|
}
|
|
881
927
|
if (samplerConfig.always_off !== undefined) {
|
|
882
|
-
return new
|
|
928
|
+
return new sdk_trace_1.AlwaysOffSampler();
|
|
883
929
|
}
|
|
884
930
|
if (samplerConfig.trace_id_ratio_based !== undefined) {
|
|
885
|
-
return new
|
|
931
|
+
return new sdk_trace_1.TraceIdRatioBasedSampler(samplerConfig.trace_id_ratio_based?.ratio ?? DEFAULT_RATIO);
|
|
886
932
|
}
|
|
887
933
|
if (samplerConfig.parent_based !== undefined) {
|
|
888
934
|
const pb = samplerConfig.parent_based ?? {};
|
|
889
|
-
return new
|
|
890
|
-
root: pb.root ? buildSamplerFromConfig(pb.root) : new
|
|
935
|
+
return new sdk_trace_1.ParentBasedSampler({
|
|
936
|
+
root: pb.root ? buildSamplerFromConfig(pb.root) : new sdk_trace_1.AlwaysOnSampler(),
|
|
891
937
|
remoteParentSampled: pb.remote_parent_sampled
|
|
892
938
|
? buildSamplerFromConfig(pb.remote_parent_sampled)
|
|
893
939
|
: undefined,
|
|
@@ -902,8 +948,8 @@ function buildSamplerFromConfig(samplerConfig) {
|
|
|
902
948
|
: undefined,
|
|
903
949
|
});
|
|
904
950
|
}
|
|
905
|
-
api_1.diag.
|
|
906
|
-
return new
|
|
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() });
|
|
907
953
|
}
|
|
908
954
|
exports.buildSamplerFromConfig = buildSamplerFromConfig;
|
|
909
955
|
//# sourceMappingURL=utils.js.map
|