@application-kit/observability 0.1.0 → 0.3.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/CHANGELOG.md +26 -0
- package/README.md +98 -17
- package/dist/cjs/cqrs/cqrs-logger.d.ts +12 -0
- package/dist/cjs/cqrs/cqrs-logger.js +72 -0
- package/dist/cjs/cqrs/cqrs-logger.module.d.ts +2 -0
- package/dist/cjs/cqrs/cqrs-logger.module.js +22 -0
- package/dist/cjs/cqrs/index.d.ts +2 -0
- package/dist/cjs/cqrs/index.js +18 -0
- package/dist/cjs/health/cli/health-cli-options.interface.d.ts +3 -0
- package/dist/cjs/health/cli/health-cli-options.interface.js +2 -0
- package/dist/cjs/health/cli/health-cli.d.ts +13 -0
- package/dist/cjs/health/cli/health-cli.js +56 -0
- package/dist/cjs/health/cli/health-cli.module.d.ts +5 -0
- package/dist/cjs/health/cli/health-cli.module.js +23 -0
- package/dist/cjs/health/cli/index.d.ts +3 -0
- package/dist/cjs/health/cli/index.js +19 -0
- package/dist/cjs/health/graphql/health-check.type.d.ts +3 -0
- package/dist/cjs/health/graphql/health-check.type.js +24 -0
- package/dist/cjs/health/graphql/health-graphql.module.d.ts +5 -0
- package/dist/cjs/health/graphql/health-graphql.module.js +26 -0
- package/dist/cjs/health/graphql/health.resolver.d.ts +11 -0
- package/dist/cjs/health/graphql/health.resolver.js +55 -0
- package/dist/cjs/health/graphql/index.d.ts +3 -0
- package/dist/cjs/health/graphql/index.js +19 -0
- package/dist/cjs/health/health-checks.d.ts +10 -0
- package/dist/cjs/health/health-checks.js +53 -0
- package/dist/cjs/health/health-http.module.d.ts +5 -0
- package/dist/cjs/health/health-http.module.js +26 -0
- package/dist/cjs/health/health-module-options.interface.d.ts +9 -0
- package/dist/cjs/health/health-module-options.interface.js +2 -0
- package/dist/cjs/health/health.config.d.ts +8 -0
- package/dist/cjs/health/health.config.js +39 -0
- package/dist/cjs/health/health.controller.d.ts +14 -0
- package/dist/cjs/health/health.controller.js +78 -0
- package/dist/cjs/health/health.environment.d.ts +5 -0
- package/dist/cjs/health/health.environment.js +38 -0
- package/dist/cjs/health/health.module.d.ts +5 -0
- package/dist/cjs/health/health.module.js +28 -0
- package/dist/cjs/health/index.d.ts +8 -0
- package/dist/cjs/health/index.js +24 -0
- package/dist/cjs/health/migrations.health-indicator.d.ts +9 -0
- package/dist/cjs/health/migrations.health-indicator.js +40 -0
- package/dist/cjs/http/client-ip-options.interface.d.ts +3 -0
- package/dist/cjs/http/client-ip-options.interface.js +2 -0
- package/dist/cjs/http/index.d.ts +2 -0
- package/dist/cjs/http/index.js +18 -0
- package/dist/cjs/http/resolve-client-ip.d.ts +14 -0
- package/dist/cjs/http/resolve-client-ip.js +22 -0
- package/dist/cjs/logging/constants.d.ts +1 -0
- package/dist/cjs/logging/constants.js +4 -0
- package/dist/cjs/logging/index.d.ts +8 -0
- package/dist/cjs/logging/index.js +24 -0
- package/dist/cjs/logging/infrastructure-paths.d.ts +4 -0
- package/dist/cjs/logging/infrastructure-paths.js +9 -0
- package/dist/cjs/logging/logger.environment.d.ts +4 -0
- package/dist/cjs/logging/logger.environment.js +24 -0
- package/dist/cjs/logging/observability-logger.interface.d.ts +4 -0
- package/dist/cjs/logging/observability-logger.interface.js +2 -0
- package/dist/cjs/logging/pino-logger-options.interface.d.ts +5 -0
- package/dist/cjs/logging/pino-logger-options.interface.js +2 -0
- package/dist/cjs/logging/pino-logger.config.d.ts +15 -0
- package/dist/cjs/logging/pino-logger.config.js +104 -0
- package/dist/cjs/logging/resolve-request-id.d.ts +4 -0
- package/dist/cjs/logging/resolve-request-id.js +10 -0
- package/dist/cjs/logging/resolve-support-id.d.ts +3 -0
- package/dist/cjs/logging/resolve-support-id.js +8 -0
- package/dist/cjs/metrics/index.d.ts +3 -0
- package/dist/cjs/metrics/index.js +3 -0
- package/dist/cjs/metrics/metrics-hooks.d.ts +2 -0
- package/dist/cjs/metrics/metrics-hooks.js +37 -0
- package/dist/cjs/metrics/metrics-http.module.d.ts +5 -0
- package/dist/cjs/metrics/metrics-http.module.js +29 -0
- package/dist/cjs/metrics/metrics.controller.d.ts +7 -0
- package/dist/cjs/metrics/metrics.controller.js +42 -0
- package/dist/cjs/shared/active-span-context.d.ts +2 -0
- package/dist/cjs/shared/active-span-context.js +9 -0
- package/dist/cjs/shared/with-class-decorator.d.ts +2 -0
- package/dist/cjs/shared/with-class-decorator.js +14 -0
- package/dist/esm/cqrs/cqrs-logger.d.ts +12 -0
- package/dist/esm/cqrs/cqrs-logger.js +69 -0
- package/dist/esm/cqrs/cqrs-logger.module.d.ts +2 -0
- package/dist/esm/cqrs/cqrs-logger.module.js +19 -0
- package/dist/esm/cqrs/index.d.ts +2 -0
- package/dist/esm/cqrs/index.js +2 -0
- package/dist/esm/health/cli/health-cli-options.interface.d.ts +3 -0
- package/dist/esm/health/cli/health-cli-options.interface.js +1 -0
- package/dist/esm/health/cli/health-cli.d.ts +13 -0
- package/dist/esm/health/cli/health-cli.js +52 -0
- package/dist/esm/health/cli/health-cli.module.d.ts +5 -0
- package/dist/esm/health/cli/health-cli.module.js +20 -0
- package/dist/esm/health/cli/index.d.ts +3 -0
- package/dist/esm/health/cli/index.js +3 -0
- package/dist/esm/health/graphql/health-check.type.d.ts +3 -0
- package/dist/esm/health/graphql/health-check.type.js +21 -0
- package/dist/esm/health/graphql/health-graphql.module.d.ts +5 -0
- package/dist/esm/health/graphql/health-graphql.module.js +23 -0
- package/dist/esm/health/graphql/health.resolver.d.ts +11 -0
- package/dist/esm/health/graphql/health.resolver.js +52 -0
- package/dist/esm/health/graphql/index.d.ts +3 -0
- package/dist/esm/health/graphql/index.js +3 -0
- package/dist/esm/health/health-checks.d.ts +10 -0
- package/dist/esm/health/health-checks.js +50 -0
- package/dist/esm/health/health-http.module.d.ts +5 -0
- package/dist/esm/health/health-http.module.js +23 -0
- package/dist/esm/health/health-module-options.interface.d.ts +9 -0
- package/dist/esm/health/health-module-options.interface.js +1 -0
- package/dist/esm/health/health.config.d.ts +8 -0
- package/dist/esm/health/health.config.js +36 -0
- package/dist/esm/health/health.controller.d.ts +14 -0
- package/dist/esm/health/health.controller.js +75 -0
- package/dist/esm/health/health.environment.d.ts +5 -0
- package/dist/esm/health/health.environment.js +34 -0
- package/dist/esm/health/health.module.d.ts +5 -0
- package/dist/esm/health/health.module.js +25 -0
- package/dist/esm/health/index.d.ts +8 -0
- package/dist/esm/health/index.js +8 -0
- package/dist/esm/health/migrations.health-indicator.d.ts +9 -0
- package/dist/esm/health/migrations.health-indicator.js +37 -0
- package/dist/esm/http/client-ip-options.interface.d.ts +3 -0
- package/dist/esm/http/client-ip-options.interface.js +1 -0
- package/dist/esm/http/index.d.ts +2 -0
- package/dist/esm/http/index.js +2 -0
- package/dist/esm/http/resolve-client-ip.d.ts +14 -0
- package/dist/esm/http/resolve-client-ip.js +18 -0
- package/dist/esm/logging/constants.d.ts +1 -0
- package/dist/esm/logging/constants.js +1 -0
- package/dist/esm/logging/index.d.ts +8 -0
- package/dist/esm/logging/index.js +8 -0
- package/dist/esm/logging/infrastructure-paths.d.ts +4 -0
- package/dist/esm/logging/infrastructure-paths.js +5 -0
- package/dist/esm/logging/logger.environment.d.ts +4 -0
- package/dist/esm/logging/logger.environment.js +20 -0
- package/dist/esm/logging/observability-logger.interface.d.ts +4 -0
- package/dist/esm/logging/observability-logger.interface.js +1 -0
- package/dist/esm/logging/pino-logger-options.interface.d.ts +5 -0
- package/dist/esm/logging/pino-logger-options.interface.js +1 -0
- package/dist/esm/logging/pino-logger.config.d.ts +15 -0
- package/dist/esm/logging/pino-logger.config.js +99 -0
- package/dist/esm/logging/resolve-request-id.d.ts +4 -0
- package/dist/esm/logging/resolve-request-id.js +6 -0
- package/dist/esm/logging/resolve-support-id.d.ts +3 -0
- package/dist/esm/logging/resolve-support-id.js +4 -0
- package/dist/esm/metrics/index.d.ts +3 -0
- package/dist/esm/metrics/index.js +3 -0
- package/dist/esm/metrics/metrics-hooks.d.ts +2 -0
- package/dist/esm/metrics/metrics-hooks.js +33 -0
- package/dist/esm/metrics/metrics-http.module.d.ts +5 -0
- package/dist/esm/metrics/metrics-http.module.js +26 -0
- package/dist/esm/metrics/metrics.controller.d.ts +7 -0
- package/dist/esm/metrics/metrics.controller.js +39 -0
- package/dist/esm/shared/active-span-context.d.ts +2 -0
- package/dist/esm/shared/active-span-context.js +5 -0
- package/dist/esm/shared/with-class-decorator.d.ts +2 -0
- package/dist/esm/shared/with-class-decorator.js +10 -0
- package/package.json +140 -5
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Inject } from '@nestjs/common';
|
|
14
|
+
import { Query, Resolver } from '@nestjs/graphql';
|
|
15
|
+
import { HealthCheckService } from '@nestjs/terminus';
|
|
16
|
+
import { OBSERVABILITY_LOGGER } from '../../logging/constants.js';
|
|
17
|
+
import { HealthChecks } from '../health-checks.js';
|
|
18
|
+
import { HealthCheckType } from './health-check.type.js';
|
|
19
|
+
let HealthResolver = class HealthResolver {
|
|
20
|
+
healthCheck;
|
|
21
|
+
logger;
|
|
22
|
+
healthChecks;
|
|
23
|
+
constructor(healthCheck, logger, healthChecks) {
|
|
24
|
+
this.healthCheck = healthCheck;
|
|
25
|
+
this.logger = logger;
|
|
26
|
+
this.healthChecks = healthChecks;
|
|
27
|
+
}
|
|
28
|
+
async health() {
|
|
29
|
+
try {
|
|
30
|
+
const health = await this.healthCheck.check(this.healthChecks.build());
|
|
31
|
+
return { status: health.status };
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
this.logger.error({ err: error }, 'GraphQL health check failed');
|
|
35
|
+
return { status: 'error' };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
__decorate([
|
|
40
|
+
Query(() => HealthCheckType),
|
|
41
|
+
__metadata("design:type", Function),
|
|
42
|
+
__metadata("design:paramtypes", []),
|
|
43
|
+
__metadata("design:returntype", Promise)
|
|
44
|
+
], HealthResolver.prototype, "health", null);
|
|
45
|
+
HealthResolver = __decorate([
|
|
46
|
+
Resolver({ isAbstract: true }),
|
|
47
|
+
__param(0, Inject(HealthCheckService)),
|
|
48
|
+
__param(1, Inject(OBSERVABILITY_LOGGER)),
|
|
49
|
+
__param(2, Inject(HealthChecks)),
|
|
50
|
+
__metadata("design:paramtypes", [HealthCheckService, Object, HealthChecks])
|
|
51
|
+
], HealthResolver);
|
|
52
|
+
export { HealthResolver };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DiskHealthIndicator, HealthIndicatorFunction, MemoryHealthIndicator, TypeOrmHealthIndicator } from '@nestjs/terminus';
|
|
2
|
+
import { HealthConfig } from './health.config.js';
|
|
3
|
+
export declare class HealthChecks {
|
|
4
|
+
private readonly database;
|
|
5
|
+
private readonly memory;
|
|
6
|
+
private readonly disk;
|
|
7
|
+
private readonly config;
|
|
8
|
+
constructor(database: TypeOrmHealthIndicator, memory: MemoryHealthIndicator, disk: DiskHealthIndicator, config: HealthConfig);
|
|
9
|
+
build(): HealthIndicatorFunction[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
14
|
+
import { DiskHealthIndicator, MemoryHealthIndicator, TypeOrmHealthIndicator, } from '@nestjs/terminus';
|
|
15
|
+
import { HealthConfig } from './health.config.js';
|
|
16
|
+
let HealthChecks = class HealthChecks {
|
|
17
|
+
database;
|
|
18
|
+
memory;
|
|
19
|
+
disk;
|
|
20
|
+
config;
|
|
21
|
+
constructor(database, memory, disk, config) {
|
|
22
|
+
this.database = database;
|
|
23
|
+
this.memory = memory;
|
|
24
|
+
this.disk = disk;
|
|
25
|
+
this.config = config;
|
|
26
|
+
}
|
|
27
|
+
build() {
|
|
28
|
+
return [
|
|
29
|
+
async () => this.database.pingCheck('typeorm'),
|
|
30
|
+
async () => this.memory.checkHeap('memory_heap', this.config.memoryHeapBytes),
|
|
31
|
+
async () => this.memory.checkRSS('memory_rss', this.config.memoryRssBytes),
|
|
32
|
+
async () => this.disk.checkStorage('disk', {
|
|
33
|
+
path: '/',
|
|
34
|
+
thresholdPercent: this.config.diskThresholdPercent,
|
|
35
|
+
}),
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
HealthChecks = __decorate([
|
|
40
|
+
Injectable(),
|
|
41
|
+
__param(0, Inject(TypeOrmHealthIndicator)),
|
|
42
|
+
__param(1, Inject(MemoryHealthIndicator)),
|
|
43
|
+
__param(2, Inject(DiskHealthIndicator)),
|
|
44
|
+
__param(3, Inject(HealthConfig)),
|
|
45
|
+
__metadata("design:paramtypes", [TypeOrmHealthIndicator,
|
|
46
|
+
MemoryHealthIndicator,
|
|
47
|
+
DiskHealthIndicator,
|
|
48
|
+
HealthConfig])
|
|
49
|
+
], HealthChecks);
|
|
50
|
+
export { HealthChecks };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Module } from '@nestjs/common';
|
|
8
|
+
import { withClassDecorator } from '../shared/with-class-decorator.js';
|
|
9
|
+
import { HealthController } from './health.controller.js';
|
|
10
|
+
import { MigrationsHealthIndicator } from './migrations.health-indicator.js';
|
|
11
|
+
let HealthHttpModule = class HealthHttpModule {
|
|
12
|
+
static forRoot(options = {}) {
|
|
13
|
+
return {
|
|
14
|
+
controllers: [withClassDecorator(HealthController, options.publicRoute)],
|
|
15
|
+
module: this,
|
|
16
|
+
providers: [MigrationsHealthIndicator],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
HealthHttpModule = __decorate([
|
|
21
|
+
Module({})
|
|
22
|
+
], HealthHttpModule);
|
|
23
|
+
export { HealthHttpModule };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ModuleMetadata } from '@nestjs/common';
|
|
2
|
+
import type { TerminusModuleOptions } from '@nestjs/terminus';
|
|
3
|
+
export interface HealthCarrierOptionsInterface {
|
|
4
|
+
readonly publicRoute?: ClassDecorator;
|
|
5
|
+
}
|
|
6
|
+
export interface HealthModuleOptionsInterface {
|
|
7
|
+
readonly imports?: ModuleMetadata['imports'];
|
|
8
|
+
readonly terminus?: TerminusModuleOptions;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HealthEnvironment } from './health.environment.js';
|
|
2
|
+
export declare class HealthConfig {
|
|
3
|
+
private readonly environment;
|
|
4
|
+
get diskThresholdPercent(): number;
|
|
5
|
+
get memoryHeapBytes(): number;
|
|
6
|
+
get memoryRssBytes(): number;
|
|
7
|
+
constructor(environment: HealthEnvironment);
|
|
8
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
14
|
+
import { HealthEnvironment } from './health.environment.js';
|
|
15
|
+
const BYTES_IN_MEGABYTE = 1024 * 1024;
|
|
16
|
+
let HealthConfig = class HealthConfig {
|
|
17
|
+
environment;
|
|
18
|
+
get diskThresholdPercent() {
|
|
19
|
+
return this.environment.HEALTH_DISK_THRESHOLD_PERCENT;
|
|
20
|
+
}
|
|
21
|
+
get memoryHeapBytes() {
|
|
22
|
+
return this.environment.HEALTH_MEMORY_HEAP_MB * BYTES_IN_MEGABYTE;
|
|
23
|
+
}
|
|
24
|
+
get memoryRssBytes() {
|
|
25
|
+
return this.environment.HEALTH_MEMORY_RSS_MB * BYTES_IN_MEGABYTE;
|
|
26
|
+
}
|
|
27
|
+
constructor(environment) {
|
|
28
|
+
this.environment = environment;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
HealthConfig = __decorate([
|
|
32
|
+
Injectable(),
|
|
33
|
+
__param(0, Inject(HealthEnvironment)),
|
|
34
|
+
__metadata("design:paramtypes", [HealthEnvironment])
|
|
35
|
+
], HealthConfig);
|
|
36
|
+
export { HealthConfig };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HealthCheckResult } from '@nestjs/terminus';
|
|
2
|
+
import { HealthCheckService, TypeOrmHealthIndicator } from '@nestjs/terminus';
|
|
3
|
+
import { HealthChecks } from './health-checks.js';
|
|
4
|
+
import { MigrationsHealthIndicator } from './migrations.health-indicator.js';
|
|
5
|
+
export declare class HealthController {
|
|
6
|
+
private readonly health;
|
|
7
|
+
private readonly database;
|
|
8
|
+
private readonly migrations;
|
|
9
|
+
private readonly healthChecks;
|
|
10
|
+
constructor(health: HealthCheckService, database: TypeOrmHealthIndicator, migrations: MigrationsHealthIndicator, healthChecks: HealthChecks);
|
|
11
|
+
check(): Promise<HealthCheckResult>;
|
|
12
|
+
live(): Promise<HealthCheckResult>;
|
|
13
|
+
ready(): Promise<HealthCheckResult>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { runAsInfrastructureQuery } from '@application-kit/typeorm/logging';
|
|
14
|
+
import { Controller, Get, Inject } from '@nestjs/common';
|
|
15
|
+
import { HealthCheck, HealthCheckService, TypeOrmHealthIndicator } from '@nestjs/terminus';
|
|
16
|
+
import { HEALTH_ROUTE } from '../logging/infrastructure-paths.js';
|
|
17
|
+
import { HealthChecks } from './health-checks.js';
|
|
18
|
+
import { MigrationsHealthIndicator } from './migrations.health-indicator.js';
|
|
19
|
+
let HealthController = class HealthController {
|
|
20
|
+
health;
|
|
21
|
+
database;
|
|
22
|
+
migrations;
|
|
23
|
+
healthChecks;
|
|
24
|
+
constructor(health, database, migrations, healthChecks) {
|
|
25
|
+
this.health = health;
|
|
26
|
+
this.database = database;
|
|
27
|
+
this.migrations = migrations;
|
|
28
|
+
this.healthChecks = healthChecks;
|
|
29
|
+
}
|
|
30
|
+
async check() {
|
|
31
|
+
return runAsInfrastructureQuery(async () => this.health.check(this.healthChecks.build()));
|
|
32
|
+
}
|
|
33
|
+
async live() {
|
|
34
|
+
return this.health.check([]);
|
|
35
|
+
}
|
|
36
|
+
async ready() {
|
|
37
|
+
return runAsInfrastructureQuery(async () => this.health.check([
|
|
38
|
+
async () => this.database.pingCheck('typeorm'),
|
|
39
|
+
async () => this.migrations.isUpToDate('migrations'),
|
|
40
|
+
]));
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
__decorate([
|
|
44
|
+
Get(),
|
|
45
|
+
HealthCheck(),
|
|
46
|
+
__metadata("design:type", Function),
|
|
47
|
+
__metadata("design:paramtypes", []),
|
|
48
|
+
__metadata("design:returntype", Promise)
|
|
49
|
+
], HealthController.prototype, "check", null);
|
|
50
|
+
__decorate([
|
|
51
|
+
Get('live'),
|
|
52
|
+
HealthCheck(),
|
|
53
|
+
__metadata("design:type", Function),
|
|
54
|
+
__metadata("design:paramtypes", []),
|
|
55
|
+
__metadata("design:returntype", Promise)
|
|
56
|
+
], HealthController.prototype, "live", null);
|
|
57
|
+
__decorate([
|
|
58
|
+
Get('ready'),
|
|
59
|
+
HealthCheck(),
|
|
60
|
+
__metadata("design:type", Function),
|
|
61
|
+
__metadata("design:paramtypes", []),
|
|
62
|
+
__metadata("design:returntype", Promise)
|
|
63
|
+
], HealthController.prototype, "ready", null);
|
|
64
|
+
HealthController = __decorate([
|
|
65
|
+
Controller(HEALTH_ROUTE),
|
|
66
|
+
__param(0, Inject(HealthCheckService)),
|
|
67
|
+
__param(1, Inject(TypeOrmHealthIndicator)),
|
|
68
|
+
__param(2, Inject(MigrationsHealthIndicator)),
|
|
69
|
+
__param(3, Inject(HealthChecks)),
|
|
70
|
+
__metadata("design:paramtypes", [HealthCheckService,
|
|
71
|
+
TypeOrmHealthIndicator,
|
|
72
|
+
MigrationsHealthIndicator,
|
|
73
|
+
HealthChecks])
|
|
74
|
+
], HealthController);
|
|
75
|
+
export { HealthController };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Expose, Type } from 'class-transformer';
|
|
11
|
+
import { IsNumber } from 'class-validator';
|
|
12
|
+
export class HealthEnvironment {
|
|
13
|
+
HEALTH_DISK_THRESHOLD_PERCENT = 0.8;
|
|
14
|
+
HEALTH_MEMORY_HEAP_MB = 500;
|
|
15
|
+
HEALTH_MEMORY_RSS_MB = 800;
|
|
16
|
+
}
|
|
17
|
+
__decorate([
|
|
18
|
+
Expose(),
|
|
19
|
+
IsNumber(),
|
|
20
|
+
Type(() => Number),
|
|
21
|
+
__metadata("design:type", Object)
|
|
22
|
+
], HealthEnvironment.prototype, "HEALTH_DISK_THRESHOLD_PERCENT", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
Expose(),
|
|
25
|
+
IsNumber(),
|
|
26
|
+
Type(() => Number),
|
|
27
|
+
__metadata("design:type", Object)
|
|
28
|
+
], HealthEnvironment.prototype, "HEALTH_MEMORY_HEAP_MB", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
Expose(),
|
|
31
|
+
IsNumber(),
|
|
32
|
+
Type(() => Number),
|
|
33
|
+
__metadata("design:type", Object)
|
|
34
|
+
], HealthEnvironment.prototype, "HEALTH_MEMORY_RSS_MB", void 0);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Module } from '@nestjs/common';
|
|
8
|
+
import { TerminusModule } from '@nestjs/terminus';
|
|
9
|
+
import { HealthChecks } from './health-checks.js';
|
|
10
|
+
let HealthModule = class HealthModule {
|
|
11
|
+
static forRoot(options = {}) {
|
|
12
|
+
const terminus = TerminusModule.forRoot(options.terminus);
|
|
13
|
+
return {
|
|
14
|
+
exports: [HealthChecks, terminus],
|
|
15
|
+
global: true,
|
|
16
|
+
imports: [...options.imports ?? [], terminus],
|
|
17
|
+
module: this,
|
|
18
|
+
providers: [HealthChecks],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
HealthModule = __decorate([
|
|
23
|
+
Module({})
|
|
24
|
+
], HealthModule);
|
|
25
|
+
export { HealthModule };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './health-checks.js';
|
|
2
|
+
export * from './health-http.module.js';
|
|
3
|
+
export * from './health-module-options.interface.js';
|
|
4
|
+
export * from './health.config.js';
|
|
5
|
+
export * from './health.controller.js';
|
|
6
|
+
export * from './health.environment.js';
|
|
7
|
+
export * from './health.module.js';
|
|
8
|
+
export * from './migrations.health-indicator.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './health-checks.js';
|
|
2
|
+
export * from './health-http.module.js';
|
|
3
|
+
export * from './health-module-options.interface.js';
|
|
4
|
+
export * from './health.config.js';
|
|
5
|
+
export * from './health.controller.js';
|
|
6
|
+
export * from './health.environment.js';
|
|
7
|
+
export * from './health.module.js';
|
|
8
|
+
export * from './migrations.health-indicator.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HealthIndicatorResult } from '@nestjs/terminus';
|
|
2
|
+
import { HealthIndicatorService } from '@nestjs/terminus';
|
|
3
|
+
import { DataSource } from 'typeorm';
|
|
4
|
+
export declare class MigrationsHealthIndicator {
|
|
5
|
+
private readonly healthIndicatorService;
|
|
6
|
+
private readonly dataSource;
|
|
7
|
+
constructor(healthIndicatorService: HealthIndicatorService, dataSource: DataSource);
|
|
8
|
+
isUpToDate(key: string): Promise<HealthIndicatorResult>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
14
|
+
import { HealthIndicatorService } from '@nestjs/terminus';
|
|
15
|
+
import { InjectDataSource } from '@nestjs/typeorm';
|
|
16
|
+
import { DataSource } from 'typeorm';
|
|
17
|
+
let MigrationsHealthIndicator = class MigrationsHealthIndicator {
|
|
18
|
+
healthIndicatorService;
|
|
19
|
+
dataSource;
|
|
20
|
+
constructor(healthIndicatorService, dataSource) {
|
|
21
|
+
this.healthIndicatorService = healthIndicatorService;
|
|
22
|
+
this.dataSource = dataSource;
|
|
23
|
+
}
|
|
24
|
+
async isUpToDate(key) {
|
|
25
|
+
const hasPendingMigrations = await this.dataSource.showMigrations();
|
|
26
|
+
const indicator = this.healthIndicatorService.check(key);
|
|
27
|
+
return hasPendingMigrations ? indicator.down({ pendingMigrations: true }) : indicator.up();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
MigrationsHealthIndicator = __decorate([
|
|
31
|
+
Injectable(),
|
|
32
|
+
__param(0, Inject(HealthIndicatorService)),
|
|
33
|
+
__param(1, InjectDataSource()),
|
|
34
|
+
__metadata("design:paramtypes", [HealthIndicatorService,
|
|
35
|
+
DataSource])
|
|
36
|
+
], MigrationsHealthIndicator);
|
|
37
|
+
export { MigrationsHealthIndicator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ClientIpOptionsInterface } from './client-ip-options.interface.js';
|
|
2
|
+
export interface ClientIpSourceInterface {
|
|
3
|
+
headers?: Record<string, string | string[] | undefined> | undefined;
|
|
4
|
+
ip?: string | undefined;
|
|
5
|
+
raw?: {
|
|
6
|
+
socket?: SocketLikeInterface | undefined;
|
|
7
|
+
} | undefined;
|
|
8
|
+
socket?: SocketLikeInterface | undefined;
|
|
9
|
+
}
|
|
10
|
+
interface SocketLikeInterface {
|
|
11
|
+
remoteAddress?: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare const resolveClientIp: (request: ClientIpSourceInterface, options?: ClientIpOptionsInterface) => string;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const firstHeaderValue = (value) => {
|
|
2
|
+
const single = Array.isArray(value) ? value[0] : value;
|
|
3
|
+
return (single ?? '').trim();
|
|
4
|
+
};
|
|
5
|
+
const trustedHeaderIp = (request, trustedHeaders) => {
|
|
6
|
+
const values = trustedHeaders?.map((header) => firstHeaderValue(request.headers?.[header]));
|
|
7
|
+
return values?.find((value) => value !== '') ?? '';
|
|
8
|
+
};
|
|
9
|
+
const rawSocketIp = (request) => request.raw?.socket?.remoteAddress ?? '';
|
|
10
|
+
const socketIp = (request) => request.socket?.remoteAddress ?? rawSocketIp(request);
|
|
11
|
+
const fallbackIp = (request) => {
|
|
12
|
+
const proxyAwareIp = (request.ip ?? '').trim();
|
|
13
|
+
return proxyAwareIp === '' ? socketIp(request) : proxyAwareIp;
|
|
14
|
+
};
|
|
15
|
+
export const resolveClientIp = (request, options = {}) => {
|
|
16
|
+
const headerIp = trustedHeaderIp(request, options.trustedHeaders);
|
|
17
|
+
return headerIp === '' ? fallbackIp(request) : headerIp;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const OBSERVABILITY_LOGGER: unique symbol;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const OBSERVABILITY_LOGGER = Symbol('OBSERVABILITY_LOGGER');
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './constants.js';
|
|
2
|
+
export * from './infrastructure-paths.js';
|
|
3
|
+
export * from './logger.environment.js';
|
|
4
|
+
export * from './observability-logger.interface.js';
|
|
5
|
+
export * from './pino-logger-options.interface.js';
|
|
6
|
+
export * from './pino-logger.config.js';
|
|
7
|
+
export * from './resolve-request-id.js';
|
|
8
|
+
export * from './resolve-support-id.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './constants.js';
|
|
2
|
+
export * from './infrastructure-paths.js';
|
|
3
|
+
export * from './logger.environment.js';
|
|
4
|
+
export * from './observability-logger.interface.js';
|
|
5
|
+
export * from './pino-logger-options.interface.js';
|
|
6
|
+
export * from './pino-logger.config.js';
|
|
7
|
+
export * from './resolve-request-id.js';
|
|
8
|
+
export * from './resolve-support-id.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const HEALTH_ROUTE = 'health';
|
|
2
|
+
export const METRICS_ROUTE = 'metrics';
|
|
3
|
+
export const INFRASTRUCTURE_PATHS = [`/${HEALTH_ROUTE}`, `/${METRICS_ROUTE}`];
|
|
4
|
+
export const isInfrastructurePath = (path) => INFRASTRUCTURE_PATHS
|
|
5
|
+
.some((prefix) => path === prefix || path.startsWith(`${prefix}/`));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Expose } from 'class-transformer';
|
|
11
|
+
import { IsIn } from 'class-validator';
|
|
12
|
+
const LOG_LEVELS = ['trace', 'debug', 'info', 'warn', 'error', 'fatal', 'silent'];
|
|
13
|
+
export class LoggerEnvironment {
|
|
14
|
+
LOG_LEVEL = 'warn';
|
|
15
|
+
}
|
|
16
|
+
__decorate([
|
|
17
|
+
Expose(),
|
|
18
|
+
IsIn(LOG_LEVELS),
|
|
19
|
+
__metadata("design:type", String)
|
|
20
|
+
], LoggerEnvironment.prototype, "LOG_LEVEL", void 0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Params } from 'nestjs-pino';
|
|
2
|
+
import type { Level } from 'pino';
|
|
3
|
+
import type { PinoLoggerOptionsInterface } from './pino-logger-options.interface.js';
|
|
4
|
+
import { LoggerEnvironment } from './logger.environment.js';
|
|
5
|
+
export declare const responseLogLevel: (request: {
|
|
6
|
+
url?: string | undefined;
|
|
7
|
+
}, response: {
|
|
8
|
+
statusCode: number;
|
|
9
|
+
}, error?: Error) => Level;
|
|
10
|
+
export declare const traceContextMixin: () => Record<string, number | string>;
|
|
11
|
+
export declare class PinoLoggerConfig {
|
|
12
|
+
private readonly environment;
|
|
13
|
+
constructor(environment: LoggerEnvironment);
|
|
14
|
+
createOptions(options?: PinoLoggerOptionsInterface): Params;
|
|
15
|
+
}
|