@pawells/nestjs-shared 1.0.0-dev.4c8c698
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/LICENSE +21 -0
- package/README.md +802 -0
- package/build/LICENSE +21 -0
- package/build/README.md +802 -0
- package/build/common/common.module.d.ts +49 -0
- package/build/common/common.module.d.ts.map +1 -0
- package/build/common/common.module.js +178 -0
- package/build/common/common.module.js.map +1 -0
- package/build/common/constants/histogram-buckets.constants.d.ts +12 -0
- package/build/common/constants/histogram-buckets.constants.d.ts.map +1 -0
- package/build/common/constants/histogram-buckets.constants.js +51 -0
- package/build/common/constants/histogram-buckets.constants.js.map +1 -0
- package/build/common/constants/http-status.constants.d.ts +27 -0
- package/build/common/constants/http-status.constants.d.ts.map +1 -0
- package/build/common/constants/http-status.constants.js +27 -0
- package/build/common/constants/http-status.constants.js.map +1 -0
- package/build/common/constants/timeout.constants.d.ts +29 -0
- package/build/common/constants/timeout.constants.d.ts.map +1 -0
- package/build/common/constants/timeout.constants.js +45 -0
- package/build/common/constants/timeout.constants.js.map +1 -0
- package/build/common/controllers/metrics.controller.d.ts +23 -0
- package/build/common/controllers/metrics.controller.d.ts.map +1 -0
- package/build/common/controllers/metrics.controller.js +66 -0
- package/build/common/controllers/metrics.controller.js.map +1 -0
- package/build/common/decorators/common-decorators.d.ts +90 -0
- package/build/common/decorators/common-decorators.d.ts.map +1 -0
- package/build/common/decorators/common-decorators.js +101 -0
- package/build/common/decorators/common-decorators.js.map +1 -0
- package/build/common/decorators/decorator-factory.d.ts +108 -0
- package/build/common/decorators/decorator-factory.d.ts.map +1 -0
- package/build/common/decorators/decorator-factory.js +104 -0
- package/build/common/decorators/decorator-factory.js.map +1 -0
- package/build/common/decorators/guard.decorators.d.ts +48 -0
- package/build/common/decorators/guard.decorators.d.ts.map +1 -0
- package/build/common/decorators/guard.decorators.js +49 -0
- package/build/common/decorators/guard.decorators.js.map +1 -0
- package/build/common/decorators/index.d.ts +10 -0
- package/build/common/decorators/index.d.ts.map +1 -0
- package/build/common/decorators/index.js +11 -0
- package/build/common/decorators/index.js.map +1 -0
- package/build/common/decorators/instrument.decorator.d.ts +128 -0
- package/build/common/decorators/instrument.decorator.d.ts.map +1 -0
- package/build/common/decorators/instrument.decorator.js +165 -0
- package/build/common/decorators/instrument.decorator.js.map +1 -0
- package/build/common/decorators/metric.decorators.d.ts +42 -0
- package/build/common/decorators/metric.decorators.d.ts.map +1 -0
- package/build/common/decorators/metric.decorators.js +85 -0
- package/build/common/decorators/metric.decorators.js.map +1 -0
- package/build/common/decorators/request-property.decorator.d.ts +65 -0
- package/build/common/decorators/request-property.decorator.d.ts.map +1 -0
- package/build/common/decorators/request-property.decorator.js +102 -0
- package/build/common/decorators/request-property.decorator.js.map +1 -0
- package/build/common/errors/base-application-error.d.ts +98 -0
- package/build/common/errors/base-application-error.d.ts.map +1 -0
- package/build/common/errors/base-application-error.js +133 -0
- package/build/common/errors/base-application-error.js.map +1 -0
- package/build/common/errors/error-factory.d.ts +93 -0
- package/build/common/errors/error-factory.d.ts.map +1 -0
- package/build/common/errors/error-factory.js +105 -0
- package/build/common/errors/error-factory.js.map +1 -0
- package/build/common/errors/index.d.ts +13 -0
- package/build/common/errors/index.d.ts.map +1 -0
- package/build/common/errors/index.js +15 -0
- package/build/common/errors/index.js.map +1 -0
- package/build/common/factories/index.d.ts +5 -0
- package/build/common/factories/index.d.ts.map +1 -0
- package/build/common/factories/index.js +3 -0
- package/build/common/factories/index.js.map +1 -0
- package/build/common/factories/module-factory.d.ts +178 -0
- package/build/common/factories/module-factory.d.ts.map +1 -0
- package/build/common/factories/module-factory.js +253 -0
- package/build/common/factories/module-factory.js.map +1 -0
- package/build/common/factories/rate-limit-config.factory.d.ts +79 -0
- package/build/common/factories/rate-limit-config.factory.d.ts.map +1 -0
- package/build/common/factories/rate-limit-config.factory.js +115 -0
- package/build/common/factories/rate-limit-config.factory.js.map +1 -0
- package/build/common/factories/security-bootstrap.factory.d.ts +77 -0
- package/build/common/factories/security-bootstrap.factory.d.ts.map +1 -0
- package/build/common/factories/security-bootstrap.factory.js +222 -0
- package/build/common/factories/security-bootstrap.factory.js.map +1 -0
- package/build/common/filters/global-exception.filter.d.ts +78 -0
- package/build/common/filters/global-exception.filter.d.ts.map +1 -0
- package/build/common/filters/global-exception.filter.js +192 -0
- package/build/common/filters/global-exception.filter.js.map +1 -0
- package/build/common/filters/http-exception.filter.d.ts +37 -0
- package/build/common/filters/http-exception.filter.d.ts.map +1 -0
- package/build/common/filters/http-exception.filter.js +91 -0
- package/build/common/filters/http-exception.filter.js.map +1 -0
- package/build/common/guards/csrf.guard.d.ts +53 -0
- package/build/common/guards/csrf.guard.d.ts.map +1 -0
- package/build/common/guards/csrf.guard.js +109 -0
- package/build/common/guards/csrf.guard.js.map +1 -0
- package/build/common/guards/metrics.guard.d.ts +42 -0
- package/build/common/guards/metrics.guard.d.ts.map +1 -0
- package/build/common/guards/metrics.guard.js +124 -0
- package/build/common/guards/metrics.guard.js.map +1 -0
- package/build/common/index.d.ts +43 -0
- package/build/common/index.d.ts.map +1 -0
- package/build/common/index.js +50 -0
- package/build/common/index.js.map +1 -0
- package/build/common/interceptors/http-client.interceptor.d.ts +11 -0
- package/build/common/interceptors/http-client.interceptor.d.ts.map +1 -0
- package/build/common/interceptors/http-client.interceptor.js +69 -0
- package/build/common/interceptors/http-client.interceptor.js.map +1 -0
- package/build/common/interceptors/http-instrumentation.interceptor.d.ts +64 -0
- package/build/common/interceptors/http-instrumentation.interceptor.d.ts.map +1 -0
- package/build/common/interceptors/http-instrumentation.interceptor.js +148 -0
- package/build/common/interceptors/http-instrumentation.interceptor.js.map +1 -0
- package/build/common/interceptors/http-metrics.interceptor.d.ts +46 -0
- package/build/common/interceptors/http-metrics.interceptor.d.ts.map +1 -0
- package/build/common/interceptors/http-metrics.interceptor.js +120 -0
- package/build/common/interceptors/http-metrics.interceptor.js.map +1 -0
- package/build/common/interceptors/logging.interceptor.d.ts +22 -0
- package/build/common/interceptors/logging.interceptor.d.ts.map +1 -0
- package/build/common/interceptors/logging.interceptor.js +67 -0
- package/build/common/interceptors/logging.interceptor.js.map +1 -0
- package/build/common/interfaces/cache-provider.interface.d.ts +54 -0
- package/build/common/interfaces/cache-provider.interface.d.ts.map +1 -0
- package/build/common/interfaces/cache-provider.interface.js +6 -0
- package/build/common/interfaces/cache-provider.interface.js.map +1 -0
- package/build/common/interfaces/index.d.ts +7 -0
- package/build/common/interfaces/index.d.ts.map +1 -0
- package/build/common/interfaces/index.js +3 -0
- package/build/common/interfaces/index.js.map +1 -0
- package/build/common/interfaces/log-context.interface.d.ts +77 -0
- package/build/common/interfaces/log-context.interface.d.ts.map +1 -0
- package/build/common/interfaces/log-context.interface.js +2 -0
- package/build/common/interfaces/log-context.interface.js.map +1 -0
- package/build/common/interfaces/log-entry.interface.d.ts +26 -0
- package/build/common/interfaces/log-entry.interface.d.ts.map +1 -0
- package/build/common/interfaces/log-entry.interface.js +33 -0
- package/build/common/interfaces/log-entry.interface.js.map +1 -0
- package/build/common/interfaces/logger.interface.d.ts +62 -0
- package/build/common/interfaces/logger.interface.d.ts.map +1 -0
- package/build/common/interfaces/logger.interface.js +2 -0
- package/build/common/interfaces/logger.interface.js.map +1 -0
- package/build/common/interfaces/metrics-exporter.interface.d.ts +275 -0
- package/build/common/interfaces/metrics-exporter.interface.d.ts.map +1 -0
- package/build/common/interfaces/metrics-exporter.interface.js +8 -0
- package/build/common/interfaces/metrics-exporter.interface.js.map +1 -0
- package/build/common/metrics/base-metrics-collector.d.ts +81 -0
- package/build/common/metrics/base-metrics-collector.d.ts.map +1 -0
- package/build/common/metrics/base-metrics-collector.js +88 -0
- package/build/common/metrics/base-metrics-collector.js.map +1 -0
- package/build/common/metrics/index.d.ts +2 -0
- package/build/common/metrics/index.d.ts.map +1 -0
- package/build/common/metrics/index.js +2 -0
- package/build/common/metrics/index.js.map +1 -0
- package/build/common/metrics.module.d.ts +50 -0
- package/build/common/metrics.module.d.ts.map +1 -0
- package/build/common/metrics.module.js +77 -0
- package/build/common/metrics.module.js.map +1 -0
- package/build/common/modules/throttler.module.d.ts +69 -0
- package/build/common/modules/throttler.module.d.ts.map +1 -0
- package/build/common/modules/throttler.module.js +117 -0
- package/build/common/modules/throttler.module.js.map +1 -0
- package/build/common/pipes/base-validation.pipe.d.ts +67 -0
- package/build/common/pipes/base-validation.pipe.d.ts.map +1 -0
- package/build/common/pipes/base-validation.pipe.js +95 -0
- package/build/common/pipes/base-validation.pipe.js.map +1 -0
- package/build/common/pipes/validation.pipe.d.ts +32 -0
- package/build/common/pipes/validation.pipe.d.ts.map +1 -0
- package/build/common/pipes/validation.pipe.js +60 -0
- package/build/common/pipes/validation.pipe.js.map +1 -0
- package/build/common/registry/instrumentation-registry.d.ts +227 -0
- package/build/common/registry/instrumentation-registry.d.ts.map +1 -0
- package/build/common/registry/instrumentation-registry.js +414 -0
- package/build/common/registry/instrumentation-registry.js.map +1 -0
- package/build/common/services/audit-logger.service.d.ts +91 -0
- package/build/common/services/audit-logger.service.d.ts.map +1 -0
- package/build/common/services/audit-logger.service.js +180 -0
- package/build/common/services/audit-logger.service.js.map +1 -0
- package/build/common/services/csrf.service.d.ts +202 -0
- package/build/common/services/csrf.service.d.ts.map +1 -0
- package/build/common/services/csrf.service.js +478 -0
- package/build/common/services/csrf.service.js.map +1 -0
- package/build/common/services/error-categorizer.service.d.ts +82 -0
- package/build/common/services/error-categorizer.service.d.ts.map +1 -0
- package/build/common/services/error-categorizer.service.js +339 -0
- package/build/common/services/error-categorizer.service.js.map +1 -0
- package/build/common/services/error-sanitizer.service.d.ts +146 -0
- package/build/common/services/error-sanitizer.service.d.ts.map +1 -0
- package/build/common/services/error-sanitizer.service.js +287 -0
- package/build/common/services/error-sanitizer.service.js.map +1 -0
- package/build/common/services/health-check.service.d.ts +86 -0
- package/build/common/services/health-check.service.d.ts.map +1 -0
- package/build/common/services/health-check.service.js +132 -0
- package/build/common/services/health-check.service.js.map +1 -0
- package/build/common/services/http-client.service.d.ts +113 -0
- package/build/common/services/http-client.service.d.ts.map +1 -0
- package/build/common/services/http-client.service.js +294 -0
- package/build/common/services/http-client.service.js.map +1 -0
- package/build/common/services/logger.service.d.ts +189 -0
- package/build/common/services/logger.service.d.ts.map +1 -0
- package/build/common/services/logger.service.js +423 -0
- package/build/common/services/logger.service.js.map +1 -0
- package/build/common/services/metrics-registry.service.d.ts +98 -0
- package/build/common/services/metrics-registry.service.d.ts.map +1 -0
- package/build/common/services/metrics-registry.service.js +262 -0
- package/build/common/services/metrics-registry.service.js.map +1 -0
- package/build/common/services/nest-logger-adapter.service.d.ts +62 -0
- package/build/common/services/nest-logger-adapter.service.d.ts.map +1 -0
- package/build/common/services/nest-logger-adapter.service.js +120 -0
- package/build/common/services/nest-logger-adapter.service.js.map +1 -0
- package/build/common/utils/error.utils.d.ts +16 -0
- package/build/common/utils/error.utils.d.ts.map +1 -0
- package/build/common/utils/error.utils.js +26 -0
- package/build/common/utils/error.utils.js.map +1 -0
- package/build/common/utils/lazy-getter.types.d.ts +190 -0
- package/build/common/utils/lazy-getter.types.d.ts.map +1 -0
- package/build/common/utils/lazy-getter.types.js +114 -0
- package/build/common/utils/lazy-getter.types.js.map +1 -0
- package/build/common/utils/module.utils.d.ts +33 -0
- package/build/common/utils/module.utils.d.ts.map +1 -0
- package/build/common/utils/module.utils.js +48 -0
- package/build/common/utils/module.utils.js.map +1 -0
- package/build/common/utils/sanitization.utils.d.ts +69 -0
- package/build/common/utils/sanitization.utils.d.ts.map +1 -0
- package/build/common/utils/sanitization.utils.js +141 -0
- package/build/common/utils/sanitization.utils.js.map +1 -0
- package/build/config/config.module.d.ts +30 -0
- package/build/config/config.module.d.ts.map +1 -0
- package/build/config/config.module.js +49 -0
- package/build/config/config.module.js.map +1 -0
- package/build/config/config.service.d.ts +74 -0
- package/build/config/config.service.d.ts.map +1 -0
- package/build/config/config.service.js +145 -0
- package/build/config/config.service.js.map +1 -0
- package/build/config/config.types.d.ts +143 -0
- package/build/config/config.types.d.ts.map +1 -0
- package/build/config/config.types.js +2 -0
- package/build/config/config.types.js.map +1 -0
- package/build/config/decorators/config.decorators.d.ts +43 -0
- package/build/config/decorators/config.decorators.d.ts.map +1 -0
- package/build/config/decorators/config.decorators.js +68 -0
- package/build/config/decorators/config.decorators.js.map +1 -0
- package/build/config/decorators/index.d.ts +2 -0
- package/build/config/decorators/index.d.ts.map +1 -0
- package/build/config/decorators/index.js +2 -0
- package/build/config/decorators/index.js.map +1 -0
- package/build/config/index.d.ts +7 -0
- package/build/config/index.d.ts.map +1 -0
- package/build/config/index.js +9 -0
- package/build/config/index.js.map +1 -0
- package/build/config/validation.utils.d.ts +136 -0
- package/build/config/validation.utils.d.ts.map +1 -0
- package/build/config/validation.utils.js +263 -0
- package/build/config/validation.utils.js.map +1 -0
- package/build/errors/index.d.ts +9 -0
- package/build/errors/index.d.ts.map +1 -0
- package/build/errors/index.js +12 -0
- package/build/errors/index.js.map +1 -0
- package/build/guards/custom-throttle.guard.d.ts +28 -0
- package/build/guards/custom-throttle.guard.d.ts.map +1 -0
- package/build/guards/custom-throttle.guard.js +52 -0
- package/build/guards/custom-throttle.guard.js.map +1 -0
- package/build/guards/index.d.ts +2 -0
- package/build/guards/index.d.ts.map +1 -0
- package/build/guards/index.js +2 -0
- package/build/guards/index.js.map +1 -0
- package/build/index.d.ts +53 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +61 -0
- package/build/index.js.map +1 -0
- package/build/logging/index.d.ts +7 -0
- package/build/logging/index.d.ts.map +1 -0
- package/build/logging/index.js +7 -0
- package/build/logging/index.js.map +1 -0
- package/build/metrics/index.d.ts +6 -0
- package/build/metrics/index.d.ts.map +1 -0
- package/build/metrics/index.js +11 -0
- package/build/metrics/index.js.map +1 -0
- package/build/package.json +72 -0
- package/build/security/index.d.ts +8 -0
- package/build/security/index.d.ts.map +1 -0
- package/build/security/index.js +11 -0
- package/build/security/index.js.map +1 -0
- package/build/test-setup.d.ts +2 -0
- package/build/test-setup.d.ts.map +1 -0
- package/build/test-setup.js +40 -0
- package/build/test-setup.js.map +1 -0
- package/build/validation/index.d.ts +6 -0
- package/build/validation/index.d.ts.map +1 -0
- package/build/validation/index.js +8 -0
- package/build/validation/index.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const DEBUG_LEVEL = 0;
|
|
2
|
+
const INFO_LEVEL = 1;
|
|
3
|
+
const WARN_LEVEL = 2;
|
|
4
|
+
const ERROR_LEVEL = 3;
|
|
5
|
+
const FATAL_LEVEL = 4;
|
|
6
|
+
const SILENT_LEVEL = 5;
|
|
7
|
+
export var LogLevel;
|
|
8
|
+
(function (LogLevel) {
|
|
9
|
+
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
10
|
+
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
11
|
+
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
12
|
+
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
13
|
+
LogLevel[LogLevel["FATAL"] = 4] = "FATAL";
|
|
14
|
+
/** Suppresses all log output. */
|
|
15
|
+
LogLevel[LogLevel["SILENT"] = 5] = "SILENT";
|
|
16
|
+
})(LogLevel || (LogLevel = {}));
|
|
17
|
+
export const LOG_LEVEL_STRINGS = {
|
|
18
|
+
[LogLevel.DEBUG]: 'debug',
|
|
19
|
+
[LogLevel.INFO]: 'info',
|
|
20
|
+
[LogLevel.WARN]: 'warn',
|
|
21
|
+
[LogLevel.ERROR]: 'error',
|
|
22
|
+
[LogLevel.FATAL]: 'fatal',
|
|
23
|
+
[LogLevel.SILENT]: 'silent',
|
|
24
|
+
};
|
|
25
|
+
export const LOG_LEVEL_FROM_STRING = {
|
|
26
|
+
debug: LogLevel.DEBUG,
|
|
27
|
+
info: LogLevel.INFO,
|
|
28
|
+
warn: LogLevel.WARN,
|
|
29
|
+
error: LogLevel.ERROR,
|
|
30
|
+
fatal: LogLevel.FATAL,
|
|
31
|
+
silent: LogLevel.SILENT,
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=log-entry.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-entry.interface.js","sourceRoot":"","sources":["../../../src/common/interfaces/log-entry.interface.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,MAAM,CAAN,IAAY,QAQX;AARD,WAAY,QAAQ;IACnB,yCAAmB,CAAA;IACnB,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;IACjB,yCAAmB,CAAA;IACnB,yCAAmB,CAAA;IACnB,iCAAiC;IACjC,2CAAqB,CAAA;AACtB,CAAC,EARW,QAAQ,KAAR,QAAQ,QAQnB;AAED,MAAM,CAAC,MAAM,iBAAiB,GAA6B;IAC1D,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACvB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACvB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ;CAC3B,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAA6B;IAC9D,KAAK,EAAE,QAAQ,CAAC,KAAK;IACrB,IAAI,EAAE,QAAQ,CAAC,IAAI;IACnB,IAAI,EAAE,QAAQ,CAAC,IAAI;IACnB,KAAK,EAAE,QAAQ,CAAC,KAAK;IACrB,KAAK,EAAE,QAAQ,CAAC,KAAK;IACrB,MAAM,EAAE,QAAQ,CAAC,MAAM;CACvB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LogMetadata } from './log-entry.interface.js';
|
|
2
|
+
/**
|
|
3
|
+
* Basic logging interface following Interface Segregation Principle
|
|
4
|
+
* Provides essential logging methods without contextual logger creation
|
|
5
|
+
*/
|
|
6
|
+
export interface ILogger {
|
|
7
|
+
/**
|
|
8
|
+
* Log debug message
|
|
9
|
+
* @param message - Log message
|
|
10
|
+
* @param context - Optional context override
|
|
11
|
+
* @param metadata - Optional structured metadata
|
|
12
|
+
*/
|
|
13
|
+
debug(message: string | Error, context?: string, metadata?: LogMetadata): void;
|
|
14
|
+
debug(message: string | Error, metadata?: LogMetadata): void;
|
|
15
|
+
/**
|
|
16
|
+
* Log info message
|
|
17
|
+
* @param message - Log message
|
|
18
|
+
* @param context - Optional context override
|
|
19
|
+
* @param metadata - Optional structured metadata
|
|
20
|
+
*/
|
|
21
|
+
info(message: string | Error, context?: string, metadata?: LogMetadata): void;
|
|
22
|
+
info(message: string | Error, metadata?: LogMetadata): void;
|
|
23
|
+
/**
|
|
24
|
+
* Log warning message
|
|
25
|
+
* @param message - Log message
|
|
26
|
+
* @param context - Optional context override
|
|
27
|
+
* @param metadata - Optional structured metadata
|
|
28
|
+
*/
|
|
29
|
+
warn(message: string | Error, context?: string, metadata?: LogMetadata): void;
|
|
30
|
+
warn(message: string | Error, metadata?: LogMetadata): void;
|
|
31
|
+
/**
|
|
32
|
+
* Log error message
|
|
33
|
+
* @param message - Log message or Error object
|
|
34
|
+
* @param trace - Optional stack trace
|
|
35
|
+
* @param context - Optional context override
|
|
36
|
+
* @param metadata - Optional structured metadata
|
|
37
|
+
*/
|
|
38
|
+
error(message: string | Error, trace?: string, context?: string, metadata?: LogMetadata): void;
|
|
39
|
+
error(message: string | Error, context?: string, metadata?: LogMetadata): void;
|
|
40
|
+
/**
|
|
41
|
+
* Log fatal message
|
|
42
|
+
* @param message - Log message or Error object
|
|
43
|
+
* @param trace - Optional stack trace
|
|
44
|
+
* @param context - Optional context override
|
|
45
|
+
* @param metadata - Optional structured metadata
|
|
46
|
+
*/
|
|
47
|
+
fatal(message: string | Error, trace?: string, context?: string, metadata?: LogMetadata): void;
|
|
48
|
+
fatal(message: string | Error, context?: string, metadata?: LogMetadata): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Contextual logging interface extending basic logging
|
|
52
|
+
* Adds capability to create contextual logger instances
|
|
53
|
+
*/
|
|
54
|
+
export interface IContextualLogger extends ILogger {
|
|
55
|
+
/**
|
|
56
|
+
* Create a contextual logger instance
|
|
57
|
+
* @param context - Context string
|
|
58
|
+
* @returns New logger instance with context
|
|
59
|
+
*/
|
|
60
|
+
createContextualLogger(context: string): IContextualLogger;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=logger.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.interface.d.ts","sourceRoot":"","sources":["../../../src/common/interfaces/logger.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,OAAO;IACvB;;;;;OAKG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAC/E,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE7D;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAC9E,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE5D;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAC9E,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE5D;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAC/F,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE/E;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAC/F,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CAC/E;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,OAAO;IACjD;;;;OAIG;IACH,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAAC;CAC3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.interface.js","sourceRoot":"","sources":["../../../src/common/interfaces/logger.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metrics exporter interface types for @pawells/nestjs-shared
|
|
3
|
+
*
|
|
4
|
+
* Provides standardized interfaces for exporting metrics to different backends
|
|
5
|
+
* (Prometheus, OpenTelemetry, etc.)
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Supported metric instrument types
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* type CounterType = 'counter'; // Always incrementing
|
|
13
|
+
* type HistogramType = 'histogram'; // Distribution of values
|
|
14
|
+
* type GaugeType = 'gauge'; // Instantaneous value
|
|
15
|
+
* type CounterWithDownType = 'updown_counter'; // Can increment or decrement
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export type MetricType = 'counter' | 'histogram' | 'gauge' | 'updown_counter';
|
|
19
|
+
/**
|
|
20
|
+
* Metric descriptor — registered once per metric, defines the shape of the metric
|
|
21
|
+
*
|
|
22
|
+
* A descriptor uniquely identifies a metric and specifies its properties. Descriptors
|
|
23
|
+
* are typically registered once during application startup and reused for all
|
|
24
|
+
* subsequent metric recordings.
|
|
25
|
+
*
|
|
26
|
+
* @property name - Unique identifier for the metric (e.g., 'http_request_duration_seconds')
|
|
27
|
+
* @property type - The kind of metric instrument
|
|
28
|
+
* @property help - Human-readable description of what the metric measures
|
|
29
|
+
* @property labelNames - Names of labels/tags associated with this metric
|
|
30
|
+
* (e.g., ['method', 'route', 'status_code'])
|
|
31
|
+
* @property buckets - Histogram bucket boundaries (histogram type only).
|
|
32
|
+
* Defaults to exponential buckets if not specified.
|
|
33
|
+
* @property unit - Optional unit of measurement (e.g., 'seconds', 'bytes', 'requests')
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const httpDurationDescriptor: MetricDescriptor = {
|
|
38
|
+
* name: 'http_request_duration_seconds',
|
|
39
|
+
* type: 'histogram',
|
|
40
|
+
* help: 'Duration of HTTP requests in seconds',
|
|
41
|
+
* labelNames: ['method', 'route', 'status_code'],
|
|
42
|
+
* buckets: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
|
|
43
|
+
* unit: 'seconds',
|
|
44
|
+
* };
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export interface MetricDescriptor {
|
|
48
|
+
/**
|
|
49
|
+
* Unique identifier for the metric
|
|
50
|
+
* Convention: snake_case with unit suffix (e.g., 'request_duration_seconds')
|
|
51
|
+
*/
|
|
52
|
+
name: string;
|
|
53
|
+
/**
|
|
54
|
+
* Type of metric instrument
|
|
55
|
+
*/
|
|
56
|
+
type: MetricType;
|
|
57
|
+
/**
|
|
58
|
+
* Human-readable description
|
|
59
|
+
*/
|
|
60
|
+
help: string;
|
|
61
|
+
/**
|
|
62
|
+
* Names of labels/tags for this metric
|
|
63
|
+
* Labels provide dimensions for filtering and aggregating metric values
|
|
64
|
+
*/
|
|
65
|
+
labelNames: string[];
|
|
66
|
+
/**
|
|
67
|
+
* Histogram bucket boundaries
|
|
68
|
+
* Only used for 'histogram' type metrics.
|
|
69
|
+
* Buckets should be in ascending order.
|
|
70
|
+
*/
|
|
71
|
+
buckets?: number[];
|
|
72
|
+
/**
|
|
73
|
+
* Unit of measurement
|
|
74
|
+
* Used by exporters for formatting and can be included in metric names
|
|
75
|
+
*/
|
|
76
|
+
unit?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Metric value — emitted each time a metric is recorded
|
|
80
|
+
*
|
|
81
|
+
* Represents a single data point for a metric at a specific point in time.
|
|
82
|
+
* Each value includes the descriptor, numeric value, labels (tag values),
|
|
83
|
+
* and a timestamp.
|
|
84
|
+
*
|
|
85
|
+
* @property descriptor - The metric descriptor that defines this value's shape
|
|
86
|
+
* @property value - The numeric value of the metric (always a number)
|
|
87
|
+
* @property labels - Label values paired with the metric. Keys must match
|
|
88
|
+
* the descriptor's labelNames. Values are typically strings but can be
|
|
89
|
+
* numbers for performance.
|
|
90
|
+
* @property timestamp - Performance timestamp (milliseconds since start, from performance.now())
|
|
91
|
+
* Used for ordering and time-series analysis.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const httpDurationValue: MetricValue = {
|
|
96
|
+
* descriptor: httpDurationDescriptor,
|
|
97
|
+
* value: 0.125, // seconds
|
|
98
|
+
* labels: {
|
|
99
|
+
* method: 'GET',
|
|
100
|
+
* route: '/api/users',
|
|
101
|
+
* status_code: '200',
|
|
102
|
+
* },
|
|
103
|
+
* timestamp: performance.now(),
|
|
104
|
+
* };
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export interface MetricValue {
|
|
108
|
+
/**
|
|
109
|
+
* Descriptor that defines this metric's structure
|
|
110
|
+
*/
|
|
111
|
+
descriptor: MetricDescriptor;
|
|
112
|
+
/**
|
|
113
|
+
* Numeric value of the metric
|
|
114
|
+
* Range depends on metric type:
|
|
115
|
+
* - counter: >= 0 (always increasing)
|
|
116
|
+
* - gauge: any number
|
|
117
|
+
* - histogram: any number (typically distribution measure)
|
|
118
|
+
* - updown_counter: any number (can increase or decrease)
|
|
119
|
+
*/
|
|
120
|
+
value: number;
|
|
121
|
+
/**
|
|
122
|
+
* Label values paired with the metric
|
|
123
|
+
* Keys correspond to descriptor.labelNames
|
|
124
|
+
* Values are typically strings but can be numbers
|
|
125
|
+
*/
|
|
126
|
+
labels: Record<string, string | number>;
|
|
127
|
+
/**
|
|
128
|
+
* Performance timestamp in milliseconds (from performance.now())
|
|
129
|
+
* Used for ordering, trending, and time-series analysis
|
|
130
|
+
*/
|
|
131
|
+
timestamp: number;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Metrics exporter interface
|
|
135
|
+
*
|
|
136
|
+
* Implemented by exporters that handle metric collection and export to external systems
|
|
137
|
+
* (Prometheus, OpenTelemetry, CloudWatch, etc.).
|
|
138
|
+
*
|
|
139
|
+
* An exporter can support two modes:
|
|
140
|
+
* - **Event-based** (`supportsEventBased`): Receives metrics as they're recorded
|
|
141
|
+
* - **Pull-based** (`supportsPull`): Provides metrics on-demand during scrape/pull requests
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // Prometheus exporter (event-based push + pull-based scrape)
|
|
146
|
+
* class PrometheusExporter implements IMetricsExporter {
|
|
147
|
+
* readonly supportsEventBased = true;
|
|
148
|
+
* readonly supportsPull = true;
|
|
149
|
+
*
|
|
150
|
+
* onMetricRecorded(value: MetricValue) {
|
|
151
|
+
* // Update Prometheus registry
|
|
152
|
+
* this.registry.observe(value);
|
|
153
|
+
* }
|
|
154
|
+
*
|
|
155
|
+
* getMetrics(): string {
|
|
156
|
+
* // Return Prometheus text format
|
|
157
|
+
* return this.registry.metrics();
|
|
158
|
+
* }
|
|
159
|
+
* }
|
|
160
|
+
*
|
|
161
|
+
* // OpenTelemetry exporter (event-based only)
|
|
162
|
+
* class OTelExporter implements IMetricsExporter {
|
|
163
|
+
* readonly supportsEventBased = true;
|
|
164
|
+
* readonly supportsPull = false;
|
|
165
|
+
*
|
|
166
|
+
* onMetricRecorded(value: MetricValue) {
|
|
167
|
+
* // Send to OTEL collector
|
|
168
|
+
* this.client.send(value);
|
|
169
|
+
* }
|
|
170
|
+
* }
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
export interface IMetricsExporter {
|
|
174
|
+
/**
|
|
175
|
+
* Whether this exporter wants to be called synchronously on each metric recording
|
|
176
|
+
*
|
|
177
|
+
* If true, onMetricRecorded() will be called for every metric value recorded.
|
|
178
|
+
* Used for active/eager exporters like Prometheus that maintain in-memory registries.
|
|
179
|
+
*
|
|
180
|
+
* @readonly
|
|
181
|
+
*/
|
|
182
|
+
readonly supportsEventBased: boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Whether this exporter supports pull-based reads (e.g., Prometheus scrape endpoint)
|
|
185
|
+
*
|
|
186
|
+
* If true, getMetrics() can be called to retrieve current metric values on-demand.
|
|
187
|
+
* Used for Prometheus-style scrape endpoints.
|
|
188
|
+
*
|
|
189
|
+
* @readonly
|
|
190
|
+
*/
|
|
191
|
+
readonly supportsPull: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Called when a metric value is recorded
|
|
194
|
+
*
|
|
195
|
+
* Only called if supportsEventBased = true.
|
|
196
|
+
* Implementations should process the metric quickly to avoid blocking the request.
|
|
197
|
+
* If processing needs to be async, implementations should queue work and return immediately.
|
|
198
|
+
*
|
|
199
|
+
* @param value - The metric value being recorded
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* onMetricRecorded(value: MetricValue): void {
|
|
204
|
+
* // Update in-memory registry
|
|
205
|
+
* const key = this.buildKey(value);
|
|
206
|
+
* this.registry.update(key, value);
|
|
207
|
+
*
|
|
208
|
+
* // If async work needed, queue it
|
|
209
|
+
* this.queue.push(value);
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
onMetricRecorded?(value: MetricValue): void;
|
|
214
|
+
/**
|
|
215
|
+
* Called when a new metric descriptor is registered
|
|
216
|
+
*
|
|
217
|
+
* Exporters can use this hook to pre-create instruments or validate that
|
|
218
|
+
* they support the metric type. Implementations should be fast.
|
|
219
|
+
*
|
|
220
|
+
* @param descriptor - The metric descriptor being registered
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* onDescriptorRegistered(descriptor: MetricDescriptor): void {
|
|
225
|
+
* // Pre-create Prometheus gauge/counter/histogram
|
|
226
|
+
* this.registry.register(descriptor);
|
|
227
|
+
* }
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
onDescriptorRegistered?(descriptor: MetricDescriptor): void;
|
|
231
|
+
/**
|
|
232
|
+
* Retrieve all current metric values (pull-based)
|
|
233
|
+
*
|
|
234
|
+
* Only required if supportsPull = true.
|
|
235
|
+
* Called by scrape endpoints or pull-based collectors to fetch metrics.
|
|
236
|
+
* Should return metrics in the format expected by the external system
|
|
237
|
+
* (e.g., Prometheus text format, JSON, etc.).
|
|
238
|
+
*
|
|
239
|
+
* @returns Current metrics in the exporter's format (string, or Promise<string>)
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* // Prometheus exporter
|
|
244
|
+
* getMetrics(): string {
|
|
245
|
+
* return this.registry.metrics(); // Returns Prometheus text format
|
|
246
|
+
* }
|
|
247
|
+
*
|
|
248
|
+
* // Async exporter
|
|
249
|
+
* getMetrics(): Promise<string> {
|
|
250
|
+
* return this.client.fetchMetrics(); // Fetch from remote backend
|
|
251
|
+
* }
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
getMetrics?(): Promise<string> | string;
|
|
255
|
+
/**
|
|
256
|
+
* Called on application shutdown
|
|
257
|
+
*
|
|
258
|
+
* Exporters should use this hook to flush buffered metrics, close connections,
|
|
259
|
+
* and clean up resources.
|
|
260
|
+
*
|
|
261
|
+
* @returns Optional promise (for async cleanup)
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* shutdown(): Promise<void> {
|
|
266
|
+
* return Promise.all([
|
|
267
|
+
* this.client.flush(),
|
|
268
|
+
* this.client.close(),
|
|
269
|
+
* ]);
|
|
270
|
+
* }
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
shutdown?(): Promise<void> | void;
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=metrics-exporter.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics-exporter.interface.d.ts","sourceRoot":"","sources":["../../../src/common/interfaces/metrics-exporter.interface.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,OAAO,GAAG,gBAAgB,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,UAAU,CAAC;IAEjB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,UAAU,EAAE,MAAM,EAAE,CAAC;IAErB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,WAAW;IAC3B;;OAEG;IACH,UAAU,EAAE,gBAAgB,CAAC;IAE7B;;;;;;;OAOG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAExC;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;;;OAOG;IACH,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;IAErC;;;;;;;OAOG;IACH,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAE/B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,gBAAgB,CAAC,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAE5C;;;;;;;;;;;;;;;OAeG;IACH,sBAAsB,CAAC,CAAC,UAAU,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAE5D;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,UAAU,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IAExC;;;;;;;;;;;;;;;;;OAiBG;IACH,QAAQ,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics-exporter.interface.js","sourceRoot":"","sources":["../../../src/common/interfaces/metrics-exporter.interface.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
|
+
import { Counter, Gauge, Histogram } from 'prom-client';
|
|
3
|
+
import { MetricsRegistryService } from '../services/metrics-registry.service.js';
|
|
4
|
+
/**
|
|
5
|
+
* BaseMetricsCollector
|
|
6
|
+
*
|
|
7
|
+
* Abstract base class for domain-specific metrics collection. Services can extend this class
|
|
8
|
+
* to define custom Prometheus metrics that are registered with the centralized MetricsRegistryService.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* class StreamMetricsCollector extends BaseMetricsCollector {
|
|
13
|
+
* protected initializeMetrics(): void {
|
|
14
|
+
* this.registerCounter('stream_created', 'Total streams created', ['region']);
|
|
15
|
+
* this.registerGauge('active_streams', 'Currently active streams', ['region']);
|
|
16
|
+
* this.registerHistogram('stream_duration', 'Stream duration in seconds', ['region']);
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* const collector = new StreamMetricsCollector(metricsRegistry);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class BaseMetricsCollector {
|
|
24
|
+
protected readonly logger: Logger;
|
|
25
|
+
private readonly metricsRegistry;
|
|
26
|
+
private readonly metrics;
|
|
27
|
+
constructor(metricsRegistry: MetricsRegistryService);
|
|
28
|
+
/**
|
|
29
|
+
* Initialize metrics for this collector.
|
|
30
|
+
* Subclasses must implement this method to register their custom metrics.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* protected initializeMetrics(): void {
|
|
34
|
+
* this.registerCounter('events_processed', 'Total events processed');
|
|
35
|
+
* this.registerGauge('queue_depth', 'Current queue depth');
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
protected abstract initializeMetrics(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Register a counter metric.
|
|
41
|
+
*
|
|
42
|
+
* @param name - The metric name (e.g., 'requests_total')
|
|
43
|
+
* @param help - Help text describing the metric
|
|
44
|
+
* @param labelNames - Optional label names for the metric
|
|
45
|
+
* @returns The registered counter metric
|
|
46
|
+
*/
|
|
47
|
+
protected registerCounter(name: string, help: string, labelNames?: string[]): Counter<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Register a gauge metric.
|
|
50
|
+
*
|
|
51
|
+
* @param name - The metric name (e.g., 'queue_size')
|
|
52
|
+
* @param help - Help text describing the metric
|
|
53
|
+
* @param labelNames - Optional label names for the metric
|
|
54
|
+
* @returns The registered gauge metric
|
|
55
|
+
*/
|
|
56
|
+
protected registerGauge(name: string, help: string, labelNames?: string[]): Gauge<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Register a histogram metric.
|
|
59
|
+
*
|
|
60
|
+
* @param name - The metric name (e.g., 'request_duration')
|
|
61
|
+
* @param help - Help text describing the metric
|
|
62
|
+
* @param labelNames - Optional label names for the metric
|
|
63
|
+
* @param buckets - Optional bucket boundaries for the histogram
|
|
64
|
+
* @returns The registered histogram metric
|
|
65
|
+
*/
|
|
66
|
+
protected registerHistogram(name: string, help: string, labelNames?: string[], buckets?: number[]): Histogram<string>;
|
|
67
|
+
/**
|
|
68
|
+
* Get a registered metric by name.
|
|
69
|
+
*
|
|
70
|
+
* @param name - The metric name
|
|
71
|
+
* @returns The metric instance, or undefined if not found
|
|
72
|
+
*/
|
|
73
|
+
getMetric(name: string): Counter<string> | Gauge<string> | Histogram<string> | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Get all registered metrics.
|
|
76
|
+
*
|
|
77
|
+
* @returns A Map of all registered metrics keyed by name
|
|
78
|
+
*/
|
|
79
|
+
getAllMetrics(): Map<string, Counter<string> | Gauge<string> | Histogram<string>>;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=base-metrics-collector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-metrics-collector.d.ts","sourceRoot":"","sources":["../../../src/common/metrics/base-metrics-collector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AAEjF;;;;;;;;;;;;;;;;;;GAkBG;AACH,8BAAsB,oBAAoB;IACzC,SAAS,CAAC,QAAQ,CAAC,MAAM,SAAqC;IAE9D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAyB;IAEzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+E;gBAE3F,eAAe,EAAE,sBAAsB;IAMnD;;;;;;;;;OASG;IACH,SAAS,CAAC,QAAQ,CAAC,iBAAiB,IAAI,IAAI;IAE5C;;;;;;;OAOG;IACH,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,EAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAMjG;;;;;;;OAOG;IACH,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,EAAO,GAAG,KAAK,CAAC,MAAM,CAAC;IAM7F;;;;;;;;OAQG;IACH,SAAS,CAAC,iBAAiB,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,UAAU,GAAE,MAAM,EAAO,EACzB,OAAO,CAAC,EAAE,MAAM,EAAE,GAChB,SAAS,CAAC,MAAM,CAAC;IAMpB;;;;;OAKG;IACI,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,SAAS;IAI/F;;;;OAIG;IACI,aAAa,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;CAGxF"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* BaseMetricsCollector
|
|
4
|
+
*
|
|
5
|
+
* Abstract base class for domain-specific metrics collection. Services can extend this class
|
|
6
|
+
* to define custom Prometheus metrics that are registered with the centralized MetricsRegistryService.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* class StreamMetricsCollector extends BaseMetricsCollector {
|
|
11
|
+
* protected initializeMetrics(): void {
|
|
12
|
+
* this.registerCounter('stream_created', 'Total streams created', ['region']);
|
|
13
|
+
* this.registerGauge('active_streams', 'Currently active streams', ['region']);
|
|
14
|
+
* this.registerHistogram('stream_duration', 'Stream duration in seconds', ['region']);
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* const collector = new StreamMetricsCollector(metricsRegistry);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class BaseMetricsCollector {
|
|
22
|
+
logger = new Logger(this.constructor.name);
|
|
23
|
+
metricsRegistry;
|
|
24
|
+
metrics = new Map();
|
|
25
|
+
constructor(metricsRegistry) {
|
|
26
|
+
this.metricsRegistry = metricsRegistry;
|
|
27
|
+
this.initializeMetrics();
|
|
28
|
+
this.logger.log(`${this.constructor.name} initialized with ${this.metrics.size} metrics`);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Register a counter metric.
|
|
32
|
+
*
|
|
33
|
+
* @param name - The metric name (e.g., 'requests_total')
|
|
34
|
+
* @param help - Help text describing the metric
|
|
35
|
+
* @param labelNames - Optional label names for the metric
|
|
36
|
+
* @returns The registered counter metric
|
|
37
|
+
*/
|
|
38
|
+
registerCounter(name, help, labelNames = []) {
|
|
39
|
+
const counter = this.metricsRegistry.createCounter(name, help, labelNames);
|
|
40
|
+
this.metrics.set(name, counter);
|
|
41
|
+
return counter;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Register a gauge metric.
|
|
45
|
+
*
|
|
46
|
+
* @param name - The metric name (e.g., 'queue_size')
|
|
47
|
+
* @param help - Help text describing the metric
|
|
48
|
+
* @param labelNames - Optional label names for the metric
|
|
49
|
+
* @returns The registered gauge metric
|
|
50
|
+
*/
|
|
51
|
+
registerGauge(name, help, labelNames = []) {
|
|
52
|
+
const gauge = this.metricsRegistry.createGauge(name, help, labelNames);
|
|
53
|
+
this.metrics.set(name, gauge);
|
|
54
|
+
return gauge;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Register a histogram metric.
|
|
58
|
+
*
|
|
59
|
+
* @param name - The metric name (e.g., 'request_duration')
|
|
60
|
+
* @param help - Help text describing the metric
|
|
61
|
+
* @param labelNames - Optional label names for the metric
|
|
62
|
+
* @param buckets - Optional bucket boundaries for the histogram
|
|
63
|
+
* @returns The registered histogram metric
|
|
64
|
+
*/
|
|
65
|
+
registerHistogram(name, help, labelNames = [], buckets) {
|
|
66
|
+
const histogram = this.metricsRegistry.createHistogram(name, help, labelNames, buckets);
|
|
67
|
+
this.metrics.set(name, histogram);
|
|
68
|
+
return histogram;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get a registered metric by name.
|
|
72
|
+
*
|
|
73
|
+
* @param name - The metric name
|
|
74
|
+
* @returns The metric instance, or undefined if not found
|
|
75
|
+
*/
|
|
76
|
+
getMetric(name) {
|
|
77
|
+
return this.metrics.get(name);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get all registered metrics.
|
|
81
|
+
*
|
|
82
|
+
* @returns A Map of all registered metrics keyed by name
|
|
83
|
+
*/
|
|
84
|
+
getAllMetrics() {
|
|
85
|
+
return new Map(this.metrics);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=base-metrics-collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-metrics-collector.js","sourceRoot":"","sources":["../../../src/common/metrics/base-metrics-collector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAgB,oBAAoB;IACtB,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAE7C,eAAe,CAAyB;IAExC,OAAO,GAAqE,IAAI,GAAG,EAAE,CAAC;IAEvG,YAAY,eAAuC;QAClD,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,qBAAqB,IAAI,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,CAAC;IAC3F,CAAC;IAcD;;;;;;;OAOG;IACO,eAAe,CAAC,IAAY,EAAE,IAAY,EAAE,aAAuB,EAAE;QAC9E,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;QAC3E,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAChC,OAAO,OAAO,CAAC;IAChB,CAAC;IAED;;;;;;;OAOG;IACO,aAAa,CAAC,IAAY,EAAE,IAAY,EAAE,aAAuB,EAAE;QAC5E,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;QACvE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC9B,OAAO,KAAK,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACO,iBAAiB,CAC1B,IAAY,EACZ,IAAY,EACZ,aAAuB,EAAE,EACzB,OAAkB;QAElB,MAAM,SAAS,GAAG,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;QACxF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAClC,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,IAAY;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;;;OAIG;IACI,aAAa;QACnB,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/metrics/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/metrics/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { ModuleMetadata } from '@nestjs/common/interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Async options for MetricsModule.
|
|
5
|
+
* Configuration options for asynchronous MetricsModule initialization.
|
|
6
|
+
*/
|
|
7
|
+
export interface MetricsModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Metrics Module.
|
|
11
|
+
* Provides comprehensive Prometheus metrics collection and exposure for NestJS applications.
|
|
12
|
+
*
|
|
13
|
+
* Features:
|
|
14
|
+
* - HTTP request metrics (duration, count, size) with automatic cardinality prevention
|
|
15
|
+
* - Custom metric creation (counter, gauge, histogram)
|
|
16
|
+
* - Default Node.js metrics collection
|
|
17
|
+
* - Prometheus endpoint at /metrics
|
|
18
|
+
* - Metrics registry management
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* - Imported as global module in CommonModule
|
|
22
|
+
* - Controlled by METRICS_ENABLED environment variable (default: true)
|
|
23
|
+
* - Automatically normalizes dynamic path segments to prevent unbounded label cardinality
|
|
24
|
+
* - MetricsController exports metrics at GET /metrics in Prometheus format
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* // Access metrics in any injectable
|
|
29
|
+
* constructor(private metrics: MetricsRegistryService) {}
|
|
30
|
+
*
|
|
31
|
+
* // Create and record custom metrics
|
|
32
|
+
* const counter = this.metrics.createCounter('orders_total', 'Total orders');
|
|
33
|
+
* counter.inc({ status: 'completed' });
|
|
34
|
+
*
|
|
35
|
+
* // Get metrics (typically called by MetricsController)
|
|
36
|
+
* const prometheusText = await this.metrics.getMetrics();
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class MetricsModule {
|
|
40
|
+
/**
|
|
41
|
+
* Configure metrics module for root application
|
|
42
|
+
* Enables HTTP metrics collection and /metrics endpoint
|
|
43
|
+
*/
|
|
44
|
+
static forRoot(): DynamicModule;
|
|
45
|
+
/**
|
|
46
|
+
* Configure metrics module with async options
|
|
47
|
+
*/
|
|
48
|
+
static forRootAsync(options: MetricsModuleAsyncOptions): DynamicModule;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=metrics.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.module.d.ts","sourceRoot":"","sources":["../../src/common/metrics.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAK3D;;;GAGG;AACH,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC;CAEjF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,qBAYa,aAAa;IACzB;;;OAGG;WACW,OAAO,IAAI,aAAa;IAMtC;;OAEG;WACW,YAAY,CAAC,OAAO,EAAE,yBAAyB,GAAG,aAAa;CAM7E"}
|