@safaricom-mxl/node-sdk 0.0.18 → 0.0.20
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 +13 -0
- package/dist/bin/opentelemetry-instrument.cjs +6 -6
- package/dist/bin/opentelemetry-instrument.mjs +2 -3
- package/dist/{evlog-BII4D1ne.d.mts → evlog-BBvPZ6Un.d.cts} +3 -7
- package/dist/evlog-BBvPZ6Un.d.cts.map +1 -0
- package/dist/{evlog-DP7bcV7t.d.cts → evlog-DnsHTU1C.d.mts} +3 -7
- package/dist/evlog-DnsHTU1C.d.mts.map +1 -0
- package/dist/{express-Bhkoez1P.d.cts → express-DWWuahjk.d.mts} +1 -3
- package/dist/express-DWWuahjk.d.mts.map +1 -0
- package/dist/{fastify-OrlGsmbX.d.cts → fastify-DAufwt8Z.d.mts} +1 -3
- package/dist/fastify-DAufwt8Z.d.mts.map +1 -0
- package/dist/{gcp-CKISiuHV.d.mts → gcp-DTKJr0BW.d.mts} +2 -4
- package/dist/gcp-DTKJr0BW.d.mts.map +1 -0
- package/dist/gcp.cjs +8 -11
- package/dist/gcp.d.cts +6 -2
- package/dist/gcp.d.cts.map +1 -0
- package/dist/gcp.d.mts +1 -1
- package/dist/gcp.mjs +8 -11
- package/dist/gcp.mjs.map +1 -1
- package/dist/{index-Bz-SovV2.d.cts → index-B9yoUw0E.d.mts} +18 -26
- package/dist/index-B9yoUw0E.d.mts.map +1 -0
- package/dist/{index-DQ6mCen2.d.mts → index-DUzuYLlh.d.cts} +21 -27
- package/dist/index-DUzuYLlh.d.cts.map +1 -0
- package/dist/index.cjs +9 -11
- package/dist/index.d.cts +12 -12
- package/dist/index.d.mts +12 -12
- package/dist/index.mjs +9 -11
- package/dist/index.mjs.map +1 -1
- package/dist/{initSDK-CA5vGy0p.mjs → initSDK-BQAwICCw.mjs} +466 -119
- package/dist/initSDK-BQAwICCw.mjs.map +1 -0
- package/dist/{initSDK-BwgQ0ed7.cjs → initSDK-WUqhxMoV.cjs} +470 -123
- package/dist/integrations/express.cjs +2 -3
- package/dist/integrations/express.d.cts +18 -2
- package/dist/integrations/express.d.cts.map +1 -0
- package/dist/integrations/express.d.mts +1 -1
- package/dist/integrations/express.mjs +2 -3
- package/dist/integrations/express.mjs.map +1 -1
- package/dist/integrations/fastify.cjs +2 -3
- package/dist/integrations/fastify.d.cts +6 -2
- package/dist/integrations/fastify.d.cts.map +1 -0
- package/dist/integrations/fastify.d.mts +1 -1
- package/dist/integrations/fastify.mjs +2 -3
- package/dist/integrations/fastify.mjs.map +1 -1
- package/dist/integrations/koa.cjs +2 -3
- package/dist/integrations/koa.d.cts +4 -2
- package/dist/integrations/koa.d.cts.map +1 -0
- package/dist/integrations/koa.d.mts +1 -1
- package/dist/integrations/koa.mjs +2 -3
- package/dist/integrations/nest.cjs +1 -2
- package/dist/integrations/nest.d.cts +4 -2
- package/dist/integrations/nest.d.cts.map +1 -0
- package/dist/integrations/nest.d.mts +1 -1
- package/dist/integrations/nest.mjs +1 -2
- package/dist/{json-DSW-bpAR.cjs → json-CbEbCXvy.cjs} +2 -3
- package/dist/{json-DVwqENiw.mjs → json-D8GZ_Psl.mjs} +2 -3
- package/dist/{json-DVwqENiw.mjs.map → json-D8GZ_Psl.mjs.map} +1 -1
- package/dist/{koa-B1Ko1p06.d.cts → koa-D2Ce046w.d.mts} +1 -3
- package/dist/koa-D2Ce046w.d.mts.map +1 -0
- package/dist/logger/evlog.cjs +3 -4
- package/dist/logger/evlog.d.cts +1 -1
- package/dist/logger/evlog.d.mts +1 -1
- package/dist/logger/evlog.mjs +3 -4
- package/dist/logger/evlog.mjs.map +1 -1
- package/dist/logger/nest.cjs +2 -3
- package/dist/logger/nest.d.cts +12 -2
- package/dist/logger/nest.d.cts.map +1 -0
- package/dist/logger/nest.d.mts +1 -1
- package/dist/logger/nest.mjs +2 -3
- package/dist/logger/nest.mjs.map +1 -1
- package/dist/logger/pino.cjs +5 -6
- package/dist/logger/pino.d.cts +31 -2
- package/dist/logger/pino.d.cts.map +1 -0
- package/dist/logger/pino.d.mts +1 -1
- package/dist/logger/pino.mjs +3 -4
- package/dist/logger/winston.cjs +6 -7
- package/dist/logger/winston.d.cts +28 -2
- package/dist/logger/winston.d.cts.map +1 -0
- package/dist/logger/winston.d.mts +1 -1
- package/dist/logger/winston.mjs +3 -4
- package/dist/logger/winston.mjs.map +1 -1
- package/dist/nest-D23C_cT5.d.mts +5 -0
- package/dist/nest-D23C_cT5.d.mts.map +1 -0
- package/dist/{nest-B5ufrE__.d.mts → nest-VvyIAhum.d.mts} +2 -4
- package/dist/nest-VvyIAhum.d.mts.map +1 -0
- package/dist/{otelLogger-BCV0GOWq.cjs → otelLogger-CPrxphm8.cjs} +6 -10
- package/dist/{otelLogger-DcLZFC1y.mjs → otelLogger-z2g8OuAd.mjs} +7 -11
- package/dist/{otelLogger-DcLZFC1y.mjs.map → otelLogger-z2g8OuAd.mjs.map} +1 -1
- package/dist/{pino-B-lO5HxK.d.cts → pino-CRzjSHO1.d.mts} +2 -4
- package/dist/pino-CRzjSHO1.d.mts.map +1 -0
- package/dist/{recordException-DTepFVfN.mjs → recordException-D4LkyJPb.mjs} +2 -3
- package/dist/{recordException-DTepFVfN.mjs.map → recordException-D4LkyJPb.mjs.map} +1 -1
- package/dist/{recordException-mVorhCzj.cjs → recordException-zcmSkhl5.cjs} +1 -2
- package/dist/{rolldown-runtime-VH7oDXx4.cjs → rolldown-runtime-CmQyd0Gu.cjs} +1 -2
- package/dist/tracing.cjs +2 -3
- package/dist/tracing.d.cts +2 -4
- package/dist/tracing.d.cts.map +1 -1
- package/dist/tracing.d.mts +2 -4
- package/dist/tracing.d.mts.map +1 -1
- package/dist/tracing.mjs +2 -3
- package/dist/{types-Duv0_o_x.d.mts → types-Cfpz8pqb.d.cts} +10 -5
- package/dist/types-Cfpz8pqb.d.cts.map +1 -0
- package/dist/{types-DdKOwAmI.d.cts → types-Dpuoi1cv.d.mts} +9 -4
- package/dist/types-Dpuoi1cv.d.mts.map +1 -0
- package/dist/{types-BsieoQtI.d.cts → types-TwVQ-GEN.d.cts} +2 -4
- package/dist/types-TwVQ-GEN.d.cts.map +1 -0
- package/dist/{types-Dtp1_OwC.d.mts → types-hBHUXkBe.d.mts} +2 -4
- package/dist/types-hBHUXkBe.d.mts.map +1 -0
- package/dist/{winston-BmRwq75d.d.mts → winston-Bi-Tdd0D.d.mts} +2 -4
- package/dist/winston-Bi-Tdd0D.d.mts.map +1 -0
- package/package.json +23 -22
- package/dist/evlog-BII4D1ne.d.mts.map +0 -1
- package/dist/evlog-DP7bcV7t.d.cts.map +0 -1
- package/dist/express-Bhkoez1P.d.cts.map +0 -1
- package/dist/express-Bhkoez1P.d.mts +0 -20
- package/dist/express-Bhkoez1P.d.mts.map +0 -1
- package/dist/fastify-OrlGsmbX.d.cts.map +0 -1
- package/dist/fastify-OrlGsmbX.d.mts +0 -8
- package/dist/fastify-OrlGsmbX.d.mts.map +0 -1
- package/dist/gcp-CKISiuHV.d.mts.map +0 -1
- package/dist/gcp-DWryQGf5.d.cts +0 -9
- package/dist/gcp-DWryQGf5.d.cts.map +0 -1
- package/dist/index-Bz-SovV2.d.cts.map +0 -1
- package/dist/index-DQ6mCen2.d.mts.map +0 -1
- package/dist/initSDK-CA5vGy0p.mjs.map +0 -1
- package/dist/koa-B1Ko1p06.d.cts.map +0 -1
- package/dist/koa-B1Ko1p06.d.mts +0 -7
- package/dist/koa-B1Ko1p06.d.mts.map +0 -1
- package/dist/nest-8gUTpgCB.d.cts +0 -7
- package/dist/nest-8gUTpgCB.d.cts.map +0 -1
- package/dist/nest-B5ufrE__.d.mts.map +0 -1
- package/dist/nest-C6fqfCBa.d.cts +0 -15
- package/dist/nest-C6fqfCBa.d.cts.map +0 -1
- package/dist/nest-Df9hU7gJ.d.mts +0 -7
- package/dist/nest-Df9hU7gJ.d.mts.map +0 -1
- package/dist/pino-B-lO5HxK.d.cts.map +0 -1
- package/dist/pino-D6VfyKmW.d.mts +0 -33
- package/dist/pino-D6VfyKmW.d.mts.map +0 -1
- package/dist/types-BsieoQtI.d.cts.map +0 -1
- package/dist/types-DdKOwAmI.d.cts.map +0 -1
- package/dist/types-Dtp1_OwC.d.mts.map +0 -1
- package/dist/types-Duv0_o_x.d.mts.map +0 -1
- package/dist/winston-BmRwq75d.d.mts.map +0 -1
- package/dist/winston-DvH6EQ93.d.cts +0 -31
- package/dist/winston-DvH6EQ93.d.cts.map +0 -1
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
const require_rolldown_runtime = require("./rolldown-runtime-
|
|
2
|
-
const require_otelLogger = require("./otelLogger-BCV0GOWq.cjs");
|
|
3
|
-
const require_logger_winston = require("./logger/winston.cjs");
|
|
4
|
-
const require_recordException = require("./recordException-mVorhCzj.cjs");
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-CmQyd0Gu.cjs");
|
|
5
2
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
6
|
-
_opentelemetry_api = require_rolldown_runtime.__toESM(_opentelemetry_api, 1);
|
|
7
|
-
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
8
3
|
let _opentelemetry_auto_instrumentations_node = require("@opentelemetry/auto-instrumentations-node");
|
|
9
4
|
let _opentelemetry_instrumentation_runtime_node = require("@opentelemetry/instrumentation-runtime-node");
|
|
10
5
|
let _opentelemetry_sdk_node = require("@opentelemetry/sdk-node");
|
|
11
|
-
let _opentelemetry_instrumentation = require("@opentelemetry/instrumentation");
|
|
12
|
-
let lodash_isobject = require("lodash.isobject");
|
|
13
|
-
lodash_isobject = require_rolldown_runtime.__toESM(lodash_isobject, 1);
|
|
14
|
-
let lodash_isplainobject = require("lodash.isplainobject");
|
|
15
|
-
lodash_isplainobject = require_rolldown_runtime.__toESM(lodash_isplainobject, 1);
|
|
16
6
|
let node_async_hooks = require("node:async_hooks");
|
|
17
7
|
let node_events = require("node:events");
|
|
18
|
-
let _opentelemetry_resources = require("@opentelemetry/resources");
|
|
19
|
-
let node_module = require("node:module");
|
|
20
|
-
let node_http = require("node:http");
|
|
21
|
-
node_http = require_rolldown_runtime.__toESM(node_http, 1);
|
|
22
|
-
let node_stream = require("node:stream");
|
|
23
|
-
let node_zlib = require("node:zlib");
|
|
24
|
-
node_zlib = require_rolldown_runtime.__toESM(node_zlib, 1);
|
|
25
|
-
let _opentelemetry_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
26
8
|
let _opentelemetry_exporter_metrics_otlp_grpc = require("@opentelemetry/exporter-metrics-otlp-grpc");
|
|
27
9
|
let _opentelemetry_exporter_metrics_otlp_proto = require("@opentelemetry/exporter-metrics-otlp-proto");
|
|
28
10
|
let _opentelemetry_sdk_metrics = require("@opentelemetry/sdk-metrics");
|
|
11
|
+
const require_otelLogger = require("./otelLogger-CPrxphm8.cjs");
|
|
29
12
|
let _opentelemetry_exporter_trace_otlp_grpc = require("@opentelemetry/exporter-trace-otlp-grpc");
|
|
30
13
|
let _opentelemetry_exporter_trace_otlp_proto = require("@opentelemetry/exporter-trace-otlp-proto");
|
|
31
|
-
|
|
14
|
+
let node_module = require("node:module");
|
|
15
|
+
let _opentelemetry_instrumentation = require("@opentelemetry/instrumentation");
|
|
16
|
+
let lodash_isobject = require("lodash.isobject");
|
|
17
|
+
let lodash_isplainobject = require("lodash.isplainobject");
|
|
18
|
+
const require_logger_winston = require("./logger/winston.cjs");
|
|
19
|
+
const require_recordException = require("./recordException-zcmSkhl5.cjs");
|
|
20
|
+
let node_http = require("node:http");
|
|
21
|
+
let node_stream = require("node:stream");
|
|
22
|
+
let node_zlib = require("node:zlib");
|
|
23
|
+
let _opentelemetry_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
24
|
+
let node_inspector = require("node:inspector");
|
|
25
|
+
let _opentelemetry_resources = require("@opentelemetry/resources");
|
|
26
|
+
let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
27
|
+
_opentelemetry_api = require_rolldown_runtime.__toESM(_opentelemetry_api, 1);
|
|
28
|
+
lodash_isobject = require_rolldown_runtime.__toESM(lodash_isobject, 1);
|
|
29
|
+
lodash_isplainobject = require_rolldown_runtime.__toESM(lodash_isplainobject, 1);
|
|
30
|
+
node_http = require_rolldown_runtime.__toESM(node_http, 1);
|
|
31
|
+
node_zlib = require_rolldown_runtime.__toESM(node_zlib, 1);
|
|
32
|
+
// src/context/AbstractAsyncHooksContextManager.ts
|
|
32
33
|
const ADD_LISTENER_METHODS = [
|
|
33
34
|
"addListener",
|
|
34
35
|
"on",
|
|
@@ -119,8 +120,7 @@ var AbstractAsyncHooksContextManager = class {
|
|
|
119
120
|
_kOtListeners = Symbol("OtListeners");
|
|
120
121
|
_wrapped = false;
|
|
121
122
|
};
|
|
122
|
-
|
|
123
|
-
//#region src/context/MutableAsyncLocalStorageContextManager.ts
|
|
123
|
+
// src/context/MutableAsyncLocalStorageContextManager.ts
|
|
124
124
|
var MutableAsyncLocalStorageContextManager = class extends AbstractAsyncHooksContextManager {
|
|
125
125
|
asyncLocalStorage;
|
|
126
126
|
constructor() {
|
|
@@ -149,8 +149,7 @@ var MutableAsyncLocalStorageContextManager = class extends AbstractAsyncHooksCon
|
|
|
149
149
|
return this;
|
|
150
150
|
}
|
|
151
151
|
};
|
|
152
|
-
|
|
153
|
-
//#region src/context/contextManager.ts
|
|
152
|
+
// src/context/contextManager.ts
|
|
154
153
|
let mutableContextManager;
|
|
155
154
|
function setMutableContextManager(manager) {
|
|
156
155
|
mutableContextManager = manager;
|
|
@@ -165,8 +164,59 @@ function getTraceAttributes() {
|
|
|
165
164
|
if (!mutableContext) return {};
|
|
166
165
|
return Object.fromEntries(mutableContext.traceAttributes);
|
|
167
166
|
}
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
// src/exporters/metricReader.ts
|
|
168
|
+
function createMetricReader(config) {
|
|
169
|
+
const url = require_otelLogger.resolveOtlpExporterUrl({
|
|
170
|
+
kind: "metric",
|
|
171
|
+
endpoint: config.otlpEndpoint
|
|
172
|
+
});
|
|
173
|
+
const headers = require_otelLogger.parseOtlpHeaders(config.otlpHeaders);
|
|
174
|
+
const exporter = config.otlpProtocol === "grpc" ? new _opentelemetry_exporter_metrics_otlp_grpc.OTLPMetricExporter({
|
|
175
|
+
url,
|
|
176
|
+
headers
|
|
177
|
+
}) : new _opentelemetry_exporter_metrics_otlp_proto.OTLPMetricExporter({
|
|
178
|
+
url,
|
|
179
|
+
headers
|
|
180
|
+
});
|
|
181
|
+
return new _opentelemetry_sdk_metrics.PeriodicExportingMetricReader({
|
|
182
|
+
exporter,
|
|
183
|
+
exportIntervalMillis: require_otelLogger.DEFAULT_METRIC_EXPORT_INTERVAL_MS,
|
|
184
|
+
exportTimeoutMillis: require_otelLogger.DEFAULT_METRIC_EXPORT_TIMEOUT_MS
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
// src/exporters/traceExporter.ts
|
|
188
|
+
function createTraceExporter(config) {
|
|
189
|
+
const url = require_otelLogger.resolveOtlpExporterUrl({
|
|
190
|
+
kind: "trace",
|
|
191
|
+
endpoint: config.otlpEndpoint,
|
|
192
|
+
explicitUrl: config.traceExporterUrl
|
|
193
|
+
});
|
|
194
|
+
const headers = require_otelLogger.parseOtlpHeaders(config.otlpHeaders);
|
|
195
|
+
if (config.otlpProtocol === "grpc") return new _opentelemetry_exporter_trace_otlp_grpc.OTLPTraceExporter({
|
|
196
|
+
url,
|
|
197
|
+
timeoutMillis: require_otelLogger.DEFAULT_TRACE_TIMEOUT_MS,
|
|
198
|
+
headers
|
|
199
|
+
});
|
|
200
|
+
return new _opentelemetry_exporter_trace_otlp_proto.OTLPTraceExporter({
|
|
201
|
+
url,
|
|
202
|
+
timeoutMillis: require_otelLogger.DEFAULT_TRACE_TIMEOUT_MS,
|
|
203
|
+
headers
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
// src/instrumentations/exceptions/sentry.ts
|
|
207
|
+
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
208
|
+
function createSentryBridge(enabled) {
|
|
209
|
+
if (!enabled) return;
|
|
210
|
+
try {
|
|
211
|
+
const sentry = require$1("@sentry/node");
|
|
212
|
+
return { captureException(error) {
|
|
213
|
+
sentry.captureException(error);
|
|
214
|
+
} };
|
|
215
|
+
} catch {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
// src/instrumentations/console.ts
|
|
170
220
|
const PACKAGE_NAME = "@safaricom-mxl/instrumentation-console";
|
|
171
221
|
const PACKAGE_VERSION = "0.0.4";
|
|
172
222
|
function parseConsoleArgs(args) {
|
|
@@ -242,8 +292,7 @@ var ConsoleInstrumentation = class extends _opentelemetry_instrumentation.Instru
|
|
|
242
292
|
})];
|
|
243
293
|
}
|
|
244
294
|
};
|
|
245
|
-
|
|
246
|
-
//#region src/instrumentations/exceptions/ExceptionInstrumentation.ts
|
|
295
|
+
// src/instrumentations/exceptions/ExceptionInstrumentation.ts
|
|
247
296
|
var ExceptionInstrumentation = class extends _opentelemetry_instrumentation.InstrumentationBase {
|
|
248
297
|
forceFlush;
|
|
249
298
|
uncaughtExceptionListener;
|
|
@@ -282,22 +331,7 @@ var ExceptionInstrumentation = class extends _opentelemetry_instrumentation.Inst
|
|
|
282
331
|
this.unhandledRejectionListener = void 0;
|
|
283
332
|
}
|
|
284
333
|
};
|
|
285
|
-
|
|
286
|
-
//#region src/instrumentations/exceptions/sentry.ts
|
|
287
|
-
const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
288
|
-
function createSentryBridge(enabled) {
|
|
289
|
-
if (!enabled) return;
|
|
290
|
-
try {
|
|
291
|
-
const sentry = require$1("@sentry/node");
|
|
292
|
-
return { captureException(error) {
|
|
293
|
-
sentry.captureException(error);
|
|
294
|
-
} };
|
|
295
|
-
} catch {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
//#endregion
|
|
300
|
-
//#region src/instrumentations/http.ts
|
|
334
|
+
// src/instrumentations/http.ts
|
|
301
335
|
const SENSITIVE_DATA_SUBSTITUTE = "[Filtered]";
|
|
302
336
|
const DEFAULT_DENYLIST = [
|
|
303
337
|
"password",
|
|
@@ -481,8 +515,7 @@ function getAdvancedHttpInstrumentationConfig({ captureBodyKeywordsFilter, captu
|
|
|
481
515
|
}
|
|
482
516
|
};
|
|
483
517
|
}
|
|
484
|
-
|
|
485
|
-
//#region src/processors/CompositeSpanProcessor.ts
|
|
518
|
+
// src/processors/CompositeSpanProcessor.ts
|
|
486
519
|
var CompositeSpanProcessor = class {
|
|
487
520
|
processors;
|
|
488
521
|
constructor(processors) {
|
|
@@ -505,8 +538,7 @@ var CompositeSpanProcessor = class {
|
|
|
505
538
|
for (const processor of this.processors) processor.onEnd(span);
|
|
506
539
|
}
|
|
507
540
|
};
|
|
508
|
-
|
|
509
|
-
//#region src/processors/FilterWhenDrainedSpanProcessor.ts
|
|
541
|
+
// src/processors/FilterWhenDrainedSpanProcessor.ts
|
|
510
542
|
var FilterWhenDrainedSpanProcessor = class {
|
|
511
543
|
delegate;
|
|
512
544
|
drained = false;
|
|
@@ -532,8 +564,7 @@ var FilterWhenDrainedSpanProcessor = class {
|
|
|
532
564
|
return this.delegate.shutdown();
|
|
533
565
|
}
|
|
534
566
|
};
|
|
535
|
-
|
|
536
|
-
//#region src/processors/NodeSpanProcessor.ts
|
|
567
|
+
// src/processors/NodeSpanProcessor.ts
|
|
537
568
|
var NodeSpanProcessor = class extends _opentelemetry_sdk_trace_base.BatchSpanProcessor {
|
|
538
569
|
constructor(exporter) {
|
|
539
570
|
super(exporter);
|
|
@@ -553,8 +584,343 @@ var NodeSpanProcessor = class extends _opentelemetry_sdk_trace_base.BatchSpanPro
|
|
|
553
584
|
super.onEnd(span);
|
|
554
585
|
}
|
|
555
586
|
};
|
|
556
|
-
|
|
557
|
-
|
|
587
|
+
// src/profiling/ProfilingSpanProcessor.ts
|
|
588
|
+
var ProfilingSpanProcessor = class {
|
|
589
|
+
#timeline;
|
|
590
|
+
#stack = [];
|
|
591
|
+
constructor(timeline) {
|
|
592
|
+
this.#timeline = timeline;
|
|
593
|
+
}
|
|
594
|
+
onStart(span, _parentContext) {
|
|
595
|
+
const context = span.spanContext();
|
|
596
|
+
const current = (context.traceFlags & _opentelemetry_api.TraceFlags.SAMPLED) === _opentelemetry_api.TraceFlags.SAMPLED ? {
|
|
597
|
+
traceId: context.traceId,
|
|
598
|
+
spanId: context.spanId
|
|
599
|
+
} : void 0;
|
|
600
|
+
this.#stack.push(current);
|
|
601
|
+
this.#timeline.note(current);
|
|
602
|
+
}
|
|
603
|
+
onEnd(_span) {
|
|
604
|
+
this.#stack.pop();
|
|
605
|
+
this.#timeline.note(this.#stack.at(-1));
|
|
606
|
+
}
|
|
607
|
+
forceFlush() {
|
|
608
|
+
return Promise.resolve();
|
|
609
|
+
}
|
|
610
|
+
shutdown() {
|
|
611
|
+
return Promise.resolve();
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
// src/profiling/span-timeline.ts
|
|
615
|
+
const SPAN_EVENT_CAPACITY = 1 << 17;
|
|
616
|
+
const makeSpanTimeline = (options = {}) => {
|
|
617
|
+
const capacity = options.capacity ?? 131072;
|
|
618
|
+
const now = options.now ?? (() => performance.now());
|
|
619
|
+
let times = new Float64Array(capacity);
|
|
620
|
+
let spans = [];
|
|
621
|
+
let length = 0;
|
|
622
|
+
let overflowed = false;
|
|
623
|
+
let recording = false;
|
|
624
|
+
let current;
|
|
625
|
+
const push = (span) => {
|
|
626
|
+
if (length >= capacity) {
|
|
627
|
+
overflowed = true;
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
times[length] = now();
|
|
631
|
+
spans[length] = span;
|
|
632
|
+
length += 1;
|
|
633
|
+
};
|
|
634
|
+
return {
|
|
635
|
+
note: (span) => {
|
|
636
|
+
current = span;
|
|
637
|
+
if (recording) push(span);
|
|
638
|
+
},
|
|
639
|
+
setRecording: (next) => {
|
|
640
|
+
if (next && !recording && current !== void 0) push(current);
|
|
641
|
+
recording = next;
|
|
642
|
+
},
|
|
643
|
+
drain: () => {
|
|
644
|
+
const drained = {
|
|
645
|
+
times,
|
|
646
|
+
spans,
|
|
647
|
+
length,
|
|
648
|
+
overflowed
|
|
649
|
+
};
|
|
650
|
+
times = new Float64Array(capacity);
|
|
651
|
+
spans = [];
|
|
652
|
+
length = 0;
|
|
653
|
+
overflowed = false;
|
|
654
|
+
if (recording && current !== void 0) push(current);
|
|
655
|
+
return drained;
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
};
|
|
659
|
+
const spanAt = (events, timeMs) => {
|
|
660
|
+
if (events.length === 0 || timeMs < (events.times[0] ?? Number.POSITIVE_INFINITY)) return;
|
|
661
|
+
const last = events.length - 1;
|
|
662
|
+
if (events.overflowed && timeMs > (events.times[last] ?? 0)) return;
|
|
663
|
+
let low = 0;
|
|
664
|
+
let high = last;
|
|
665
|
+
while (low < high) {
|
|
666
|
+
const middle = low + high + 1 >>> 1;
|
|
667
|
+
if ((events.times[middle] ?? Number.POSITIVE_INFINITY) <= timeMs) low = middle;
|
|
668
|
+
else high = middle - 1;
|
|
669
|
+
}
|
|
670
|
+
return events.spans[low];
|
|
671
|
+
};
|
|
672
|
+
// src/profiling/cpu-profile.ts
|
|
673
|
+
const IDLE = "(idle)";
|
|
674
|
+
const ROOT = "(root)";
|
|
675
|
+
const FILE_SCHEME = "file://";
|
|
676
|
+
const nanos = (epochMs) => (BigInt(Math.round(epochMs * 1e3)) * 1000n).toString();
|
|
677
|
+
var Interner = class {
|
|
678
|
+
table;
|
|
679
|
+
#index = /* @__PURE__ */ new Map();
|
|
680
|
+
constructor(zero) {
|
|
681
|
+
this.table = [zero];
|
|
682
|
+
}
|
|
683
|
+
intern(key, make) {
|
|
684
|
+
const existing = this.#index.get(key);
|
|
685
|
+
if (existing !== void 0) return existing;
|
|
686
|
+
const index = this.table.length;
|
|
687
|
+
this.table.push(make());
|
|
688
|
+
this.#index.set(key, index);
|
|
689
|
+
return index;
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
const encodeCpuProfile = (profile, options) => {
|
|
693
|
+
const samples = profile.samples ?? [];
|
|
694
|
+
const deltas = profile.timeDeltas ?? [];
|
|
695
|
+
const nodes = new Map(profile.nodes.map((node) => [node.id, node]));
|
|
696
|
+
const parents = /* @__PURE__ */ new Map();
|
|
697
|
+
for (const node of profile.nodes) for (const child of node.children ?? []) parents.set(child, node.id);
|
|
698
|
+
const strings = new Interner("");
|
|
699
|
+
const string = (value) => value === "" ? 0 : strings.intern(value, () => value);
|
|
700
|
+
const functions = new Interner({});
|
|
701
|
+
const locations = new Interner({});
|
|
702
|
+
const stacks = new Interner({});
|
|
703
|
+
const links = new Interner({});
|
|
704
|
+
const locationOf = (nodeId) => {
|
|
705
|
+
const frame = nodes.get(nodeId)?.callFrame;
|
|
706
|
+
if (frame === void 0 || frame.functionName === ROOT) return void 0;
|
|
707
|
+
const file = frame.url.startsWith(FILE_SCHEME) ? frame.url.slice(7) : frame.url;
|
|
708
|
+
const line = frame.lineNumber >= 0 ? frame.lineNumber + 1 : 0;
|
|
709
|
+
const key = `${frame.functionName}\u0000${file}\u0000${line}`;
|
|
710
|
+
return locations.intern(key, () => ({ lines: [{
|
|
711
|
+
functionIndex: functions.intern(key, () => ({
|
|
712
|
+
nameStrindex: string(frame.functionName === "" ? "(anonymous)" : frame.functionName),
|
|
713
|
+
filenameStrindex: string(file),
|
|
714
|
+
startLine: line
|
|
715
|
+
})),
|
|
716
|
+
line
|
|
717
|
+
}] }));
|
|
718
|
+
};
|
|
719
|
+
const stackOf = (nodeId) => stacks.intern(String(nodeId), () => {
|
|
720
|
+
const locationIndices = [];
|
|
721
|
+
for (let current = nodeId; current !== void 0; current = parents.get(current)) {
|
|
722
|
+
const location = locationOf(current);
|
|
723
|
+
if (location !== void 0) locationIndices.push(location);
|
|
724
|
+
}
|
|
725
|
+
return { locationIndices };
|
|
726
|
+
});
|
|
727
|
+
const maxSampleMicros = options.samplingIntervalMicros;
|
|
728
|
+
const groups = /* @__PURE__ */ new Map();
|
|
729
|
+
let elapsedMicros = 0;
|
|
730
|
+
for (let index = 0; index < samples.length; index++) {
|
|
731
|
+
elapsedMicros += deltas[index] ?? 0;
|
|
732
|
+
const nodeId = samples[index];
|
|
733
|
+
if (nodeId === void 0 || nodes.get(nodeId)?.callFrame.functionName === IDLE) continue;
|
|
734
|
+
const valueMicros = Math.min(Math.max(deltas[index + 1] ?? options.samplingIntervalMicros, 0), maxSampleMicros);
|
|
735
|
+
const offsetMs = elapsedMicros / 1e3;
|
|
736
|
+
const span = options.spanEvents === void 0 ? void 0 : spanAt(options.spanEvents, options.startedAtPerfMs + offsetMs);
|
|
737
|
+
const linkIndex = span === void 0 ? 0 : links.intern(span.spanId, () => ({
|
|
738
|
+
traceId: span.traceId,
|
|
739
|
+
spanId: span.spanId
|
|
740
|
+
}));
|
|
741
|
+
const key = `${nodeId}|${linkIndex}`;
|
|
742
|
+
const group = groups.get(key);
|
|
743
|
+
if (group === void 0) groups.set(key, {
|
|
744
|
+
nodeId,
|
|
745
|
+
linkIndex,
|
|
746
|
+
valueNanos: valueMicros * 1e3,
|
|
747
|
+
firstEpochMs: options.startedAtEpochMs + offsetMs
|
|
748
|
+
});
|
|
749
|
+
else group.valueNanos += valueMicros * 1e3;
|
|
750
|
+
}
|
|
751
|
+
if (groups.size === 0) return void 0;
|
|
752
|
+
const cpu = {
|
|
753
|
+
typeStrindex: string("cpu"),
|
|
754
|
+
unitStrindex: string("nanoseconds")
|
|
755
|
+
};
|
|
756
|
+
const profileSamples = [...groups.values()].map((group) => ({
|
|
757
|
+
stackIndex: stackOf(group.nodeId),
|
|
758
|
+
linkIndex: group.linkIndex,
|
|
759
|
+
values: [String(group.valueNanos)],
|
|
760
|
+
timestampsUnixNano: [nanos(group.firstEpochMs)]
|
|
761
|
+
}));
|
|
762
|
+
return {
|
|
763
|
+
resourceProfiles: [{
|
|
764
|
+
resource: options.resource,
|
|
765
|
+
scopeProfiles: [{
|
|
766
|
+
scope: { name: "@safaricom-mxl/node-sdk/profiling" },
|
|
767
|
+
profiles: [{
|
|
768
|
+
sampleType: cpu,
|
|
769
|
+
samples: profileSamples,
|
|
770
|
+
timeUnixNano: nanos(options.startedAtEpochMs),
|
|
771
|
+
durationNano: String(Math.round(options.durationMs * 1e6)),
|
|
772
|
+
periodType: cpu,
|
|
773
|
+
period: String(options.samplingIntervalMicros * 1e3),
|
|
774
|
+
profileId: options.profileId
|
|
775
|
+
}]
|
|
776
|
+
}]
|
|
777
|
+
}],
|
|
778
|
+
dictionary: {
|
|
779
|
+
mappingTable: [{}],
|
|
780
|
+
locationTable: locations.table,
|
|
781
|
+
functionTable: functions.table,
|
|
782
|
+
linkTable: links.table,
|
|
783
|
+
stringTable: strings.table,
|
|
784
|
+
attributeTable: [{}],
|
|
785
|
+
stackTable: stacks.table
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
};
|
|
789
|
+
// src/profiling/profiling.ts
|
|
790
|
+
const DEFAULT_PROFILE_WINDOW_MS = 6e4;
|
|
791
|
+
const MIN_PROFILE_WINDOW_MS = 1e3;
|
|
792
|
+
const MIN_SAMPLING_INTERVAL_MICROS = 100;
|
|
793
|
+
const DEFAULT_SAMPLING_INTERVAL_MICROS = 1e4;
|
|
794
|
+
const PROFILER_SETUP_TIMEOUT_MS = 5e3;
|
|
795
|
+
const PROFILER_COMMAND_TIMEOUT_MS = 5e3;
|
|
796
|
+
const EXPORT_TIMEOUT_MS = 1e4;
|
|
797
|
+
const PROFILES_PATH = "/v1development/profiles";
|
|
798
|
+
const profileWindowMs = (window) => Math.max(MIN_PROFILE_WINDOW_MS, window === void 0 || !Number.isFinite(window) || window <= 0 ? DEFAULT_PROFILE_WINDOW_MS : window);
|
|
799
|
+
const samplingIntervalOf = (micros) => micros === void 0 || !Number.isFinite(micros) || micros <= 0 ? DEFAULT_SAMPLING_INTERVAL_MICROS : Math.max(MIN_SAMPLING_INTERVAL_MICROS, Math.round(micros));
|
|
800
|
+
const post = (session, method, params, timeoutMs) => new Promise((resolve, reject) => {
|
|
801
|
+
let settled = false;
|
|
802
|
+
const timer = setTimeout(() => {
|
|
803
|
+
if (settled) return;
|
|
804
|
+
settled = true;
|
|
805
|
+
reject(/* @__PURE__ */ new Error(`${method} got no answer within ${timeoutMs} ms`));
|
|
806
|
+
}, timeoutMs);
|
|
807
|
+
session.post(method, params, (error, reply) => {
|
|
808
|
+
if (settled) return;
|
|
809
|
+
settled = true;
|
|
810
|
+
clearTimeout(timer);
|
|
811
|
+
if (error) reject(error);
|
|
812
|
+
else resolve(reply);
|
|
813
|
+
});
|
|
814
|
+
});
|
|
815
|
+
const randomHex = (bytes) => Buffer.from(crypto.getRandomValues(new Uint8Array(bytes))).toString("hex");
|
|
816
|
+
const withTimeout = (promise, ms, message) => {
|
|
817
|
+
const timeout = new Promise((_, reject) => {
|
|
818
|
+
setTimeout(() => reject(new Error(message)), ms);
|
|
819
|
+
});
|
|
820
|
+
return Promise.race([promise, timeout]);
|
|
821
|
+
};
|
|
822
|
+
let profilerHolders = 0;
|
|
823
|
+
const startCpuProfiler = (options) => {
|
|
824
|
+
profilerHolders += 1;
|
|
825
|
+
if (profilerHolders > 1) return { stop: async () => {
|
|
826
|
+
profilerHolders = Math.max(0, profilerHolders - 1);
|
|
827
|
+
} };
|
|
828
|
+
let stopped = false;
|
|
829
|
+
let loop;
|
|
830
|
+
let session;
|
|
831
|
+
const windowMs = profileWindowMs(options.profiling.window);
|
|
832
|
+
const samplingIntervalMicros = samplingIntervalOf(options.profiling.samplingIntervalMicros);
|
|
833
|
+
const url = `${options.baseUrl.replace(/\/$/, "")}${PROFILES_PATH}`;
|
|
834
|
+
let overflowWarned = false;
|
|
835
|
+
const send = async (body) => {
|
|
836
|
+
const controller = new AbortController();
|
|
837
|
+
const timer = setTimeout(() => controller.abort(), EXPORT_TIMEOUT_MS);
|
|
838
|
+
try {
|
|
839
|
+
await (await fetch(url, {
|
|
840
|
+
method: "POST",
|
|
841
|
+
headers: {
|
|
842
|
+
"content-type": "application/json",
|
|
843
|
+
"OTLP-Profiles-Development-Version": "1",
|
|
844
|
+
...options.headers
|
|
845
|
+
},
|
|
846
|
+
body: JSON.stringify(body),
|
|
847
|
+
signal: controller.signal
|
|
848
|
+
})).arrayBuffer();
|
|
849
|
+
} finally {
|
|
850
|
+
clearTimeout(timer);
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
const run = async () => {
|
|
854
|
+
const inspectorSession = new node_inspector.Session();
|
|
855
|
+
session = inspectorSession;
|
|
856
|
+
inspectorSession.connect();
|
|
857
|
+
const command = (method, params = {}) => post(inspectorSession, method, params, PROFILER_COMMAND_TIMEOUT_MS);
|
|
858
|
+
await withTimeout(command("Profiler.enable"), PROFILER_SETUP_TIMEOUT_MS, "the inspector did not answer");
|
|
859
|
+
await withTimeout(command("Profiler.setSamplingInterval", { interval: samplingIntervalMicros }), PROFILER_SETUP_TIMEOUT_MS, "the inspector did not answer");
|
|
860
|
+
const startWindow = async () => {
|
|
861
|
+
const started = {
|
|
862
|
+
startedAtPerfMs: performance.now(),
|
|
863
|
+
startedAtEpochMs: Date.now()
|
|
864
|
+
};
|
|
865
|
+
await command("Profiler.start");
|
|
866
|
+
return started;
|
|
867
|
+
};
|
|
868
|
+
options.timeline?.setRecording(true);
|
|
869
|
+
let current = await startWindow();
|
|
870
|
+
const exportWindow = async (started, reply, spanEvents) => {
|
|
871
|
+
if (spanEvents?.overflowed === true && !overflowWarned) {
|
|
872
|
+
overflowWarned = true;
|
|
873
|
+
_opentelemetry_api.diag.warn(`@safaricom-mxl/node-sdk: more than ${SPAN_EVENT_CAPACITY} span switches in one window; later samples in it are not linked to spans`);
|
|
874
|
+
}
|
|
875
|
+
const profile = reply?.profile;
|
|
876
|
+
if (profile === void 0) return;
|
|
877
|
+
const body = encodeCpuProfile(profile, {
|
|
878
|
+
resource: options.resource,
|
|
879
|
+
...started,
|
|
880
|
+
durationMs: performance.now() - started.startedAtPerfMs,
|
|
881
|
+
samplingIntervalMicros,
|
|
882
|
+
spanEvents,
|
|
883
|
+
profileId: randomHex(16)
|
|
884
|
+
});
|
|
885
|
+
if (body !== void 0) await send(body);
|
|
886
|
+
};
|
|
887
|
+
while (!stopped) {
|
|
888
|
+
await new Promise((resolve) => setTimeout(resolve, windowMs));
|
|
889
|
+
if (stopped) break;
|
|
890
|
+
const ended = current;
|
|
891
|
+
const reply = await command("Profiler.stop");
|
|
892
|
+
const spanEvents = options.timeline?.drain();
|
|
893
|
+
current = await startWindow();
|
|
894
|
+
await exportWindow(ended, reply, spanEvents).catch((error) => {
|
|
895
|
+
_opentelemetry_api.diag.warn("@safaricom-mxl/node-sdk: profile export failed", error);
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
const last = await command("Profiler.stop").catch(() => void 0);
|
|
899
|
+
await exportWindow(current, last, options.timeline?.drain()).catch((error) => {
|
|
900
|
+
_opentelemetry_api.diag.warn("@safaricom-mxl/node-sdk: final profile export skipped", error);
|
|
901
|
+
});
|
|
902
|
+
};
|
|
903
|
+
loop = run().catch((error) => {
|
|
904
|
+
options.timeline?.setRecording(false);
|
|
905
|
+
_opentelemetry_api.diag.warn("@safaricom-mxl/node-sdk: profiling is off: this runtime has no CPU profiler the SDK can drive", error);
|
|
906
|
+
});
|
|
907
|
+
return { stop: async () => {
|
|
908
|
+
stopped = true;
|
|
909
|
+
options.timeline?.setRecording(false);
|
|
910
|
+
profilerHolders = Math.max(0, profilerHolders - 1);
|
|
911
|
+
const timeout = options.shutdownTimeoutMs ?? 3e3;
|
|
912
|
+
await Promise.race([loop ?? Promise.resolve(), new Promise((resolve) => setTimeout(resolve, timeout))]);
|
|
913
|
+
try {
|
|
914
|
+
session?.disconnect();
|
|
915
|
+
} catch {}
|
|
916
|
+
} };
|
|
917
|
+
};
|
|
918
|
+
const normalizeProfiling = (profiling) => {
|
|
919
|
+
if (profiling === true) return {};
|
|
920
|
+
if (profiling === false || profiling === void 0) return void 0;
|
|
921
|
+
return profiling;
|
|
922
|
+
};
|
|
923
|
+
// src/resources/nodeSdkResource.ts
|
|
558
924
|
function createNodeSdkResource(config) {
|
|
559
925
|
return (0, _opentelemetry_resources.resourceFromAttributes)({
|
|
560
926
|
[_opentelemetry_semantic_conventions.ATTR_SERVICE_NAME]: config.serviceName || (0, _opentelemetry_resources.defaultServiceName)(),
|
|
@@ -566,71 +932,7 @@ function createNodeSdkResource(config) {
|
|
|
566
932
|
...config.additionalResourceAttributes
|
|
567
933
|
});
|
|
568
934
|
}
|
|
569
|
-
|
|
570
|
-
//#region src/exporters/metricReader.ts
|
|
571
|
-
function createMetricReader(config) {
|
|
572
|
-
const url = require_otelLogger.resolveOtlpExporterUrl({
|
|
573
|
-
kind: "metric",
|
|
574
|
-
endpoint: config.otlpEndpoint
|
|
575
|
-
});
|
|
576
|
-
const headers = require_otelLogger.parseOtlpHeaders(config.otlpHeaders);
|
|
577
|
-
const exporter = config.otlpProtocol === "grpc" ? new _opentelemetry_exporter_metrics_otlp_grpc.OTLPMetricExporter({
|
|
578
|
-
url,
|
|
579
|
-
headers
|
|
580
|
-
}) : new _opentelemetry_exporter_metrics_otlp_proto.OTLPMetricExporter({
|
|
581
|
-
url,
|
|
582
|
-
headers
|
|
583
|
-
});
|
|
584
|
-
return new _opentelemetry_sdk_metrics.PeriodicExportingMetricReader({
|
|
585
|
-
exporter,
|
|
586
|
-
exportIntervalMillis: require_otelLogger.DEFAULT_METRIC_EXPORT_INTERVAL_MS,
|
|
587
|
-
exportTimeoutMillis: require_otelLogger.DEFAULT_METRIC_EXPORT_TIMEOUT_MS
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
//#endregion
|
|
591
|
-
//#region src/exporters/traceExporter.ts
|
|
592
|
-
function createTraceExporter(config) {
|
|
593
|
-
const url = require_otelLogger.resolveOtlpExporterUrl({
|
|
594
|
-
kind: "trace",
|
|
595
|
-
endpoint: config.otlpEndpoint,
|
|
596
|
-
explicitUrl: config.traceExporterUrl
|
|
597
|
-
});
|
|
598
|
-
const headers = require_otelLogger.parseOtlpHeaders(config.otlpHeaders);
|
|
599
|
-
if (config.otlpProtocol === "grpc") return new _opentelemetry_exporter_trace_otlp_grpc.OTLPTraceExporter({
|
|
600
|
-
url,
|
|
601
|
-
timeoutMillis: require_otelLogger.DEFAULT_TRACE_TIMEOUT_MS,
|
|
602
|
-
headers
|
|
603
|
-
});
|
|
604
|
-
return new _opentelemetry_exporter_trace_otlp_proto.OTLPTraceExporter({
|
|
605
|
-
url,
|
|
606
|
-
timeoutMillis: require_otelLogger.DEFAULT_TRACE_TIMEOUT_MS,
|
|
607
|
-
headers
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
//#endregion
|
|
611
|
-
//#region src/sdk/sampler.ts
|
|
612
|
-
const DEFAULT_RATIO = 1;
|
|
613
|
-
function resolveTraceSampler(traceSampler, traceSamplerArg) {
|
|
614
|
-
if (typeof traceSampler !== "string") return traceSampler;
|
|
615
|
-
switch (traceSampler) {
|
|
616
|
-
case "always_on": return new _opentelemetry_sdk_trace_base.AlwaysOnSampler();
|
|
617
|
-
case "always_off": return new _opentelemetry_sdk_trace_base.AlwaysOffSampler();
|
|
618
|
-
case "parentbased_always_on": return new _opentelemetry_sdk_trace_base.ParentBasedSampler({ root: new _opentelemetry_sdk_trace_base.AlwaysOnSampler() });
|
|
619
|
-
case "parentbased_always_off": return new _opentelemetry_sdk_trace_base.ParentBasedSampler({ root: new _opentelemetry_sdk_trace_base.AlwaysOffSampler() });
|
|
620
|
-
case "traceidratio": return new _opentelemetry_sdk_trace_base.TraceIdRatioBasedSampler(resolveSamplerRatio(traceSamplerArg));
|
|
621
|
-
case "parentbased_traceidratio": return new _opentelemetry_sdk_trace_base.ParentBasedSampler({ root: new _opentelemetry_sdk_trace_base.TraceIdRatioBasedSampler(resolveSamplerRatio(traceSamplerArg)) });
|
|
622
|
-
default:
|
|
623
|
-
_opentelemetry_api.diag.error(`@safaricom-mxl/node-sdk: unknown sampler "${traceSampler}", defaulting to always_on`);
|
|
624
|
-
return new _opentelemetry_sdk_trace_base.AlwaysOnSampler();
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
function resolveSamplerRatio(arg) {
|
|
628
|
-
const parsed = Number(arg);
|
|
629
|
-
if (!Number.isFinite(parsed) || parsed < 0 || parsed > 1) return DEFAULT_RATIO;
|
|
630
|
-
return parsed;
|
|
631
|
-
}
|
|
632
|
-
//#endregion
|
|
633
|
-
//#region src/sdk/config.ts
|
|
935
|
+
// src/sdk/config.ts
|
|
634
936
|
function resolveSDKConfig(config = {}) {
|
|
635
937
|
return {
|
|
636
938
|
additionalInstrumentations: config.additionalInstrumentations ?? [],
|
|
@@ -657,6 +959,7 @@ function resolveSDKConfig(config = {}) {
|
|
|
657
959
|
otlpEndpoint: config.otlpEndpoint ?? require_otelLogger.getStringFromEnv("OTEL_EXPORTER_OTLP_ENDPOINT"),
|
|
658
960
|
otlpHeaders: config.otlpHeaders ?? require_otelLogger.getStringFromEnv("OTEL_EXPORTER_OTLP_HEADERS"),
|
|
659
961
|
otlpProtocol: config.otlpProtocol ?? require_otelLogger.getStringFromEnv("OTEL_EXPORTER_OTLP_PROTOCOL") ?? "http/protobuf",
|
|
962
|
+
profiling: config.profiling,
|
|
660
963
|
sentryIntegrationEnabled: config.sentryIntegrationEnabled ?? require_otelLogger.getBooleanFromEnv("MXL_NODE_SENTRY_INTEGRATION_ENABLED") ?? false,
|
|
661
964
|
serviceName: config.serviceName ?? require_otelLogger.getStringFromEnv("OTEL_SERVICE_NAME") ?? "app",
|
|
662
965
|
spanLimits: config.spanLimits,
|
|
@@ -667,8 +970,28 @@ function resolveSDKConfig(config = {}) {
|
|
|
667
970
|
traceSamplerArg: config.traceSamplerArg ?? require_otelLogger.getStringFromEnv("OTEL_TRACES_SAMPLER_ARG") ?? "1"
|
|
668
971
|
};
|
|
669
972
|
}
|
|
670
|
-
|
|
671
|
-
|
|
973
|
+
// src/sdk/sampler.ts
|
|
974
|
+
const DEFAULT_RATIO = 1;
|
|
975
|
+
function resolveTraceSampler(traceSampler, traceSamplerArg) {
|
|
976
|
+
if (typeof traceSampler !== "string") return traceSampler;
|
|
977
|
+
switch (traceSampler) {
|
|
978
|
+
case "always_on": return new _opentelemetry_sdk_trace_base.AlwaysOnSampler();
|
|
979
|
+
case "always_off": return new _opentelemetry_sdk_trace_base.AlwaysOffSampler();
|
|
980
|
+
case "parentbased_always_on": return new _opentelemetry_sdk_trace_base.ParentBasedSampler({ root: new _opentelemetry_sdk_trace_base.AlwaysOnSampler() });
|
|
981
|
+
case "parentbased_always_off": return new _opentelemetry_sdk_trace_base.ParentBasedSampler({ root: new _opentelemetry_sdk_trace_base.AlwaysOffSampler() });
|
|
982
|
+
case "traceidratio": return new _opentelemetry_sdk_trace_base.TraceIdRatioBasedSampler(resolveSamplerRatio(traceSamplerArg));
|
|
983
|
+
case "parentbased_traceidratio": return new _opentelemetry_sdk_trace_base.ParentBasedSampler({ root: new _opentelemetry_sdk_trace_base.TraceIdRatioBasedSampler(resolveSamplerRatio(traceSamplerArg)) });
|
|
984
|
+
default:
|
|
985
|
+
_opentelemetry_api.diag.error(`@safaricom-mxl/node-sdk: unknown sampler "${traceSampler}", defaulting to always_on`);
|
|
986
|
+
return new _opentelemetry_sdk_trace_base.AlwaysOnSampler();
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
function resolveSamplerRatio(arg) {
|
|
990
|
+
const parsed = Number(arg);
|
|
991
|
+
if (!Number.isFinite(parsed) || parsed < 0 || parsed > 1) return DEFAULT_RATIO;
|
|
992
|
+
return parsed;
|
|
993
|
+
}
|
|
994
|
+
// src/sdk/state.ts
|
|
672
995
|
let activeConfig;
|
|
673
996
|
function setActiveSDKConfig(config) {
|
|
674
997
|
activeConfig = config;
|
|
@@ -676,12 +999,12 @@ function setActiveSDKConfig(config) {
|
|
|
676
999
|
function getActiveSDKConfig() {
|
|
677
1000
|
return activeConfig;
|
|
678
1001
|
}
|
|
679
|
-
|
|
680
|
-
//#region src/sdk/initSDK.ts
|
|
1002
|
+
// src/sdk/initSDK.ts
|
|
681
1003
|
let sdk;
|
|
682
1004
|
let logger;
|
|
683
1005
|
let contextManager;
|
|
684
1006
|
let drainableSpanProcessor;
|
|
1007
|
+
let cpuProfiler;
|
|
685
1008
|
let signalHandlersRegistered = false;
|
|
686
1009
|
const terminationHandlers = [];
|
|
687
1010
|
function initSDK(config = {}) {
|
|
@@ -705,7 +1028,13 @@ function initSDK(config = {}) {
|
|
|
705
1028
|
};
|
|
706
1029
|
logger = new require_otelLogger.OTelLogger({ config: resolved });
|
|
707
1030
|
const traceProcessor = new NodeSpanProcessor(createTraceExporter(resolved));
|
|
708
|
-
const
|
|
1031
|
+
const profiling = normalizeProfiling(resolved.profiling);
|
|
1032
|
+
const timeline = profiling !== void 0 && profiling.linkSpans !== false && !resolved.disableTracing ? makeSpanTimeline() : void 0;
|
|
1033
|
+
const spanProcessors = resolved.disableTracing ? [] : [drainableSpanProcessor = new FilterWhenDrainedSpanProcessor(new CompositeSpanProcessor([
|
|
1034
|
+
traceProcessor,
|
|
1035
|
+
...resolved.spanProcessors,
|
|
1036
|
+
...timeline === void 0 ? [] : [new ProfilingSpanProcessor(timeline)]
|
|
1037
|
+
]))];
|
|
709
1038
|
const instrumentations = [
|
|
710
1039
|
...(0, _opentelemetry_auto_instrumentations_node.getNodeAutoInstrumentations)(autoInstrumentationConfig),
|
|
711
1040
|
new _opentelemetry_instrumentation_runtime_node.RuntimeNodeInstrumentation(),
|
|
@@ -728,6 +1057,23 @@ function initSDK(config = {}) {
|
|
|
728
1057
|
});
|
|
729
1058
|
sdk.start();
|
|
730
1059
|
logger.setGlobalProvider();
|
|
1060
|
+
if (profiling !== void 0) {
|
|
1061
|
+
const tracesUrl = require_otelLogger.resolveOtlpExporterUrl({
|
|
1062
|
+
kind: "trace",
|
|
1063
|
+
endpoint: resolved.otlpEndpoint,
|
|
1064
|
+
explicitUrl: resolved.traceExporterUrl
|
|
1065
|
+
});
|
|
1066
|
+
cpuProfiler = startCpuProfiler({
|
|
1067
|
+
baseUrl: tracesUrl.replace(/\/v1\/traces\/?$/, ""),
|
|
1068
|
+
resource: { attributes: [{
|
|
1069
|
+
key: "service.name",
|
|
1070
|
+
value: { stringValue: resolved.serviceName }
|
|
1071
|
+
}] },
|
|
1072
|
+
headers: require_otelLogger.parseOtlpHeaders(resolved.otlpHeaders),
|
|
1073
|
+
profiling,
|
|
1074
|
+
timeline
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
731
1077
|
if (resolved.stopOnTerminationSignals && !signalHandlersRegistered) registerTerminationHandlers();
|
|
732
1078
|
if (!resolved.disableStartupLogs) _opentelemetry_api.diag.info("@safaricom-mxl/node-sdk: initialized");
|
|
733
1079
|
return getControl();
|
|
@@ -766,6 +1112,8 @@ async function shutdown() {
|
|
|
766
1112
|
signalHandlersRegistered = false;
|
|
767
1113
|
}
|
|
768
1114
|
drainableSpanProcessor?.drain();
|
|
1115
|
+
await cpuProfiler?.stop();
|
|
1116
|
+
cpuProfiler = void 0;
|
|
769
1117
|
await Promise.allSettled([logger?.shutdown(), sdk?.shutdown()]);
|
|
770
1118
|
sdk = void 0;
|
|
771
1119
|
logger = void 0;
|
|
@@ -780,7 +1128,6 @@ function getControl() {
|
|
|
780
1128
|
setTraceAttributes
|
|
781
1129
|
};
|
|
782
1130
|
}
|
|
783
|
-
//#endregion
|
|
784
1131
|
Object.defineProperty(exports, "forceFlush", {
|
|
785
1132
|
enumerable: true,
|
|
786
1133
|
get: function() {
|