@nathapp/nestjs-observability 4.5.1 → 4.6.1
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/AGENTS.md +39 -0
- package/CLAUDE.md +37 -0
- package/GEMINI.md +37 -0
- package/codex.md +37 -0
- package/dist/metrics/http-metrics.interceptor.js +37 -31
- package/dist/metrics/http-metrics.interceptor.js.map +1 -1
- package/dist/tracing/init-tracing.js +9 -10
- package/dist/tracing/init-tracing.js.map +1 -1
- package/dist/tracing/shutdown.js +53 -13
- package/dist/tracing/shutdown.js.map +1 -1
- package/package.json +3 -3
package/AGENTS.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Agent Instructions
|
|
2
|
+
|
|
3
|
+
This file is auto-generated from `.nax/context.md`.
|
|
4
|
+
DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
5
|
+
|
|
6
|
+
These instructions apply to all AI coding agents in this project.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Project Metadata
|
|
11
|
+
|
|
12
|
+
> Auto-injected by `nax generate`
|
|
13
|
+
|
|
14
|
+
**Project:** `@nathapp/nestjs-observability`
|
|
15
|
+
|
|
16
|
+
**Language:** TypeScript
|
|
17
|
+
|
|
18
|
+
**Key dependencies:** @nathapp/typescript-config, @nestjs/common, @nestjs/core, @nestjs/testing, @types/jest, jest, ts-jest, typescript
|
|
19
|
+
|
|
20
|
+
**Commands:** test: `npm run test` | lint: `npm run lint` | typecheck: `npm run type-check && npm run type-check:test`
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
# @nathapp/nestjs-observability
|
|
24
|
+
|
|
25
|
+
Prometheus metrics and OpenTelemetry tracing with request correlation.
|
|
26
|
+
|
|
27
|
+
## Commands
|
|
28
|
+
|
|
29
|
+
Run from `packages/nestjs-observability/`. Replace the example test path with a path relative to this package.
|
|
30
|
+
|
|
31
|
+
| Purpose | Command |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| Build this package | `npm run build` |
|
|
34
|
+
| Run specific test files | `npm test -- --runTestsByPath path/to/file.spec.ts` |
|
|
35
|
+
| Run the default suite | `npm test` |
|
|
36
|
+
| Run the default suite with coverage | `npm run test:cov` |
|
|
37
|
+
| Type-check library source | `npm run type-check` |
|
|
38
|
+
| Type-check test source | `npm run type-check:test` |
|
|
39
|
+
| Lint library and test source | `npm run lint` |
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Project Context
|
|
2
|
+
|
|
3
|
+
This file is auto-generated from `.nax/context.md`.
|
|
4
|
+
DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Project Metadata
|
|
9
|
+
|
|
10
|
+
> Auto-injected by `nax generate`
|
|
11
|
+
|
|
12
|
+
**Project:** `@nathapp/nestjs-observability`
|
|
13
|
+
|
|
14
|
+
**Language:** TypeScript
|
|
15
|
+
|
|
16
|
+
**Key dependencies:** @nathapp/typescript-config, @nestjs/common, @nestjs/core, @nestjs/testing, @types/jest, jest, ts-jest, typescript
|
|
17
|
+
|
|
18
|
+
**Commands:** test: `npm run test` | lint: `npm run lint` | typecheck: `npm run type-check && npm run type-check:test`
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
# @nathapp/nestjs-observability
|
|
22
|
+
|
|
23
|
+
Prometheus metrics and OpenTelemetry tracing with request correlation.
|
|
24
|
+
|
|
25
|
+
## Commands
|
|
26
|
+
|
|
27
|
+
Run from `packages/nestjs-observability/`. Replace the example test path with a path relative to this package.
|
|
28
|
+
|
|
29
|
+
| Purpose | Command |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| Build this package | `npm run build` |
|
|
32
|
+
| Run specific test files | `npm test -- --runTestsByPath path/to/file.spec.ts` |
|
|
33
|
+
| Run the default suite | `npm test` |
|
|
34
|
+
| Run the default suite with coverage | `npm run test:cov` |
|
|
35
|
+
| Type-check library source | `npm run type-check` |
|
|
36
|
+
| Type-check test source | `npm run type-check:test` |
|
|
37
|
+
| Lint library and test source | `npm run lint` |
|
package/GEMINI.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Gemini CLI Context
|
|
2
|
+
|
|
3
|
+
This file is auto-generated from `.nax/context.md`.
|
|
4
|
+
DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Project Metadata
|
|
9
|
+
|
|
10
|
+
> Auto-injected by `nax generate`
|
|
11
|
+
|
|
12
|
+
**Project:** `@nathapp/nestjs-observability`
|
|
13
|
+
|
|
14
|
+
**Language:** TypeScript
|
|
15
|
+
|
|
16
|
+
**Key dependencies:** @nathapp/typescript-config, @nestjs/common, @nestjs/core, @nestjs/testing, @types/jest, jest, ts-jest, typescript
|
|
17
|
+
|
|
18
|
+
**Commands:** test: `npm run test` | lint: `npm run lint` | typecheck: `npm run type-check && npm run type-check:test`
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
# @nathapp/nestjs-observability
|
|
22
|
+
|
|
23
|
+
Prometheus metrics and OpenTelemetry tracing with request correlation.
|
|
24
|
+
|
|
25
|
+
## Commands
|
|
26
|
+
|
|
27
|
+
Run from `packages/nestjs-observability/`. Replace the example test path with a path relative to this package.
|
|
28
|
+
|
|
29
|
+
| Purpose | Command |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| Build this package | `npm run build` |
|
|
32
|
+
| Run specific test files | `npm test -- --runTestsByPath path/to/file.spec.ts` |
|
|
33
|
+
| Run the default suite | `npm test` |
|
|
34
|
+
| Run the default suite with coverage | `npm run test:cov` |
|
|
35
|
+
| Type-check library source | `npm run type-check` |
|
|
36
|
+
| Type-check test source | `npm run type-check:test` |
|
|
37
|
+
| Lint library and test source | `npm run lint` |
|
package/codex.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Codex Instructions
|
|
2
|
+
|
|
3
|
+
This file is auto-generated from `.nax/context.md`.
|
|
4
|
+
DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Project Metadata
|
|
9
|
+
|
|
10
|
+
> Auto-injected by `nax generate`
|
|
11
|
+
|
|
12
|
+
**Project:** `@nathapp/nestjs-observability`
|
|
13
|
+
|
|
14
|
+
**Language:** TypeScript
|
|
15
|
+
|
|
16
|
+
**Key dependencies:** @nathapp/typescript-config, @nestjs/common, @nestjs/core, @nestjs/testing, @types/jest, jest, ts-jest, typescript
|
|
17
|
+
|
|
18
|
+
**Commands:** test: `npm run test` | lint: `npm run lint` | typecheck: `npm run type-check && npm run type-check:test`
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
# @nathapp/nestjs-observability
|
|
22
|
+
|
|
23
|
+
Prometheus metrics and OpenTelemetry tracing with request correlation.
|
|
24
|
+
|
|
25
|
+
## Commands
|
|
26
|
+
|
|
27
|
+
Run from `packages/nestjs-observability/`. Replace the example test path with a path relative to this package.
|
|
28
|
+
|
|
29
|
+
| Purpose | Command |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| Build this package | `npm run build` |
|
|
32
|
+
| Run specific test files | `npm test -- --runTestsByPath path/to/file.spec.ts` |
|
|
33
|
+
| Run the default suite | `npm test` |
|
|
34
|
+
| Run the default suite with coverage | `npm run test:cov` |
|
|
35
|
+
| Type-check library source | `npm run type-check` |
|
|
36
|
+
| Type-check test source | `npm run type-check:test` |
|
|
37
|
+
| Lint library and test source | `npm run lint` |
|
|
@@ -14,6 +14,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.HttpMetricsInterceptor = exports.resolveRoute = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
|
+
const rxjs_1 = require("rxjs");
|
|
17
18
|
const operators_1 = require("rxjs/operators");
|
|
18
19
|
const metrics_providers_1 = require("./metrics.providers");
|
|
19
20
|
const safeExecute = (fn) => {
|
|
@@ -65,25 +66,29 @@ const resolveRoute = (request) => {
|
|
|
65
66
|
return 'UNKNOWN';
|
|
66
67
|
};
|
|
67
68
|
exports.resolveRoute = resolveRoute;
|
|
68
|
-
const resolveStatus = (context,
|
|
69
|
-
var _a, _b, _c;
|
|
69
|
+
const resolveStatus = (context, emptyCompletion) => {
|
|
70
|
+
var _a, _b, _c, _d;
|
|
71
|
+
const fallback = emptyCompletion ? EMPTY_COMPLETION_STATUS : 200;
|
|
70
72
|
try {
|
|
71
73
|
const response = (_b = (_a = context.switchToHttp()).getResponse) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
72
74
|
if (response) {
|
|
75
|
+
if (emptyCompletion && !(response.headersSent || response.sent || ((_c = response.raw) === null || _c === void 0 ? void 0 : _c.headersSent)))
|
|
76
|
+
return fallback;
|
|
73
77
|
if (typeof response.statusCode === 'number') {
|
|
74
78
|
return response.statusCode;
|
|
75
79
|
}
|
|
76
|
-
if (typeof ((
|
|
80
|
+
if (typeof ((_d = response.raw) === null || _d === void 0 ? void 0 : _d.statusCode) === 'number') {
|
|
77
81
|
return response.raw.statusCode;
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
return fallback;
|
|
81
85
|
}
|
|
82
|
-
catch (
|
|
86
|
+
catch (_e) {
|
|
83
87
|
return fallback;
|
|
84
88
|
}
|
|
85
89
|
};
|
|
86
90
|
const statusFromError = (err) => err instanceof common_1.HttpException ? err.getStatus() : 500;
|
|
91
|
+
const EMPTY_COMPLETION_STATUS = 500;
|
|
87
92
|
let HttpMetricsInterceptor = class HttpMetricsInterceptor {
|
|
88
93
|
constructor(requests, errors, duration) {
|
|
89
94
|
this.requests = requests;
|
|
@@ -103,36 +108,37 @@ let HttpMetricsInterceptor = class HttpMetricsInterceptor {
|
|
|
103
108
|
const request = context.switchToHttp().getRequest();
|
|
104
109
|
const method = (_a = request === null || request === void 0 ? void 0 : request.method) !== null && _a !== void 0 ? _a : 'UNKNOWN';
|
|
105
110
|
const route = (0, exports.resolveRoute)(request);
|
|
106
|
-
const startedAt = process.hrtime.bigint();
|
|
107
111
|
if (this.ignoreRoutes.has(route)) {
|
|
108
112
|
return next.handle();
|
|
109
113
|
}
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
114
|
+
const response = next.handle();
|
|
115
|
+
return (0, rxjs_1.defer)(() => {
|
|
116
|
+
const startedAt = process.hrtime.bigint();
|
|
117
|
+
let errorStatus;
|
|
118
|
+
let deliveredValue = false;
|
|
119
|
+
let completed = false;
|
|
120
|
+
return response.pipe((0, operators_1.tap)({
|
|
121
|
+
next: () => {
|
|
122
|
+
deliveredValue = true;
|
|
123
|
+
},
|
|
124
|
+
error: (err) => {
|
|
125
|
+
errorStatus = 500;
|
|
126
|
+
safeExecute(() => { errorStatus = statusFromError(err); });
|
|
127
|
+
},
|
|
128
|
+
complete: () => {
|
|
129
|
+
completed = true;
|
|
130
|
+
},
|
|
131
|
+
}), (0, operators_1.finalize)(() => {
|
|
132
|
+
const status = errorStatus !== null && errorStatus !== void 0 ? errorStatus : resolveStatus(context, completed && !deliveredValue);
|
|
133
|
+
const labels = { method, route, status: String(status) };
|
|
134
|
+
const seconds = Number(process.hrtime.bigint() - startedAt) / 1000000000;
|
|
135
|
+
safeExecute(() => { var _a, _b; return (_b = (_a = this.requests) === null || _a === void 0 ? void 0 : _a.inc) === null || _b === void 0 ? void 0 : _b.call(_a, labels); });
|
|
136
|
+
safeExecute(() => { var _a, _b; return (_b = (_a = this.duration) === null || _a === void 0 ? void 0 : _a.observe) === null || _b === void 0 ? void 0 : _b.call(_a, labels, seconds); });
|
|
137
|
+
if (status >= 500) {
|
|
138
|
+
safeExecute(() => { var _a, _b; return (_b = (_a = this.errors) === null || _a === void 0 ? void 0 : _a.inc) === null || _b === void 0 ? void 0 : _b.call(_a, labels); });
|
|
139
|
+
}
|
|
140
|
+
}));
|
|
141
|
+
});
|
|
136
142
|
}
|
|
137
143
|
};
|
|
138
144
|
exports.HttpMetricsInterceptor = HttpMetricsInterceptor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-metrics.interceptor.js","sourceRoot":"","sources":["../../lib/metrics/http-metrics.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CASwB;
|
|
1
|
+
{"version":3,"file":"http-metrics.interceptor.js","sourceRoot":"","sources":["../../lib/metrics/http-metrics.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CASwB;AACxB,+BAAyC;AACzC,8CAA+C;AAC/C,2DAI6B;AAsB7B,MAAM,WAAW,GAAG,CAAC,EAAc,EAAQ,EAAE;IAC3C,IAAI,CAAC;QACH,EAAE,EAAE,CAAC;IACP,CAAC;IAAC,WAAM,CAAC;IAET,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,GAAW,EAAU,EAAE;IACzC,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,OAAO,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF,MAAM,0BAA0B,GAC9B,+FAA+F,CAAC;AAElG,MAAM,aAAa,GAAG,CAAC,GAAW,EAAU,EAAE,CAC5C,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC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AAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,mDAA+B,CAAC,CAAA;IAEnD,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,yDAAqC,CAAC,CAAA;IAEzD,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,6DAAyC,CAAC,CAAA;;GARrD,sBAAsB,CAoElC"}
|
|
@@ -4,7 +4,6 @@ exports.registerShutdown = void 0;
|
|
|
4
4
|
exports.buildNodeSdk = buildNodeSdk;
|
|
5
5
|
exports.initTracing = initTracing;
|
|
6
6
|
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
7
|
-
const sdk_trace_base_2 = require("@opentelemetry/sdk-trace-base");
|
|
8
7
|
const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
|
|
9
8
|
const auto_instrumentations_node_1 = require("@opentelemetry/auto-instrumentations-node");
|
|
10
9
|
const sdk_node_1 = require("@opentelemetry/sdk-node");
|
|
@@ -14,26 +13,26 @@ var shutdown_2 = require("./shutdown");
|
|
|
14
13
|
Object.defineProperty(exports, "registerShutdown", { enumerable: true, get: function () { return shutdown_2.registerShutdown; } });
|
|
15
14
|
const chooseSampler = (ratio) => {
|
|
16
15
|
if (ratio === undefined)
|
|
17
|
-
return new
|
|
16
|
+
return new sdk_trace_base_1.AlwaysOnSampler();
|
|
18
17
|
if (!Number.isFinite(ratio) || ratio < 0 || ratio > 1) {
|
|
19
18
|
throw new Error(`samplingRatio must be a finite number in [0, 1], received ${ratio}`);
|
|
20
19
|
}
|
|
21
20
|
if (ratio === 0)
|
|
22
|
-
return new
|
|
21
|
+
return new sdk_trace_base_1.AlwaysOffSampler();
|
|
23
22
|
if (ratio === 1)
|
|
24
|
-
return new
|
|
25
|
-
return new
|
|
23
|
+
return new sdk_trace_base_1.AlwaysOnSampler();
|
|
24
|
+
return new sdk_trace_base_1.TraceIdRatioBasedSampler(ratio);
|
|
26
25
|
};
|
|
27
|
-
const
|
|
26
|
+
const traceProcessingOptions = (opts) => {
|
|
28
27
|
var _a;
|
|
29
28
|
const exporter = (_a = opts.exporter) !== null && _a !== void 0 ? _a : 'otlp';
|
|
30
29
|
switch (exporter) {
|
|
31
30
|
case 'console':
|
|
32
|
-
return new sdk_trace_base_1.ConsoleSpanExporter();
|
|
31
|
+
return { traceExporter: new sdk_trace_base_1.ConsoleSpanExporter() };
|
|
33
32
|
case 'otlp':
|
|
34
|
-
return new exporter_trace_otlp_http_1.OTLPTraceExporter({ url: opts.otlpUrl });
|
|
33
|
+
return { traceExporter: new exporter_trace_otlp_http_1.OTLPTraceExporter({ url: opts.otlpUrl }) };
|
|
35
34
|
case 'none':
|
|
36
|
-
return
|
|
35
|
+
return { spanProcessors: [new sdk_trace_base_1.NoopSpanProcessor()] };
|
|
37
36
|
default: {
|
|
38
37
|
const exhaustive = exporter;
|
|
39
38
|
throw new Error(`unknown exporter ${String(exhaustive)}`);
|
|
@@ -50,7 +49,7 @@ function buildNodeSdk(opts) {
|
|
|
50
49
|
return new sdk_node_1.NodeSDK({
|
|
51
50
|
resource,
|
|
52
51
|
sampler: chooseSampler(opts.samplingRatio),
|
|
53
|
-
|
|
52
|
+
...traceProcessingOptions(opts),
|
|
54
53
|
instrumentations: buildInstrumentations(opts),
|
|
55
54
|
});
|
|
56
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-tracing.js","sourceRoot":"","sources":["../../lib/tracing/init-tracing.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"init-tracing.js","sourceRoot":"","sources":["../../lib/tracing/init-tracing.ts"],"names":[],"mappings":";;;AA2DA,oCAQC;AAYD,kCAcC;AA3FD,kEAMuC;AACvC,sFAA4E;AAC5E,0FAAwF;AACxF,sDAAkD;AAClD,wDAAkE;AAElE,yCAA8C;AAI9C,uCAA8C;AAArC,4GAAA,gBAAgB,OAAA;AAEz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BAAgB,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC,gBAAgB,CAAC;IACtE,OAAO,IAAA,wDAA2B,GAAE,CAAC;AACvC,CAAC,CAAC;AAOF,SAAgB,YAAY,CAAC,IAA6B;IACxD,MAAM,QAAQ,GAAG,IAAA,kCAAsB,EAAC,EAAE,cAAc,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC9E,OAAO,IAAI,kBAAO,CAAC;QACjB,QAAQ;QACR,OAAO,EAAE,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC;QAC1C,GAAG,sBAAsB,CAAC,IAAI,CAAC;QAC/B,gBAAgB,EAAE,qBAAqB,CAAC,IAAI,CAAsB;KACnE,CAAC,CAAC;AACL,CAAC;AAID,IAAI,OAAO,GAAG,KAAK,CAAC;AAQpB,SAAgB,WAAW,CACzB,IAA6B,EAC7B,aAA4D,YAAY;IAExE,IAAI,OAAO;QAAE,OAAO;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,GAAY,UAAU,CAAC,IAAI,CAAC,CAAC;QACtC,GAAG,CAAC,KAAK,EAAE,CAAC;QACZ,IAAA,2BAAgB,EAAC,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QACvC,OAAO,GAAG,IAAI,CAAC;IACjB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gFAAgF,OAAO,IAAI,CAAC,CAAC;IACpH,CAAC;AACH,CAAC"}
|
package/dist/tracing/shutdown.js
CHANGED
|
@@ -1,19 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerShutdown = registerShutdown;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.
|
|
13
|
-
|
|
4
|
+
const node_events_1 = require("node:events");
|
|
5
|
+
const HANDLED_SIGNALS = ['SIGTERM', 'SIGINT'];
|
|
6
|
+
const isHandledSignal = (event) => event === 'SIGTERM' || event === 'SIGINT';
|
|
7
|
+
const handlers = [];
|
|
8
|
+
let draining;
|
|
9
|
+
function flush() {
|
|
10
|
+
draining !== null && draining !== void 0 ? draining : (draining = Promise.resolve().then(async () => {
|
|
11
|
+
while (handlers.length) {
|
|
12
|
+
const batch = handlers.splice(0);
|
|
13
|
+
await Promise.allSettled(batch.map(handler => Promise.resolve().then(handler)));
|
|
14
|
+
}
|
|
15
|
+
draining = undefined;
|
|
16
|
+
}));
|
|
17
|
+
return draining;
|
|
18
|
+
}
|
|
19
|
+
const removedSignalListeners = new Set();
|
|
20
|
+
function trackRemoval(event, listener) {
|
|
21
|
+
if (!isHandledSignal(event) || listener === signalListeners[event])
|
|
22
|
+
return;
|
|
23
|
+
removedSignalListeners.add(event);
|
|
24
|
+
queueMicrotask(() => removedSignalListeners.delete(event));
|
|
25
|
+
}
|
|
26
|
+
function createSignalListener(signal) {
|
|
27
|
+
const onSignal = async () => {
|
|
28
|
+
const restoreDefault = process.listenerCount(signal) === 0 && !removedSignalListeners.has(signal);
|
|
29
|
+
do {
|
|
30
|
+
await flush();
|
|
31
|
+
} while (handlers.length);
|
|
32
|
+
if (restoreDefault && process.listeners(signal).every(listener => listener === onSignal)) {
|
|
33
|
+
process.off(signal, onSignal);
|
|
34
|
+
process.kill(process.pid, signal);
|
|
35
|
+
}
|
|
14
36
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
37
|
+
return onSignal;
|
|
38
|
+
}
|
|
39
|
+
const signalListeners = {
|
|
40
|
+
SIGTERM: createSignalListener('SIGTERM'),
|
|
41
|
+
SIGINT: createSignalListener('SIGINT'),
|
|
42
|
+
};
|
|
43
|
+
function registerShutdown(handler) {
|
|
44
|
+
handlers.push(handler);
|
|
45
|
+
if (draining)
|
|
46
|
+
return;
|
|
47
|
+
if (!(0, node_events_1.getEventListeners)(process, 'removeListener').includes(trackRemoval)) {
|
|
48
|
+
process.on('removeListener', trackRemoval);
|
|
49
|
+
}
|
|
50
|
+
for (const signal of HANDLED_SIGNALS) {
|
|
51
|
+
if (!process.listeners(signal).includes(signalListeners[signal])) {
|
|
52
|
+
process.prependOnceListener(signal, signalListeners[signal]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!process.listeners('beforeExit').includes(flush)) {
|
|
56
|
+
process.once('beforeExit', flush);
|
|
57
|
+
}
|
|
18
58
|
}
|
|
19
59
|
//# sourceMappingURL=shutdown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shutdown.js","sourceRoot":"","sources":["../../lib/tracing/shutdown.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"shutdown.js","sourceRoot":"","sources":["../../lib/tracing/shutdown.ts"],"names":[],"mappings":";;AAyEA,4CAcC;AAvFD,6CAAgD;AAQhD,MAAM,eAAe,GAA6B,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAExE,MAAM,eAAe,GAAG,CAAC,KAAsB,EAA0B,EAAE,CACzE,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,QAAQ,CAAC;AAE5C,MAAM,QAAQ,GAAsB,EAAE,CAAC;AACvC,IAAI,QAAmC,CAAC;AAExC,SAAS,KAAK;IACZ,QAAQ,aAAR,QAAQ,cAAR,QAAQ,IAAR,QAAQ,GAAK,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;QAC7C,OAAO,QAAQ,CAAC,MAAM,EAAE,CAAC;YACvB,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACjC,MAAM,OAAO,CAAC,UAAU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Ae,GAA0C;IAC7D,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC;IACxC,MAAM,EAAE,oBAAoB,CAAC,QAAQ,CAAC;CACvC,CAAC;AAWF,SAAgB,gBAAgB,CAAC,OAAwB;IACvD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,IAAI,QAAQ;QAAE,OAAO;IACrB,IAAI,CAAC,IAAA,+BAAiB,EAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;QACzE,OAAO,CAAC,EAAE,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;IAC7C,CAAC;IACD,KAAK,MAAM,MAAM,IAAI,eAAe,EAAE,CAAC;QACrC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;YACjE,OAAO,CAAC,mBAAmB,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrD,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nestjs-observability",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.1",
|
|
4
4
|
"description": "First-party metrics (Prometheus) and distributed tracing (OpenTelemetry) for NestJS, joined to the nathapp correlation-id context",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@nathapp/eslint-config": "1.0.1",
|
|
44
|
-
"@nathapp/nestjs-common": "^4.
|
|
45
|
-
"@nathapp/nestjs-logging": "^4.
|
|
44
|
+
"@nathapp/nestjs-common": "^4.6.1",
|
|
45
|
+
"@nathapp/nestjs-logging": "^4.6.1",
|
|
46
46
|
"@nathapp/typescript-config": "1.0.1",
|
|
47
47
|
"@nestjs/common": "^12.0.0",
|
|
48
48
|
"@nestjs/core": "^12.0.0",
|