@opentelemetry/sdk-node 0.222.0 → 0.300.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/dist/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/create-from-config.cjs +753 -0
- package/dist/create-from-config.cjs.map +1 -0
- package/dist/create-from-config.mjs +740 -0
- package/dist/create-from-config.mjs.map +1 -0
- package/dist/create-from-env.cjs +59 -0
- package/dist/create-from-env.cjs.map +1 -0
- package/dist/create-from-env.mjs +57 -0
- package/dist/create-from-env.mjs.map +1 -0
- package/dist/diag.cjs +95 -0
- package/dist/diag.cjs.map +1 -0
- package/dist/diag.mjs +95 -0
- package/dist/diag.mjs.map +1 -0
- package/dist/index.cjs +52 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.mjs +8 -0
- package/dist/sdk.cjs +206 -0
- package/dist/sdk.cjs.map +1 -0
- package/dist/sdk.d.cts +65 -0
- package/dist/sdk.d.cts.map +1 -0
- package/dist/sdk.d.mts +65 -0
- package/dist/sdk.d.mts.map +1 -0
- package/dist/sdk.mjs +206 -0
- package/dist/sdk.mjs.map +1 -0
- package/dist/start.cjs +76 -0
- package/dist/start.cjs.map +1 -0
- package/dist/start.d.cts +12 -0
- package/dist/start.d.cts.map +1 -0
- package/dist/start.d.mts +12 -0
- package/dist/start.d.mts.map +1 -0
- package/dist/start.mjs +75 -0
- package/dist/start.mjs.map +1 -0
- package/dist/types.d.cts +42 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +42 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/utils.cjs +214 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.mjs +203 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +47 -41
- package/build/src/create-from-config.d.ts +0 -29
- package/build/src/create-from-config.js +0 -1036
- package/build/src/create-from-config.js.map +0 -1
- package/build/src/create-from-env.d.ts +0 -11
- package/build/src/create-from-env.js +0 -81
- package/build/src/create-from-env.js.map +0 -1
- package/build/src/diag.d.ts +0 -47
- package/build/src/diag.js +0 -100
- package/build/src/diag.js.map +0 -1
- package/build/src/index.d.ts +0 -19
- package/build/src/index.js +0 -32
- package/build/src/index.js.map +0 -1
- package/build/src/sdk.d.ts +0 -62
- package/build/src/sdk.js +0 -315
- package/build/src/sdk.js.map +0 -1
- package/build/src/semconv.d.ts +0 -62
- package/build/src/semconv.js +0 -74
- package/build/src/semconv.js.map +0 -1
- package/build/src/start.d.ts +0 -12
- package/build/src/start.js +0 -121
- package/build/src/start.js.map +0 -1
- package/build/src/types.d.ts +0 -55
- package/build/src/types.js +0 -7
- package/build/src/types.js.map +0 -1
- package/build/src/utils.d.ts +0 -31
- package/build/src/utils.js +0 -327
- package/build/src/utils.js.map +0 -1
- package/build/src/version.d.ts +0 -2
- package/build/src/version.js +0 -10
- package/build/src/version.js.map +0 -1
|
@@ -0,0 +1,740 @@
|
|
|
1
|
+
import { diag } from "@opentelemetry/api";
|
|
2
|
+
import { CompositePropagator, W3CBaggagePropagator, W3CTraceContextPropagator, getStringFromEnv } from "@opentelemetry/core";
|
|
3
|
+
import { BatchLogRecordProcessor, ConsoleLogRecordExporter, LoggerProvider, SimpleLogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
4
|
+
import { AggregationType, ConsoleMetricExporter, InstrumentType, MeterProvider, PeriodicExportingMetricReader, createAllowListAttributesProcessor, createDenyListAttributesProcessor } from "@opentelemetry/sdk-metrics";
|
|
5
|
+
import { defaultResource, detectResources, hostDetector, osDetector, processDetector, resourceFromAttributes, serviceInstanceIdDetector } from "@opentelemetry/resources";
|
|
6
|
+
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
7
|
+
import { OTLPLogExporter as OTLPLogExporter$1 } from "@opentelemetry/exporter-logs-otlp-grpc";
|
|
8
|
+
import { OTLPLogExporter as OTLPLogExporter$2 } from "@opentelemetry/exporter-logs-otlp-proto";
|
|
9
|
+
import { PrometheusExporter } from "@opentelemetry/exporter-prometheus";
|
|
10
|
+
import { AlwaysOffSampler, AlwaysOnSampler, BatchSpanProcessor, ConsoleSpanExporter, ParentBasedSampler, RandomIdGenerator, SimpleSpanProcessor, TraceIdRatioBasedSampler, TracerProvider } from "@opentelemetry/sdk-trace";
|
|
11
|
+
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
|
|
12
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
13
|
+
import { OTLPTraceExporter as OTLPTraceExporter$1 } from "@opentelemetry/exporter-trace-otlp-http";
|
|
14
|
+
import { OTLPTraceExporter as OTLPTraceExporter$2 } from "@opentelemetry/exporter-trace-otlp-grpc";
|
|
15
|
+
import { B3InjectEncoding, B3Propagator } from "@opentelemetry/propagator-b3";
|
|
16
|
+
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-grpc";
|
|
17
|
+
import { AggregationTemporalityPreference, OTLPMetricExporter as OTLPMetricExporter$1 } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
18
|
+
import { OTLPMetricExporter as OTLPMetricExporter$2 } from "@opentelemetry/exporter-metrics-otlp-proto";
|
|
19
|
+
import { mergeHeadersConfig, mergePropagatorCompositeConfig, mergeResourceAttributesConfig } from "@opentelemetry/configuration";
|
|
20
|
+
import { inspect } from "util";
|
|
21
|
+
import { readFileSync } from "fs";
|
|
22
|
+
import * as path from "path";
|
|
23
|
+
import { CompressionAlgorithm } from "@opentelemetry/otlp-exporter-base";
|
|
24
|
+
import { createEmptyMetadata, createInsecureCredentials, createSslCredentials } from "@opentelemetry/otlp-grpc-exporter-base";
|
|
25
|
+
//#region src/create-from-config.ts
|
|
26
|
+
/**
|
|
27
|
+
* Create SDK components from parsed declarative config.
|
|
28
|
+
* https://opentelemetry.io/docs/specs/otel/configuration/sdk/#create
|
|
29
|
+
*
|
|
30
|
+
* Dev Notes:
|
|
31
|
+
* This file exports `create<SDK Thing>FromConfig(...)` functions intended to
|
|
32
|
+
* be used by the "create" step of `startNodeSDK()`.
|
|
33
|
+
*/
|
|
34
|
+
function getGrpcMetadataFromHeaders(headers, headersList) {
|
|
35
|
+
const headerValues = mergeHeadersConfig(headers, headersList);
|
|
36
|
+
if (!headerValues || Object.keys(headerValues).length === 0) return;
|
|
37
|
+
const metadata = createEmptyMetadata();
|
|
38
|
+
for (const [name, value] of Object.entries(headerValues)) metadata.set(name, value);
|
|
39
|
+
return metadata;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Warn if some props from a declarative config object have not been handled.
|
|
43
|
+
*
|
|
44
|
+
* This is intended to be used by `create*FromConfig()` functions. It is a low
|
|
45
|
+
* tech mechanism to add awareness when a given valid config is not being
|
|
46
|
+
* completely handled. This could help when properties are added to the
|
|
47
|
+
* configuration schema. (A higher tech mechanism that wraps the parsed
|
|
48
|
+
* configuration during `create()` and watches for untouched properties
|
|
49
|
+
* might be nice.)
|
|
50
|
+
*/
|
|
51
|
+
function checkConfigUse(name, props, handledProps) {
|
|
52
|
+
if (!props) return;
|
|
53
|
+
const unhandledProps = Object.keys(props).filter((k) => !handledProps.includes(k));
|
|
54
|
+
if (unhandledProps.length > 0) diag.warn(`Config warning: some specified ${name} configuration properties were not handled by SDK setup: ${JSON.stringify(unhandledProps)}`);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Return the single non-undefined entry in the given config object, or throw.
|
|
58
|
+
*
|
|
59
|
+
* It is common for Declarative Configuration to have config objects with
|
|
60
|
+
* a single entry, e.g.
|
|
61
|
+
*
|
|
62
|
+
* "LogRecordProcessor": {
|
|
63
|
+
* "type": "object",
|
|
64
|
+
* "additionalProperties": {
|
|
65
|
+
* "type": [
|
|
66
|
+
* "object",
|
|
67
|
+
* "null"
|
|
68
|
+
* ]
|
|
69
|
+
* },
|
|
70
|
+
* "minProperties": 1,
|
|
71
|
+
* "maxProperties": 1,
|
|
72
|
+
*
|
|
73
|
+
* The TypeScript types cannot express the minProperties/maxProperties from the
|
|
74
|
+
* JSON schema. We guard against that here.
|
|
75
|
+
*/
|
|
76
|
+
function mustSingleEntry(configObj, configTypeName) {
|
|
77
|
+
const entries = Object.entries(configObj).filter(([_name, properties]) => properties !== void 0);
|
|
78
|
+
if (entries.length !== 1) {
|
|
79
|
+
const entryNames = entries.map((e) => e[0]);
|
|
80
|
+
throw new Error(`invalid ${configTypeName} in configuration: must have exactly one entry: entries=${JSON.stringify(entryNames)}`);
|
|
81
|
+
}
|
|
82
|
+
return entries[0];
|
|
83
|
+
}
|
|
84
|
+
function loadTlsConfigFile(absPath, propName) {
|
|
85
|
+
try {
|
|
86
|
+
if (!path.isAbsolute(absPath)) throw new Error(`TLS config file "${absPath}" must be an absolute path`);
|
|
87
|
+
return readFileSync(absPath);
|
|
88
|
+
} catch (err) {
|
|
89
|
+
throw new Error(`could not load "tls.${propName}" from config: ${err.message}`, { cause: err });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get TLS-related HTTP client options from declarative configuration.
|
|
94
|
+
* https://opentelemetry.io/docs/specs/otel-config/types/#type-httptls
|
|
95
|
+
* https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions
|
|
96
|
+
*/
|
|
97
|
+
function httpTlsOptionsFromConfig(tls) {
|
|
98
|
+
if (!tls) return;
|
|
99
|
+
checkConfigUse("HttpTls", tls, [
|
|
100
|
+
"ca_file",
|
|
101
|
+
"cert_file",
|
|
102
|
+
"key_file"
|
|
103
|
+
]);
|
|
104
|
+
const httpTlsOptions = {};
|
|
105
|
+
if (tls.ca_file) httpTlsOptions.ca = loadTlsConfigFile(tls.ca_file, "ca_file");
|
|
106
|
+
if (tls.cert_file) httpTlsOptions.cert = loadTlsConfigFile(tls.cert_file, "cert_file");
|
|
107
|
+
if (tls.key_file) httpTlsOptions.key = loadTlsConfigFile(tls.key_file, "key_file");
|
|
108
|
+
return httpTlsOptions;
|
|
109
|
+
}
|
|
110
|
+
function grpcCredentialsFromConfig(tls) {
|
|
111
|
+
if (!tls) return;
|
|
112
|
+
checkConfigUse("GrpcTls", tls, [
|
|
113
|
+
"insecure",
|
|
114
|
+
"ca_file",
|
|
115
|
+
"cert_file",
|
|
116
|
+
"key_file"
|
|
117
|
+
]);
|
|
118
|
+
if (tls?.insecure) return createInsecureCredentials();
|
|
119
|
+
const rootCert = tls.ca_file ? loadTlsConfigFile(tls.ca_file, "ca_file") : void 0;
|
|
120
|
+
const privateKey = tls.key_file ? loadTlsConfigFile(tls.key_file, "key_file") : void 0;
|
|
121
|
+
const certChain = tls.cert_file ? loadTlsConfigFile(tls.cert_file, "cert_file") : void 0;
|
|
122
|
+
if (rootCert || privateKey || certChain) return createSslCredentials(rootCert, privateKey, certChain);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Validate an export(er) timeout value.
|
|
126
|
+
* "timeout" properties in the declarative config schema are typically
|
|
127
|
+
* described with:
|
|
128
|
+
*
|
|
129
|
+
* 1. Value must be non-negative.
|
|
130
|
+
* 2. A value of 0 indicates no limit (infinity).
|
|
131
|
+
*
|
|
132
|
+
* Search "timeout" at https://opentelemetry.io/docs/specs/otel-config/types/
|
|
133
|
+
*
|
|
134
|
+
* This function enforces (1), and guards against (2) because current OTel
|
|
135
|
+
* JS SDK components do *not* handle a `0` timeout value.
|
|
136
|
+
* See https://github.com/open-telemetry/opentelemetry-js/issues/6617
|
|
137
|
+
*/
|
|
138
|
+
function validateExportTimeoutConfig(timeout, errLabel) {
|
|
139
|
+
if (timeout == null) return;
|
|
140
|
+
else if (timeout < 0) throw new Error(`${errLabel} value must be non-negative: ${timeout}`);
|
|
141
|
+
else if (timeout === 0) throw new Error(`${errLabel} of 0 (infinite) is not supported`);
|
|
142
|
+
return timeout;
|
|
143
|
+
}
|
|
144
|
+
function createPropagatorFromConfig(propagatorConfig) {
|
|
145
|
+
const configComposite = mergePropagatorCompositeConfig(propagatorConfig.composite, propagatorConfig.composite_list);
|
|
146
|
+
if (!configComposite) return;
|
|
147
|
+
const kvFromItem = (item) => {
|
|
148
|
+
const keys = [];
|
|
149
|
+
let value = void 0;
|
|
150
|
+
for (const key of Object.keys(item)) {
|
|
151
|
+
value = item[key];
|
|
152
|
+
if (value === void 0) continue;
|
|
153
|
+
keys.push(key);
|
|
154
|
+
}
|
|
155
|
+
if (keys.length !== 1) throw new Error(`invalid "propagator" entry in configuration, there must be exactly one key (with a non-undefined value): ${inspect(item)}`);
|
|
156
|
+
return [keys[0], value];
|
|
157
|
+
};
|
|
158
|
+
const names = /* @__PURE__ */ new Set();
|
|
159
|
+
const kvs = [];
|
|
160
|
+
for (const item of configComposite) {
|
|
161
|
+
const kv = kvFromItem(item);
|
|
162
|
+
const k = kv[0];
|
|
163
|
+
if (names.has(k)) continue;
|
|
164
|
+
names.add(k);
|
|
165
|
+
kvs.push(kv);
|
|
166
|
+
if (k === "none") return;
|
|
167
|
+
}
|
|
168
|
+
const propagatorsFactory = /* @__PURE__ */ new Map([
|
|
169
|
+
["tracecontext", () => new W3CTraceContextPropagator()],
|
|
170
|
+
["baggage", () => new W3CBaggagePropagator()],
|
|
171
|
+
["b3", () => new B3Propagator()],
|
|
172
|
+
["b3multi", () => new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER })]
|
|
173
|
+
]);
|
|
174
|
+
const propagators = [];
|
|
175
|
+
for (const [name] of kvs) {
|
|
176
|
+
const propagator = propagatorsFactory.get(name)?.();
|
|
177
|
+
if (!propagator) throw new Error(`unknown TextMapPropagator in configuration: "${name}"`);
|
|
178
|
+
propagators.push(propagator);
|
|
179
|
+
}
|
|
180
|
+
if (propagators.length === 0) return;
|
|
181
|
+
else return new CompositePropagator({ propagators });
|
|
182
|
+
}
|
|
183
|
+
var ServiceNameDetector = class {
|
|
184
|
+
detect() {
|
|
185
|
+
const attributes = {};
|
|
186
|
+
const serviceName = getStringFromEnv("OTEL_SERVICE_NAME");
|
|
187
|
+
if (serviceName) attributes[ATTR_SERVICE_NAME] = serviceName;
|
|
188
|
+
return { attributes };
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const serviceNameDetector = new ServiceNameDetector();
|
|
192
|
+
function createResourceFromConfig(resourceConfig) {
|
|
193
|
+
checkConfigUse("Resource", resourceConfig, [
|
|
194
|
+
"attributes",
|
|
195
|
+
"attributes_list",
|
|
196
|
+
"schema_url",
|
|
197
|
+
"detection/development"
|
|
198
|
+
]);
|
|
199
|
+
let resource = defaultResource();
|
|
200
|
+
if (!resourceConfig) return resource;
|
|
201
|
+
if (resourceConfig["detection/development"]) {
|
|
202
|
+
checkConfigUse("ExperimentalResourceDetection", resourceConfig["detection/development"], ["detectors"]);
|
|
203
|
+
if (resourceConfig["detection/development"].detectors) {
|
|
204
|
+
const detectors = [];
|
|
205
|
+
for (const d of resourceConfig["detection/development"].detectors) {
|
|
206
|
+
const [name] = mustSingleEntry(d, "ExperimentalResourceDetector");
|
|
207
|
+
switch (name) {
|
|
208
|
+
case "host":
|
|
209
|
+
detectors.push(hostDetector);
|
|
210
|
+
detectors.push(osDetector);
|
|
211
|
+
break;
|
|
212
|
+
case "process":
|
|
213
|
+
detectors.push(processDetector);
|
|
214
|
+
break;
|
|
215
|
+
case "service":
|
|
216
|
+
detectors.push(serviceNameDetector);
|
|
217
|
+
detectors.push(serviceInstanceIdDetector);
|
|
218
|
+
break;
|
|
219
|
+
default: throw new Error(`unknown ExperimentalResourceDetector name in configuration: "${name}"`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (detectors.length > 0) resource = resource.merge(detectResources({ detectors }));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const configAttrs = mergeResourceAttributesConfig(resourceConfig.attributes, resourceConfig.attributes_list);
|
|
226
|
+
if (configAttrs && configAttrs.length > 0) {
|
|
227
|
+
const attrs = {};
|
|
228
|
+
for (const a of configAttrs) if (a.value !== null) attrs[a.name] = a.value;
|
|
229
|
+
resource = resource.merge(resourceFromAttributes(attrs));
|
|
230
|
+
}
|
|
231
|
+
if (resourceConfig.schema_url) resource = resource.merge(resourceFromAttributes({}, { schemaUrl: resourceConfig.schema_url }));
|
|
232
|
+
return resource;
|
|
233
|
+
}
|
|
234
|
+
function createLogRecordLimitsFromConfig(limits, attribute_limits) {
|
|
235
|
+
if (!limits && !attribute_limits) return;
|
|
236
|
+
return {
|
|
237
|
+
attributeValueLengthLimit: limits?.attribute_value_length_limit ?? attribute_limits?.attribute_value_length_limit ?? void 0,
|
|
238
|
+
attributeCountLimit: limits?.attribute_count_limit ?? attribute_limits?.attribute_count_limit ?? void 0
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
function createLogRecordExporterFromConfig(exporter) {
|
|
242
|
+
const [name, properties] = mustSingleEntry(exporter, "LogRecordExporter");
|
|
243
|
+
switch (name) {
|
|
244
|
+
case "otlp_http": {
|
|
245
|
+
checkConfigUse("OtlpHttpExporter", properties, [
|
|
246
|
+
"compression",
|
|
247
|
+
"endpoint",
|
|
248
|
+
"headers",
|
|
249
|
+
"headers_list",
|
|
250
|
+
"timeout",
|
|
251
|
+
"tls",
|
|
252
|
+
"encoding"
|
|
253
|
+
]);
|
|
254
|
+
const props = properties;
|
|
255
|
+
const commonOpts = {
|
|
256
|
+
compression: props?.compression === "gzip" ? CompressionAlgorithm.GZIP : CompressionAlgorithm.NONE,
|
|
257
|
+
url: props?.endpoint ?? void 0,
|
|
258
|
+
headers: mergeHeadersConfig(props?.headers, props?.headers_list),
|
|
259
|
+
timeoutMillis: validateExportTimeoutConfig(props?.timeout, "OtlpHttpExporter.timeout"),
|
|
260
|
+
httpAgentOptions: httpTlsOptionsFromConfig(props?.tls)
|
|
261
|
+
};
|
|
262
|
+
const encoding = props?.encoding ?? "protobuf";
|
|
263
|
+
switch (encoding) {
|
|
264
|
+
case "json": return new OTLPLogExporter(commonOpts);
|
|
265
|
+
case "protobuf": return new OTLPLogExporter$2(commonOpts);
|
|
266
|
+
default: throw new Error(`unknown OtlpHttpExporter encoding in configuration: "${encoding}"`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
case "otlp_grpc": {
|
|
270
|
+
checkConfigUse("OtlpGrpcExporter", properties, [
|
|
271
|
+
"compression",
|
|
272
|
+
"endpoint",
|
|
273
|
+
"timeout",
|
|
274
|
+
"tls",
|
|
275
|
+
"headers",
|
|
276
|
+
"headers_list"
|
|
277
|
+
]);
|
|
278
|
+
const props = properties;
|
|
279
|
+
return new OTLPLogExporter$1({
|
|
280
|
+
compression: props?.compression === "gzip" ? CompressionAlgorithm.GZIP : CompressionAlgorithm.NONE,
|
|
281
|
+
url: props?.endpoint ?? void 0,
|
|
282
|
+
timeoutMillis: validateExportTimeoutConfig(props?.timeout, "OtlpGrpcExporter.timeout"),
|
|
283
|
+
credentials: grpcCredentialsFromConfig(props?.tls),
|
|
284
|
+
metadata: getGrpcMetadataFromHeaders(props?.headers, props?.headers_list)
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
case "console": return new ConsoleLogRecordExporter();
|
|
288
|
+
default: throw new Error(`unknown LogRecordExporter name in configuration: "${name}"`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function createLogRecordProcessorFromConfig(processor) {
|
|
292
|
+
const [name, properties] = mustSingleEntry(processor, "LogRecordProcessor");
|
|
293
|
+
switch (name) {
|
|
294
|
+
case "batch": {
|
|
295
|
+
checkConfigUse("BatchLogRecordProcessor", properties, [
|
|
296
|
+
"exporter",
|
|
297
|
+
"max_queue_size",
|
|
298
|
+
"max_export_batch_size",
|
|
299
|
+
"schedule_delay",
|
|
300
|
+
"export_timeout"
|
|
301
|
+
]);
|
|
302
|
+
const props = properties;
|
|
303
|
+
const exporter = createLogRecordExporterFromConfig(props.exporter);
|
|
304
|
+
return new BatchLogRecordProcessor({
|
|
305
|
+
exporter,
|
|
306
|
+
maxQueueSize: props.max_queue_size ?? void 0,
|
|
307
|
+
maxExportBatchSize: props.max_export_batch_size ?? void 0,
|
|
308
|
+
scheduledDelayMillis: props.schedule_delay ?? void 0,
|
|
309
|
+
exportTimeoutMillis: validateExportTimeoutConfig(props.export_timeout, "BatchLogRecordProcessor.export_timeout")
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
case "simple": {
|
|
313
|
+
const exporter = createLogRecordExporterFromConfig(properties.exporter);
|
|
314
|
+
return new SimpleLogRecordProcessor({ exporter });
|
|
315
|
+
}
|
|
316
|
+
default: throw new Error(`unknown LogRecordProcessor name: "${name}"`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function createLoggerProviderFromConfig(resource, logger_provider, attribute_limits) {
|
|
320
|
+
const processors = logger_provider.processors.map((p) => createLogRecordProcessorFromConfig(p));
|
|
321
|
+
const logRecordLimits = createLogRecordLimitsFromConfig(logger_provider.limits, attribute_limits);
|
|
322
|
+
checkConfigUse("LoggerProvider", logger_provider, ["processors", "limits"]);
|
|
323
|
+
return new LoggerProvider({
|
|
324
|
+
resource,
|
|
325
|
+
processors,
|
|
326
|
+
logRecordLimits
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
function createSpanLimitsFromConfig(limits, attribute_limits) {
|
|
330
|
+
if (!limits && !attribute_limits) return;
|
|
331
|
+
return {
|
|
332
|
+
attributeValueLengthLimit: limits?.attribute_value_length_limit ?? attribute_limits?.attribute_value_length_limit ?? void 0,
|
|
333
|
+
attributeCountLimit: limits?.attribute_count_limit ?? attribute_limits?.attribute_count_limit ?? void 0,
|
|
334
|
+
eventCountLimit: limits?.event_count_limit ?? void 0,
|
|
335
|
+
linkCountLimit: limits?.link_count_limit ?? void 0,
|
|
336
|
+
attributePerEventCountLimit: limits?.event_attribute_count_limit ?? void 0,
|
|
337
|
+
attributePerLinkCountLimit: limits?.link_attribute_count_limit ?? void 0
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Map a declarative-config `temporality_preference` value to the enum the OTLP
|
|
342
|
+
* metric exporters expect. Returns undefined for an unspecified preference so
|
|
343
|
+
* the exporter falls back to its own default (cumulative).
|
|
344
|
+
*/
|
|
345
|
+
function aggregationTemporalityPreferenceFromConfig(temporality_preference) {
|
|
346
|
+
if (temporality_preference == null) return;
|
|
347
|
+
switch (temporality_preference) {
|
|
348
|
+
case "delta": return AggregationTemporalityPreference.DELTA;
|
|
349
|
+
case "low_memory": return AggregationTemporalityPreference.LOWMEMORY;
|
|
350
|
+
case "cumulative": return AggregationTemporalityPreference.CUMULATIVE;
|
|
351
|
+
default: throw new Error(`unknown temporality_preference value in configuration: ${temporality_preference}`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Map a declarative-config `default_histogram_aggregation` value to an
|
|
356
|
+
* AggregationSelector that applies the requested aggregation to histogram
|
|
357
|
+
* instruments and leaves all other instrument types at their default. Returns
|
|
358
|
+
* undefined for an unspecified value so the exporter uses its own default.
|
|
359
|
+
*/
|
|
360
|
+
function aggregationSelectorFromConfig(default_histogram_aggregation) {
|
|
361
|
+
if (default_histogram_aggregation == null) return;
|
|
362
|
+
let histoAggOpt;
|
|
363
|
+
switch (default_histogram_aggregation) {
|
|
364
|
+
case "base2_exponential_bucket_histogram":
|
|
365
|
+
histoAggOpt = { type: AggregationType.EXPONENTIAL_HISTOGRAM };
|
|
366
|
+
break;
|
|
367
|
+
case "explicit_bucket_histogram":
|
|
368
|
+
histoAggOpt = { type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM };
|
|
369
|
+
break;
|
|
370
|
+
default: throw new Error(`unknown default_histogram_aggregation value in configuration: ${default_histogram_aggregation}`);
|
|
371
|
+
}
|
|
372
|
+
return (instrumentType) => instrumentType === InstrumentType.HISTOGRAM ? histoAggOpt : { type: AggregationType.DEFAULT };
|
|
373
|
+
}
|
|
374
|
+
/** exported for testing */
|
|
375
|
+
function createPushMetricExporterFromConfig(exporter) {
|
|
376
|
+
const [name, properties] = mustSingleEntry(exporter, "PushMetricExporter");
|
|
377
|
+
switch (name) {
|
|
378
|
+
case "otlp_http": {
|
|
379
|
+
checkConfigUse("PushMetricExporter", properties, [
|
|
380
|
+
"compression",
|
|
381
|
+
"endpoint",
|
|
382
|
+
"headers",
|
|
383
|
+
"headers_list",
|
|
384
|
+
"timeout",
|
|
385
|
+
"tls",
|
|
386
|
+
"temporality_preference",
|
|
387
|
+
"default_histogram_aggregation",
|
|
388
|
+
"encoding"
|
|
389
|
+
]);
|
|
390
|
+
const props = properties;
|
|
391
|
+
const commonOpts = {
|
|
392
|
+
compression: props?.compression === "gzip" ? CompressionAlgorithm.GZIP : CompressionAlgorithm.NONE,
|
|
393
|
+
url: props?.endpoint ?? void 0,
|
|
394
|
+
headers: mergeHeadersConfig(props?.headers, props?.headers_list),
|
|
395
|
+
timeoutMillis: validateExportTimeoutConfig(props?.timeout, "PushMetricExporter.timeout"),
|
|
396
|
+
httpAgentOptions: httpTlsOptionsFromConfig(props?.tls),
|
|
397
|
+
temporalityPreference: aggregationTemporalityPreferenceFromConfig(props?.temporality_preference),
|
|
398
|
+
aggregationPreference: aggregationSelectorFromConfig(props?.default_histogram_aggregation)
|
|
399
|
+
};
|
|
400
|
+
const encoding = props?.encoding ?? "protobuf";
|
|
401
|
+
switch (encoding) {
|
|
402
|
+
case "json": return new OTLPMetricExporter$1(commonOpts);
|
|
403
|
+
case "protobuf": return new OTLPMetricExporter$2(commonOpts);
|
|
404
|
+
default: throw new Error(`unknown OtlpHttpMetricExporter encoding in configuration: "${encoding}"`);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
case "otlp_grpc": {
|
|
408
|
+
checkConfigUse("PushMetricExporter", properties, [
|
|
409
|
+
"compression",
|
|
410
|
+
"endpoint",
|
|
411
|
+
"timeout",
|
|
412
|
+
"tls",
|
|
413
|
+
"headers",
|
|
414
|
+
"headers_list",
|
|
415
|
+
"temporality_preference",
|
|
416
|
+
"default_histogram_aggregation"
|
|
417
|
+
]);
|
|
418
|
+
const props = properties;
|
|
419
|
+
return new OTLPMetricExporter({
|
|
420
|
+
compression: props?.compression === "gzip" ? CompressionAlgorithm.GZIP : CompressionAlgorithm.NONE,
|
|
421
|
+
url: props?.endpoint ?? void 0,
|
|
422
|
+
timeoutMillis: validateExportTimeoutConfig(props?.timeout, "PushMetricExporter.timeout"),
|
|
423
|
+
credentials: grpcCredentialsFromConfig(props?.tls),
|
|
424
|
+
metadata: getGrpcMetadataFromHeaders(props?.headers, props?.headers_list),
|
|
425
|
+
temporalityPreference: aggregationTemporalityPreferenceFromConfig(props?.temporality_preference),
|
|
426
|
+
aggregationPreference: aggregationSelectorFromConfig(props?.default_histogram_aggregation)
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
case "console":
|
|
430
|
+
checkConfigUse("PushMetricExporter", properties, []);
|
|
431
|
+
return new ConsoleMetricExporter();
|
|
432
|
+
default: throw new Error(`unknown PushMetricExporter name in configuration: "${name}"`);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
function createMetricProducerFromConfig(producer) {
|
|
436
|
+
const [name] = mustSingleEntry(producer, "MetricProducer");
|
|
437
|
+
switch (name) {
|
|
438
|
+
case "opencensus": throw new Error("the \"opencensus\" MetricProducer is deprecated and not supported");
|
|
439
|
+
default: throw new Error(`unknown MetricProducer name: "${name}"`);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function createPeriodicMetricReaderFromConfig(periodic) {
|
|
443
|
+
const exporter = createPushMetricExporterFromConfig(periodic.exporter);
|
|
444
|
+
const metricProducers = periodic.producers?.map(createMetricProducerFromConfig);
|
|
445
|
+
checkConfigUse("PeriodicMetricReader", periodic, [
|
|
446
|
+
"exporter",
|
|
447
|
+
"producers",
|
|
448
|
+
"interval",
|
|
449
|
+
"timeout",
|
|
450
|
+
"max_export_batch_size/development"
|
|
451
|
+
]);
|
|
452
|
+
return new PeriodicExportingMetricReader({
|
|
453
|
+
exportIntervalMillis: periodic.interval ?? 6e4,
|
|
454
|
+
exportTimeoutMillis: validateExportTimeoutConfig(periodic?.timeout, "PeriodicExportingMetricReader.timeout") ?? 3e4,
|
|
455
|
+
exporter,
|
|
456
|
+
metricProducers,
|
|
457
|
+
maxExportBatchSize: periodic["max_export_batch_size/development"] ?? void 0
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
function createPullMetricReaderFromConfig(pull) {
|
|
461
|
+
checkConfigUse("PullMetricReader", pull, ["exporter", "producers"]);
|
|
462
|
+
const metricProducers = pull.producers?.map(createMetricProducerFromConfig);
|
|
463
|
+
const [name, properties] = mustSingleEntry(pull.exporter, "PullMetricExporter");
|
|
464
|
+
switch (name) {
|
|
465
|
+
case "prometheus/development": {
|
|
466
|
+
checkConfigUse("ExperimentalPrometheusMetricExporterConfigModel", properties, [
|
|
467
|
+
"host",
|
|
468
|
+
"port",
|
|
469
|
+
"scope_info_enabled",
|
|
470
|
+
"target_info_enabled/development"
|
|
471
|
+
]);
|
|
472
|
+
const props = properties;
|
|
473
|
+
return new PrometheusExporter({
|
|
474
|
+
host: props?.host ?? "localhost",
|
|
475
|
+
port: props?.port ?? 9464,
|
|
476
|
+
withoutScopeInfo: props?.scope_info_enabled != null ? !props.scope_info_enabled : void 0,
|
|
477
|
+
withoutTargetInfo: props?.["target_info_enabled/development"] != null ? !props["target_info_enabled/development"] : void 0,
|
|
478
|
+
metricProducers
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
default: throw new Error(`unknown PullMetricReader name in configuration: "${name}"`);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function createMetricReaderFromConfig(reader) {
|
|
485
|
+
const [name, properties] = mustSingleEntry(reader, "MetricReader");
|
|
486
|
+
switch (name) {
|
|
487
|
+
case "periodic": return createPeriodicMetricReaderFromConfig(properties);
|
|
488
|
+
case "pull": return createPullMetricReaderFromConfig(properties);
|
|
489
|
+
default: throw new Error(`unknown MetricReader type in configuration: "${Object.keys(reader)[0]}"`);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function instrumentTypeFromConfig(instrument_type) {
|
|
493
|
+
switch (instrument_type) {
|
|
494
|
+
case "counter": return InstrumentType.COUNTER;
|
|
495
|
+
case "gauge": return InstrumentType.GAUGE;
|
|
496
|
+
case "histogram": return InstrumentType.HISTOGRAM;
|
|
497
|
+
case "observable_counter": return InstrumentType.OBSERVABLE_COUNTER;
|
|
498
|
+
case "observable_gauge": return InstrumentType.OBSERVABLE_GAUGE;
|
|
499
|
+
case "observable_up_down_counter": return InstrumentType.OBSERVABLE_UP_DOWN_COUNTER;
|
|
500
|
+
case "up_down_counter": return InstrumentType.UP_DOWN_COUNTER;
|
|
501
|
+
default: throw new Error(`unknown InstrumentType: ${instrument_type}`);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
function createAggregationOptionFromConfig(aggregation) {
|
|
505
|
+
const [name, properties] = mustSingleEntry(aggregation, "Aggregation");
|
|
506
|
+
switch (name) {
|
|
507
|
+
case "default": return { type: AggregationType.DEFAULT };
|
|
508
|
+
case "drop": return { type: AggregationType.DROP };
|
|
509
|
+
case "explicit_bucket_histogram": {
|
|
510
|
+
checkConfigUse("ExplicitBucketHistogramAggregation", properties, ["record_min_max", "boundaries"]);
|
|
511
|
+
const props = properties;
|
|
512
|
+
return {
|
|
513
|
+
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
|
|
514
|
+
options: {
|
|
515
|
+
recordMinMax: props?.record_min_max ?? true,
|
|
516
|
+
boundaries: props?.boundaries ?? [
|
|
517
|
+
0,
|
|
518
|
+
5,
|
|
519
|
+
10,
|
|
520
|
+
25,
|
|
521
|
+
50,
|
|
522
|
+
75,
|
|
523
|
+
100,
|
|
524
|
+
250,
|
|
525
|
+
500,
|
|
526
|
+
750,
|
|
527
|
+
1e3,
|
|
528
|
+
2500,
|
|
529
|
+
5e3,
|
|
530
|
+
7500,
|
|
531
|
+
1e4
|
|
532
|
+
]
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
case "base2_exponential_bucket_histogram": {
|
|
537
|
+
checkConfigUse("Base2ExponentialBucketHistogramAggregation", properties, ["record_min_max", "max_size"]);
|
|
538
|
+
const props = properties;
|
|
539
|
+
return {
|
|
540
|
+
type: AggregationType.EXPONENTIAL_HISTOGRAM,
|
|
541
|
+
options: {
|
|
542
|
+
recordMinMax: props?.record_min_max ?? void 0,
|
|
543
|
+
maxSize: props?.max_size ?? void 0
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
case "last_value": return { type: AggregationType.LAST_VALUE };
|
|
548
|
+
case "sum": return { type: AggregationType.SUM };
|
|
549
|
+
default: throw new Error(`unknown Aggregation name in configuration: "${name}"`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function createViewOptionsFromConfig(view) {
|
|
553
|
+
const viewOptions = {};
|
|
554
|
+
checkConfigUse("View", view, ["selector", "stream"]);
|
|
555
|
+
checkConfigUse("ViewSelector", view.selector, [
|
|
556
|
+
"instrument_name",
|
|
557
|
+
"instrument_type",
|
|
558
|
+
"unit",
|
|
559
|
+
"meter_name",
|
|
560
|
+
"meter_version",
|
|
561
|
+
"meter_schema_url"
|
|
562
|
+
]);
|
|
563
|
+
if (view.selector.instrument_name) viewOptions.instrumentName = view.selector.instrument_name;
|
|
564
|
+
if (view.selector.instrument_type) viewOptions.instrumentType = instrumentTypeFromConfig(view.selector.instrument_type);
|
|
565
|
+
if (view.selector.unit) viewOptions.instrumentUnit = view.selector.unit;
|
|
566
|
+
if (view.selector.meter_name) viewOptions.meterName = view.selector.meter_name;
|
|
567
|
+
if (view.selector.meter_version) viewOptions.meterVersion = view.selector.meter_version;
|
|
568
|
+
if (view.selector.meter_schema_url) viewOptions.meterSchemaUrl = view.selector.meter_schema_url;
|
|
569
|
+
checkConfigUse("ViewStream", view.stream, [
|
|
570
|
+
"name",
|
|
571
|
+
"description",
|
|
572
|
+
"aggregation",
|
|
573
|
+
"aggregation_cardinality_limit",
|
|
574
|
+
"attribute_keys"
|
|
575
|
+
]);
|
|
576
|
+
if (view.stream.name) viewOptions.name = view.stream.name;
|
|
577
|
+
if (view.stream.description) viewOptions.description = view.stream.description;
|
|
578
|
+
if (view.stream.aggregation) viewOptions.aggregation = createAggregationOptionFromConfig(view.stream.aggregation);
|
|
579
|
+
viewOptions.aggregationCardinalityLimit = view.stream.aggregation_cardinality_limit ?? void 0;
|
|
580
|
+
if (view.stream.attribute_keys) {
|
|
581
|
+
const processors = [];
|
|
582
|
+
if (view.stream.attribute_keys.included && view.stream.attribute_keys.included.length > 0) {
|
|
583
|
+
const unsupportedKeys = view.stream.attribute_keys.included.filter((k) => k.includes("*") || k.includes("?"));
|
|
584
|
+
if (unsupportedKeys.length > 0) throw new Error(`invalid /meter_provider/views/?/stream/attribute_keys/included in configuration: do not support wildcards: "${unsupportedKeys.join("\", \"")}"`);
|
|
585
|
+
processors.push(createAllowListAttributesProcessor(view.stream.attribute_keys.included));
|
|
586
|
+
}
|
|
587
|
+
if (view.stream.attribute_keys.excluded && view.stream.attribute_keys.excluded.length > 0) {
|
|
588
|
+
const unsupportedKeys = view.stream.attribute_keys.excluded.filter((k) => k.includes("*") || k.includes("?"));
|
|
589
|
+
if (unsupportedKeys.length > 0) throw new Error(`invalid /meter_provider/views/?/stream/attribute_keys/excluded in configuration: do not support wildcards: "${unsupportedKeys.join("\", \"")}"`);
|
|
590
|
+
processors.push(createDenyListAttributesProcessor(view.stream.attribute_keys.excluded));
|
|
591
|
+
}
|
|
592
|
+
if (processors.length > 0) viewOptions.attributesProcessors = processors;
|
|
593
|
+
}
|
|
594
|
+
return viewOptions;
|
|
595
|
+
}
|
|
596
|
+
function createMeterProviderFromConfig(resource, meter_provider) {
|
|
597
|
+
const readers = meter_provider.readers.map(createMetricReaderFromConfig);
|
|
598
|
+
const views = meter_provider.views?.map(createViewOptionsFromConfig);
|
|
599
|
+
checkConfigUse("MeterProvider", meter_provider, ["readers", "views"]);
|
|
600
|
+
return new MeterProvider({
|
|
601
|
+
resource,
|
|
602
|
+
readers,
|
|
603
|
+
views
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
function createSpanExporterFromConfig(exporter) {
|
|
607
|
+
const [name, properties] = mustSingleEntry(exporter, "SpanExporter");
|
|
608
|
+
switch (name) {
|
|
609
|
+
case "otlp_http": {
|
|
610
|
+
checkConfigUse("OtlpHttpExporter", properties, [
|
|
611
|
+
"compression",
|
|
612
|
+
"endpoint",
|
|
613
|
+
"headers",
|
|
614
|
+
"headers_list",
|
|
615
|
+
"timeout",
|
|
616
|
+
"tls",
|
|
617
|
+
"encoding"
|
|
618
|
+
]);
|
|
619
|
+
const props = properties;
|
|
620
|
+
const commonOpts = {
|
|
621
|
+
compression: props?.compression === "gzip" ? CompressionAlgorithm.GZIP : CompressionAlgorithm.NONE,
|
|
622
|
+
url: props?.endpoint ?? void 0,
|
|
623
|
+
headers: mergeHeadersConfig(props?.headers, props?.headers_list),
|
|
624
|
+
timeoutMillis: validateExportTimeoutConfig(props?.timeout, "OtlpHttpExporter.timeout"),
|
|
625
|
+
httpAgentOptions: httpTlsOptionsFromConfig(props?.tls)
|
|
626
|
+
};
|
|
627
|
+
const encoding = props?.encoding ?? "protobuf";
|
|
628
|
+
switch (encoding) {
|
|
629
|
+
case "json": return new OTLPTraceExporter$1(commonOpts);
|
|
630
|
+
case "protobuf": return new OTLPTraceExporter(commonOpts);
|
|
631
|
+
default: throw new Error(`unknown OtlpHttpExporter encoding in configuration: "${encoding}"`);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
case "otlp_grpc": {
|
|
635
|
+
checkConfigUse("OtlpGrpcExporter", properties, [
|
|
636
|
+
"compression",
|
|
637
|
+
"endpoint",
|
|
638
|
+
"timeout",
|
|
639
|
+
"tls",
|
|
640
|
+
"headers",
|
|
641
|
+
"headers_list"
|
|
642
|
+
]);
|
|
643
|
+
const props = properties;
|
|
644
|
+
return new OTLPTraceExporter$2({
|
|
645
|
+
compression: props?.compression === "gzip" ? CompressionAlgorithm.GZIP : CompressionAlgorithm.NONE,
|
|
646
|
+
url: props?.endpoint ?? void 0,
|
|
647
|
+
timeoutMillis: validateExportTimeoutConfig(props?.timeout, "OtlpGrpcExporter.timeout"),
|
|
648
|
+
credentials: grpcCredentialsFromConfig(props?.tls),
|
|
649
|
+
metadata: getGrpcMetadataFromHeaders(props?.headers, props?.headers_list)
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
case "console": return new ConsoleSpanExporter();
|
|
653
|
+
default: throw new Error(`unknown SpanExporter name in configuration: "${name}"`);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
function createSpanProcessorFromConfig(processor) {
|
|
657
|
+
const [name, properties] = mustSingleEntry(processor, "SpanProcessor");
|
|
658
|
+
switch (name) {
|
|
659
|
+
case "batch": {
|
|
660
|
+
checkConfigUse("BatchSpanProcessor", properties, [
|
|
661
|
+
"exporter",
|
|
662
|
+
"max_queue_size",
|
|
663
|
+
"max_export_batch_size",
|
|
664
|
+
"schedule_delay",
|
|
665
|
+
"export_timeout"
|
|
666
|
+
]);
|
|
667
|
+
const props = properties;
|
|
668
|
+
const exporter = createSpanExporterFromConfig(props.exporter);
|
|
669
|
+
return new BatchSpanProcessor({
|
|
670
|
+
exporter,
|
|
671
|
+
maxQueueSize: props.max_queue_size ?? void 0,
|
|
672
|
+
maxExportBatchSize: props.max_export_batch_size ?? void 0,
|
|
673
|
+
scheduledDelayMillis: props.schedule_delay ?? void 0,
|
|
674
|
+
exportTimeoutMillis: validateExportTimeoutConfig(props.export_timeout, "BatchSpanProcessor.export_timeout")
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
case "simple": {
|
|
678
|
+
const exporter = createSpanExporterFromConfig(properties.exporter);
|
|
679
|
+
return new SimpleSpanProcessor({ exporter });
|
|
680
|
+
}
|
|
681
|
+
default: throw new Error(`unknown SpanProcessor name: "${name}"`);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* Returns a Sampler for the `tracer_provider.sampler` in configuration,
|
|
686
|
+
* or `undefined` if not set.
|
|
687
|
+
*
|
|
688
|
+
* Exported for testing.
|
|
689
|
+
*/
|
|
690
|
+
function createSamplerFromConfig(samplerConfig) {
|
|
691
|
+
if (!samplerConfig) return;
|
|
692
|
+
const [name, properties] = mustSingleEntry(samplerConfig, "Sampler");
|
|
693
|
+
switch (name) {
|
|
694
|
+
case "always_off": return new AlwaysOffSampler();
|
|
695
|
+
case "always_on": return new AlwaysOnSampler();
|
|
696
|
+
case "trace_id_ratio_based": return new TraceIdRatioBasedSampler(properties?.ratio ?? 1);
|
|
697
|
+
case "parent_based": {
|
|
698
|
+
const props = properties;
|
|
699
|
+
return new ParentBasedSampler({
|
|
700
|
+
root: createSamplerFromConfig(props?.root) ?? new AlwaysOnSampler(),
|
|
701
|
+
remoteParentSampled: createSamplerFromConfig(props?.remote_parent_sampled),
|
|
702
|
+
remoteParentNotSampled: createSamplerFromConfig(props?.remote_parent_not_sampled),
|
|
703
|
+
localParentSampled: createSamplerFromConfig(props?.local_parent_sampled),
|
|
704
|
+
localParentNotSampled: createSamplerFromConfig(props?.local_parent_not_sampled)
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
default: throw new Error(`unknown Sampler name: "${name}"`);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
function createIdGeneratorFromConfig(id_generator) {
|
|
711
|
+
if (!id_generator) return;
|
|
712
|
+
const [name] = mustSingleEntry(id_generator, "IdGenerator");
|
|
713
|
+
switch (name) {
|
|
714
|
+
case "random": return new RandomIdGenerator();
|
|
715
|
+
default: throw new Error(`unknown IdGenerator name: "${name}"`);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
function createTracerProviderFromConfig(resource, tracer_provider, attribute_limits) {
|
|
719
|
+
const spanProcessors = tracer_provider.processors.map((p) => createSpanProcessorFromConfig(p));
|
|
720
|
+
const spanLimits = createSpanLimitsFromConfig(tracer_provider.limits, attribute_limits);
|
|
721
|
+
const sampler = createSamplerFromConfig(tracer_provider.sampler);
|
|
722
|
+
const idGenerator = createIdGeneratorFromConfig(tracer_provider.id_generator);
|
|
723
|
+
checkConfigUse("TracerProvider", tracer_provider, [
|
|
724
|
+
"processors",
|
|
725
|
+
"limits",
|
|
726
|
+
"sampler",
|
|
727
|
+
"id_generator"
|
|
728
|
+
]);
|
|
729
|
+
return new TracerProvider({
|
|
730
|
+
resource,
|
|
731
|
+
spanProcessors,
|
|
732
|
+
spanLimits,
|
|
733
|
+
sampler,
|
|
734
|
+
idGenerator
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
//#endregion
|
|
738
|
+
export { createIdGeneratorFromConfig, createLogRecordExporterFromConfig, createLogRecordLimitsFromConfig, createLogRecordProcessorFromConfig, createLoggerProviderFromConfig, createMeterProviderFromConfig, createPropagatorFromConfig, createPushMetricExporterFromConfig, createResourceFromConfig, createSamplerFromConfig, createSpanLimitsFromConfig, createTracerProviderFromConfig };
|
|
739
|
+
|
|
740
|
+
//# sourceMappingURL=create-from-config.mjs.map
|