@devopsplaybook.io/otel-utils 1.13.0 → 1.14.0-beta.46.f75fc2d
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
CHANGED
|
@@ -487,7 +487,7 @@ All three signals share the same service identity (name + version), the optional
|
|
|
487
487
|
- `@opentelemetry/core` — W3C trace context propagation
|
|
488
488
|
- `@opentelemetry/resources` / `@opentelemetry/semantic-conventions` — Resource attributes
|
|
489
489
|
|
|
490
|
-
|
|
490
|
+
Runtime dependencies are clean: `npm audit --omit=dev` reports no vulnerabilities. The full `npm audit` still reports 19 dev-only advisories in the Jest toolchain (`deepmerge`, `glob`, `minimatch`, `test-exclude` and Jest packages); they are tracked by the regular dependency-update task, not addressed here.
|
|
491
491
|
|
|
492
492
|
## Build
|
|
493
493
|
|
|
@@ -495,5 +495,7 @@ Dev-only `npm audit` advisories (such as those previously reported in the Jest t
|
|
|
495
495
|
npm ci # install the locked dependencies
|
|
496
496
|
npm run build # tsc → dist/, then type-check the specs
|
|
497
497
|
npm run lint # oxlint + Prettier check
|
|
498
|
-
npm test # Jest unit tests
|
|
498
|
+
npm test # Jest unit tests; enforces the coverage thresholds in jest.config.js
|
|
499
499
|
```
|
|
500
|
+
|
|
501
|
+
`npm pack --dry-run` lists the published files (`LICENSE`, `README.md`, `package.json` and `dist/**`); the `prepack` script builds `dist` first, so the tarball always contains a fresh build.
|
package/dist/src/ModuleLogger.js
CHANGED
|
@@ -10,6 +10,9 @@ const MIN_SEVERITY = {
|
|
|
10
10
|
error: api_1.SeverityNumber.ERROR,
|
|
11
11
|
};
|
|
12
12
|
class ModuleLogger {
|
|
13
|
+
module;
|
|
14
|
+
standardLogger;
|
|
15
|
+
consoleModeOverride;
|
|
13
16
|
constructor(module, standardLogger, options = {}) {
|
|
14
17
|
this.module = module;
|
|
15
18
|
this.standardLogger = standardLogger;
|
|
@@ -35,7 +38,6 @@ class ModuleLogger {
|
|
|
35
38
|
this.display("error", message, api_1.SeverityNumber.ERROR, normalizeError(error), context);
|
|
36
39
|
}
|
|
37
40
|
display(level, message, severityNumber = api_1.SeverityNumber.INFO, error, context) {
|
|
38
|
-
var _a;
|
|
39
41
|
if (severityNumber < MIN_SEVERITY[this.standardLogger.getLogLevel()]) {
|
|
40
42
|
return;
|
|
41
43
|
}
|
|
@@ -56,7 +58,7 @@ class ModuleLogger {
|
|
|
56
58
|
attributes["trace.id"] = spanCtx.traceId;
|
|
57
59
|
}
|
|
58
60
|
const logger = this.standardLogger.getLogger();
|
|
59
|
-
const consoleMode =
|
|
61
|
+
const consoleMode = this.consoleModeOverride ?? this.standardLogger.getConsoleMode();
|
|
60
62
|
const mirrorToConsole = consoleMode === "always" || (consoleMode === "fallback" && !logger);
|
|
61
63
|
if (mirrorToConsole) {
|
|
62
64
|
writeToConsole(level, this.formatConsoleLine(level, message, error, context));
|
|
@@ -80,7 +82,7 @@ class ModuleLogger {
|
|
|
80
82
|
const spanCtx = context.spanContext();
|
|
81
83
|
line += ` trace.id=${spanCtx.traceId} span.id=${spanCtx.spanId}`;
|
|
82
84
|
}
|
|
83
|
-
if (
|
|
85
|
+
if (error?.stack !== undefined) {
|
|
84
86
|
line += `\n${error.stack}`;
|
|
85
87
|
}
|
|
86
88
|
return line;
|
|
@@ -4,7 +4,7 @@ exports.shutdownAll = shutdownAll;
|
|
|
4
4
|
exports.registerShutdownHooks = registerShutdownHooks;
|
|
5
5
|
const configValidation_1 = require("./utils/configValidation");
|
|
6
6
|
const DEFAULT_SIGNALS = ["SIGTERM", "SIGINT"];
|
|
7
|
-
const DEFAULT_TIMEOUT_MILLIS =
|
|
7
|
+
const DEFAULT_TIMEOUT_MILLIS = 10_000;
|
|
8
8
|
/**
|
|
9
9
|
* Flushes and shuts down every provider, resolving even when one of them
|
|
10
10
|
* fails (the failure is reported with `console.warn`). There is no timeout:
|
|
@@ -58,10 +58,9 @@ function shutdownWithTimeout(providers, timeoutMillis) {
|
|
|
58
58
|
* idempotent and does not cancel an in-flight flush.
|
|
59
59
|
*/
|
|
60
60
|
function registerShutdownHooks(providers, options = {}) {
|
|
61
|
-
|
|
62
|
-
const signals = [...new Set((_a = options.signals) !== null && _a !== void 0 ? _a : DEFAULT_SIGNALS)];
|
|
61
|
+
const signals = [...new Set(options.signals ?? DEFAULT_SIGNALS)];
|
|
63
62
|
const timeoutMillis = (0, configValidation_1.normalizePositiveInteger)(options.timeoutMillis, DEFAULT_TIMEOUT_MILLIS);
|
|
64
|
-
const exitOnComplete =
|
|
63
|
+
const exitOnComplete = options.exit ?? true;
|
|
65
64
|
let shuttingDown = false;
|
|
66
65
|
function cleanup() {
|
|
67
66
|
for (const signal of signals) {
|
|
@@ -11,12 +11,14 @@ const exporterConfig_1 = require("./utils/exporterConfig");
|
|
|
11
11
|
let globalLoggerProvider;
|
|
12
12
|
const ALREADY_REGISTERED_WARNING = "[otel-utils] A global logger provider is already registered; StandardLogger will not replace it. This instance still logs through its own provider, but logs.getLogger() keeps using the existing provider.";
|
|
13
13
|
class StandardLogger {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
logger;
|
|
15
|
+
loggerProvider;
|
|
16
|
+
serviceVersion;
|
|
17
|
+
serviceName;
|
|
18
|
+
ownsGlobalProvider = false;
|
|
19
|
+
operationQueue = Promise.resolve();
|
|
20
|
+
consoleMode = "always";
|
|
21
|
+
logLevel = "info";
|
|
20
22
|
initOTel(config) {
|
|
21
23
|
return this.enqueue(() => this.doInitOTel(config));
|
|
22
24
|
}
|
|
@@ -24,9 +26,7 @@ class StandardLogger {
|
|
|
24
26
|
return this.enqueue(() => this.releaseProvider());
|
|
25
27
|
}
|
|
26
28
|
forceFlush() {
|
|
27
|
-
|
|
28
|
-
var _b;
|
|
29
|
-
return (_b = (_a = this.loggerProvider) === null || _a === void 0 ? void 0 : _a.forceFlush()) !== null && _b !== void 0 ? _b : Promise.resolve();
|
|
29
|
+
return this.loggerProvider?.forceFlush() ?? Promise.resolve();
|
|
30
30
|
}
|
|
31
31
|
getLogger() {
|
|
32
32
|
return this.logger;
|
|
@@ -42,7 +42,7 @@ export declare class StandardMeter {
|
|
|
42
42
|
createHistogram(key: string, options?: StandardMeterCreateHistogramOptions): Histogram;
|
|
43
43
|
createObservableCounter(key: string, callback: ObservableCallback, options?: MetricOptions): ObservableCounter;
|
|
44
44
|
createObservableUpDownCounter(key: string, callback: ObservableCallback, options?: MetricOptions): ObservableUpDownCounter;
|
|
45
|
-
createObservableGauge(key: string, callback:
|
|
45
|
+
createObservableGauge(key: string, callback: ObservableCallback, descriptionOrOptions?: string | MetricOptions): ObservableGauge;
|
|
46
46
|
private registerGlobalProvider;
|
|
47
47
|
private doShutdown;
|
|
48
48
|
}
|
|
@@ -19,8 +19,13 @@ const ALREADY_REGISTERED_WARNING = "[otel-utils] A global meter provider is alre
|
|
|
19
19
|
* is configured once, in its constructor.
|
|
20
20
|
*/
|
|
21
21
|
class StandardMeter {
|
|
22
|
+
meter;
|
|
23
|
+
meterProvider;
|
|
24
|
+
serviceVersion;
|
|
25
|
+
serviceName;
|
|
26
|
+
ownsGlobalProvider = false;
|
|
27
|
+
shutdownPromise;
|
|
22
28
|
constructor(config) {
|
|
23
|
-
this.ownsGlobalProvider = false;
|
|
24
29
|
(0, configValidation_1.validateServiceIdentity)(config);
|
|
25
30
|
this.serviceName = config.SERVICE_ID;
|
|
26
31
|
this.serviceVersion = config.VERSION;
|
|
@@ -76,7 +81,7 @@ class StandardMeter {
|
|
|
76
81
|
return this.meter.createUpDownCounter(`${this.serviceName}.${key}`, options);
|
|
77
82
|
}
|
|
78
83
|
createHistogram(key, options) {
|
|
79
|
-
const { unprefixed, ...instrumentOptions } = options
|
|
84
|
+
const { unprefixed, ...instrumentOptions } = options ?? {};
|
|
80
85
|
return this.meter.createHistogram(unprefixed ? key : `${this.serviceName}.${key}`, instrumentOptions);
|
|
81
86
|
}
|
|
82
87
|
createObservableCounter(key, callback, options) {
|
|
@@ -89,9 +94,7 @@ class StandardMeter {
|
|
|
89
94
|
observableUpDownCounter.addCallback(callback);
|
|
90
95
|
return observableUpDownCounter;
|
|
91
96
|
}
|
|
92
|
-
createObservableGauge(key,
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
-
callback, descriptionOrOptions) {
|
|
97
|
+
createObservableGauge(key, callback, descriptionOrOptions) {
|
|
95
98
|
const observableGauge = this.meter.createObservableGauge(key, typeof descriptionOrOptions === "string"
|
|
96
99
|
? { description: descriptionOrOptions }
|
|
97
100
|
: descriptionOrOptions);
|
|
@@ -50,8 +50,15 @@ function buildSampler(config) {
|
|
|
50
50
|
* is configured once, in its constructor.
|
|
51
51
|
*/
|
|
52
52
|
class StandardTracer {
|
|
53
|
+
static SPAN_NAME_SANITIZE_RE = /[^a-zA-Z0-9-_/]/g;
|
|
54
|
+
static PROPAGATOR = new core_1.W3CTraceContextPropagator();
|
|
55
|
+
traceProvider;
|
|
56
|
+
tracer;
|
|
57
|
+
serviceVersion;
|
|
58
|
+
serviceName;
|
|
59
|
+
ownsGlobalProvider = false;
|
|
60
|
+
shutdownPromise;
|
|
53
61
|
constructor(config) {
|
|
54
|
-
this.ownsGlobalProvider = false;
|
|
55
62
|
(0, configValidation_1.validateServiceIdentity)(config);
|
|
56
63
|
this.serviceName = config.SERVICE_ID;
|
|
57
64
|
this.serviceVersion = config.VERSION;
|
|
@@ -140,8 +147,6 @@ class StandardTracer {
|
|
|
140
147
|
}
|
|
141
148
|
}
|
|
142
149
|
exports.StandardTracer = StandardTracer;
|
|
143
|
-
StandardTracer.SPAN_NAME_SANITIZE_RE = /[^a-zA-Z0-9-_/]/g;
|
|
144
|
-
StandardTracer.PROPAGATOR = new core_1.W3CTraceContextPropagator();
|
|
145
150
|
function initializeContextManager() {
|
|
146
151
|
if (contextManagerInitialized) {
|
|
147
152
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devopsplaybook.io/otel-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0-beta.46.f75fc2d",
|
|
4
4
|
"description": "Utility to simplify integration with Open Telemetry",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Open",
|
|
@@ -10,10 +10,18 @@
|
|
|
10
10
|
"Metrics"
|
|
11
11
|
],
|
|
12
12
|
"license": "ISC",
|
|
13
|
-
"author": "",
|
|
13
|
+
"author": "Didier Hoarau",
|
|
14
14
|
"type": "commonjs",
|
|
15
15
|
"main": "dist/index.js",
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/devopsplaybook-io/otel-utils.git"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/devopsplaybook-io/otel-utils#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/devopsplaybook-io/otel-utils/issues"
|
|
24
|
+
},
|
|
17
25
|
"exports": {
|
|
18
26
|
".": {
|
|
19
27
|
"types": "./dist/index.d.ts",
|
|
@@ -31,6 +39,8 @@
|
|
|
31
39
|
"build": "tsc && tsc -p tsconfig.spec.json --noEmit",
|
|
32
40
|
"format": "prettier --write .",
|
|
33
41
|
"lint": "oxlint index.ts src && prettier --check .",
|
|
42
|
+
"prepack": "npm run build",
|
|
43
|
+
"prepublishOnly": "npm run build",
|
|
34
44
|
"test": "jest --coverage"
|
|
35
45
|
},
|
|
36
46
|
"dependencies": {
|