@rsdk/core 4.0.0-next.9 → 4.0.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.
Files changed (136) hide show
  1. package/CHANGELOG.md +130 -40
  2. package/dist/app-metadata/app-name.validator.js.map +1 -1
  3. package/dist/config/additional-source/additional-source.initializer.js.map +1 -1
  4. package/dist/config/config-reload.indicator.js.map +1 -1
  5. package/dist/config/config.abstract.js.map +1 -1
  6. package/dist/config/config.module.js.map +1 -1
  7. package/dist/config/context/config.context.js.map +1 -1
  8. package/dist/config/metadata/config-metadata.registry.js.map +1 -1
  9. package/dist/config/metadata/decorators/config-section.decorator.js.map +1 -1
  10. package/dist/config/parsers/array.parser.js.map +1 -1
  11. package/dist/config/parsers/path/fspath.parser.js.map +1 -1
  12. package/dist/config/parsers/url/url.parser.js.map +1 -1
  13. package/dist/config/sources/base/config-source.abstract.js.map +1 -1
  14. package/dist/config/sources/base/reloadable-config-source.abstract.js.map +1 -1
  15. package/dist/config/sources/implementations/relodable-json-file.source.js.map +1 -1
  16. package/dist/config/strategy/app-name-strategy.validator.js.map +1 -1
  17. package/dist/config/types.js.map +1 -1
  18. package/dist/config/vars.class.js.map +1 -1
  19. package/dist/context.aggregator.js.map +1 -1
  20. package/dist/exceptions/base/platform-exception.absract.js.map +1 -1
  21. package/dist/exceptions/implementations/bootstrap/double-init.exception.js.map +1 -1
  22. package/dist/exceptions/implementations/bootstrap/no-init.exception.js.map +1 -1
  23. package/dist/exceptions/metadata/exceptions.registry.js.map +1 -1
  24. package/dist/exceptions.handling/global-exceptions.filter.d.ts +3 -1
  25. package/dist/exceptions.handling/global-exceptions.filter.js +10 -4
  26. package/dist/exceptions.handling/global-exceptions.filter.js.map +1 -1
  27. package/dist/exceptions.handling/types.d.ts +4 -11
  28. package/dist/health/autodoc/heath.autodoc-resolver.js.map +1 -1
  29. package/dist/health/health.service.js.map +1 -1
  30. package/dist/health/indicators.abstract/fs-access.indicator.js.map +1 -1
  31. package/dist/index.d.ts +7 -1
  32. package/dist/index.js +22 -2
  33. package/dist/index.js.map +1 -1
  34. package/dist/logging/logging.config.js +1 -2
  35. package/dist/logging/logging.config.js.map +1 -1
  36. package/dist/metrics/metadata/autodoc/metrics.autodoc-resolver.js.map +1 -1
  37. package/dist/metrics/metrics.module.js.map +1 -1
  38. package/dist/platform.context.js.map +1 -1
  39. package/dist/platform.module.js +0 -1
  40. package/dist/platform.module.js.map +1 -1
  41. package/dist/plugin/plugin.module.js.map +1 -1
  42. package/dist/rsdk-metadata/config-metadata.extractor.js.map +1 -1
  43. package/dist/tracing/active-span.module.d.ts +5 -0
  44. package/dist/tracing/active-span.module.js +25 -0
  45. package/dist/tracing/active-span.module.js.map +1 -0
  46. package/dist/tracing/constants.d.ts +7 -1
  47. package/dist/tracing/constants.js +8 -2
  48. package/dist/tracing/constants.js.map +1 -1
  49. package/dist/tracing/decorators/span.decorator.d.ts +2 -2
  50. package/dist/tracing/decorators/span.decorator.js +14 -2
  51. package/dist/tracing/decorators/span.decorator.js.map +1 -1
  52. package/dist/tracing/index.d.ts +7 -0
  53. package/dist/tracing/index.js +7 -0
  54. package/dist/tracing/index.js.map +1 -1
  55. package/dist/tracing/request-metadata.module.d.ts +5 -0
  56. package/dist/tracing/request-metadata.module.js +25 -0
  57. package/dist/tracing/request-metadata.module.js.map +1 -0
  58. package/dist/tracing/services/active-span.storage.d.ts +17 -0
  59. package/dist/tracing/services/active-span.storage.js +46 -0
  60. package/dist/tracing/services/active-span.storage.js.map +1 -0
  61. package/dist/tracing/services/index.d.ts +0 -1
  62. package/dist/tracing/services/index.js +0 -1
  63. package/dist/tracing/services/index.js.map +1 -1
  64. package/dist/tracing/services/instrumentation.service.d.ts +2 -8
  65. package/dist/tracing/services/instrumentation.service.js +9 -114
  66. package/dist/tracing/services/instrumentation.service.js.map +1 -1
  67. package/dist/tracing/services/request-metadata.injector.d.ts +6 -0
  68. package/dist/tracing/services/request-metadata.injector.js +122 -0
  69. package/dist/tracing/services/request-metadata.injector.js.map +1 -0
  70. package/dist/tracing/services/request-metadata.storage.d.ts +32 -0
  71. package/dist/tracing/services/request-metadata.storage.js +64 -0
  72. package/dist/tracing/services/request-metadata.storage.js.map +1 -0
  73. package/dist/tracing/services/trace.injector.d.ts +1 -1
  74. package/dist/tracing/services/trace.injector.js +213 -18
  75. package/dist/tracing/services/trace.injector.js.map +1 -1
  76. package/dist/tracing/tracing.interceptor.d.ts +9 -0
  77. package/dist/tracing/tracing.interceptor.js +24 -0
  78. package/dist/tracing/tracing.interceptor.js.map +1 -0
  79. package/dist/tracing/tracing.module.d.ts +1 -1
  80. package/dist/tracing/tracing.module.js +15 -16
  81. package/dist/tracing/tracing.module.js.map +1 -1
  82. package/dist/tracing/utils/create-span.d.ts +10 -0
  83. package/dist/tracing/utils/create-span.js +20 -0
  84. package/dist/tracing/utils/create-span.js.map +1 -0
  85. package/dist/tracing/utils/save-async-hooks-context.d.ts +19 -0
  86. package/dist/tracing/utils/save-async-hooks-context.js +57 -0
  87. package/dist/tracing/utils/save-async-hooks-context.js.map +1 -0
  88. package/dist/transport/get-transport-id.d.ts +5 -0
  89. package/dist/transport/get-transport-id.js +14 -0
  90. package/dist/transport/get-transport-id.js.map +1 -0
  91. package/dist/transport/protocol.detector.d.ts +7 -0
  92. package/dist/transport/protocol.detector.js +41 -0
  93. package/dist/transport/protocol.detector.js.map +1 -0
  94. package/dist/transport/transport.module.js +9 -0
  95. package/dist/transport/transport.module.js.map +1 -1
  96. package/dist/types/index.d.ts +1 -0
  97. package/dist/types/index.js +4 -0
  98. package/dist/types/index.js.map +1 -1
  99. package/dist/types/metadata.js.map +1 -1
  100. package/dist/types/transports.d.ts +12 -0
  101. package/dist/types/transports.js.map +1 -1
  102. package/dist/unhandled-rejection.handler.js.map +1 -1
  103. package/package.json +12 -12
  104. package/src/config/reload/config-reload.events.ts +9 -0
  105. package/src/config/sources/base/config-source.abstract.ts +2 -0
  106. package/src/config/types.ts +3 -0
  107. package/src/exceptions.handling/global-exceptions.filter.ts +6 -2
  108. package/src/exceptions.handling/types.ts +4 -11
  109. package/src/index.ts +25 -1
  110. package/src/logging/logging.config.ts +1 -2
  111. package/src/platform.module.ts +1 -2
  112. package/src/tracing/active-span.module.ts +13 -0
  113. package/src/tracing/constants.ts +8 -1
  114. package/src/tracing/decorators/span.decorator.ts +19 -6
  115. package/src/tracing/index.ts +7 -0
  116. package/src/tracing/request-metadata.module.ts +13 -0
  117. package/src/tracing/services/active-span.storage.ts +32 -0
  118. package/src/tracing/services/index.ts +0 -1
  119. package/src/tracing/services/instrumentation.service.ts +16 -130
  120. package/src/tracing/services/request-metadata.injector.ts +153 -0
  121. package/src/tracing/services/request-metadata.storage.ts +69 -0
  122. package/src/tracing/services/trace.injector.ts +268 -19
  123. package/src/tracing/tracing.interceptor.ts +18 -0
  124. package/src/tracing/tracing.module.ts +14 -14
  125. package/src/tracing/utils/create-span.ts +20 -0
  126. package/src/tracing/utils/save-async-hooks-context.ts +61 -0
  127. package/src/transport/get-transport-id.ts +20 -0
  128. package/src/transport/protocol.detector.ts +38 -0
  129. package/src/transport/transport.module.ts +10 -0
  130. package/src/types/index.ts +2 -0
  131. package/src/types/transports.ts +15 -0
  132. package/tsconfig.json +12 -2
  133. package/dist/tracing/services/metadata.scanner.d.ts +0 -11
  134. package/dist/tracing/services/metadata.scanner.js +0 -50
  135. package/dist/tracing/services/metadata.scanner.js.map +0 -1
  136. package/src/tracing/services/metadata.scanner.ts +0 -40
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProtocolDetector = void 0;
4
+ const exceptions_1 = require("../exceptions");
5
+ class ProtocolDetector {
6
+ transports;
7
+ constructor(transports) {
8
+ this.transports = transports;
9
+ }
10
+ getProtocol(context) {
11
+ if (this.transports.length === 0) {
12
+ return;
13
+ }
14
+ const matchers = this.transports.map((tr) => ({
15
+ matched: tr.matchByContext(context),
16
+ tr,
17
+ }));
18
+ const matched = matchers.filter((matched) => matched.matched);
19
+ if (matched.length > 1) {
20
+ throw new exceptions_1.InternalException('So many matchers for transports', {
21
+ cause: {
22
+ matchers,
23
+ matched,
24
+ context,
25
+ },
26
+ });
27
+ }
28
+ if (matched.length === 0) {
29
+ throw new exceptions_1.InternalException('No matchers found', {
30
+ cause: {
31
+ matchers,
32
+ matched,
33
+ context,
34
+ },
35
+ });
36
+ }
37
+ return matched[0].tr.getProtocol();
38
+ }
39
+ }
40
+ exports.ProtocolDetector = ProtocolDetector;
41
+ //# sourceMappingURL=protocol.detector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.detector.js","sourceRoot":"","sources":["../../src/transport/protocol.detector.ts"],"names":[],"mappings":";;;AAEA,8CAAkD;AAGlD,MAAa,gBAAgB;IACP;IAApB,YAAoB,UAAwB;QAAxB,eAAU,GAAV,UAAU,CAAc;IAAG,CAAC;IAEhD,WAAW,CAAC,OAAsB;QAChC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO;QACT,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;YAC5C,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC;YACnC,EAAE;SACH,CAAC,CAAC,CAAC;QACJ,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9D,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,8BAAiB,CAAC,iCAAiC,EAAE;gBAC7D,KAAK,EAAE;oBACL,QAAQ;oBACR,OAAO;oBACP,OAAO;iBACR;aACF,CAAC,CAAC;QACL,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,8BAAiB,CAAC,mBAAmB,EAAE;gBAC/C,KAAK,EAAE;oBACL,QAAQ;oBACR,OAAO;oBACP,OAAO;iBACR;aACF,CAAC,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC;IACrC,CAAC;CACF;AAhCD,4CAgCC"}
@@ -6,6 +6,7 @@ const exceptions_handling_1 = require("../exceptions.handling");
6
6
  const health_module_1 = require("../health/health.module");
7
7
  const metrics_1 = require("../metrics");
8
8
  const types_1 = require("../types");
9
+ const protocol_detector_1 = require("./protocol.detector");
9
10
  class PlatformTransportModule {
10
11
  static forOptions(options) {
11
12
  return {
@@ -16,6 +17,14 @@ class PlatformTransportModule {
16
17
  ...PlatformTransportModule.getTransportModules(options),
17
18
  ],
18
19
  module: PlatformTransportModule,
20
+ providers: [
21
+ {
22
+ provide: protocol_detector_1.ProtocolDetector,
23
+ useFactory: () => new protocol_detector_1.ProtocolDetector(options.transports ?? []),
24
+ },
25
+ ],
26
+ global: true,
27
+ exports: [protocol_detector_1.ProtocolDetector],
19
28
  };
20
29
  }
21
30
  static getTransportModules(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"transport.module.js","sourceRoot":"","sources":["../../src/transport/transport.module.ts"],"names":[],"mappings":";;;AAEA,mCAAiC;AAGjC,gEAAgE;AAChE,2DAAuD;AACvD,wCAA2C;AAE3C,oCAA8C;AAE9C,MAAa,uBAAuB;IAClC,MAAM,CAAC,UAAU,CAAC,OAAgC;QAChD,OAAO;YACL,OAAO,EAAE;gBACP,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC;gBACjD,uBAAuB,CAAC,WAAW,CAAC,OAAO,CAAC;gBAC5C,uBAAuB,CAAC,sBAAsB,CAAC,OAAO,CAAC;gBACvD,GAAG,uBAAuB,CAAC,mBAAmB,CAAC,OAAO,CAAC;aACxD;YACD,MAAM,EAAE,uBAAuB;SAChC,CAAC;IACJ,CAAC;IAEO,MA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AAU,IAAI,EAAE,CAAC;QAE5C,OAAO,4CAAsB,CAAC,OAAO,CAAC;YACpC,UAAU,EAAE;gBACV,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,kBAAkB,EAAE,CAAC;gBAChD,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;aAC7D,CAAC,MAAM,CAAC,CAAC,CAAC,EAAyB,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAClD,OAAO,EAAE;gBACP,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,EAAE,EAAE,CAAC;gBAC/C,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;aAC1D,CAAC,MAAM,CAAC,CAAC,CAAC,EAAsB,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC/C,YAAY,EAAE;gBACZ,GAAG,IAAA,gBAAO,EAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,oBAAoB,EAAE,CAAC,CAAC;gBAC3D,GAAG,IAAA,gBAAO,EAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;aACvE;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAzED,0DAyEC"}
@@ -1,3 +1,4 @@
1
+ export { getTransportId, TransportId } from '../transport/get-transport-id';
1
2
  export * from './metadata';
2
3
  export * from './options';
3
4
  export * from './transports';
@@ -14,6 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.TransportId = exports.getTransportId = void 0;
18
+ var get_transport_id_1 = require("../transport/get-transport-id");
19
+ Object.defineProperty(exports, "getTransportId", { enumerable: true, get: function () { return get_transport_id_1.getTransportId; } });
20
+ Object.defineProperty(exports, "TransportId", { enumerable: true, get: function () { return get_transport_id_1.TransportId; } });
17
21
  __exportStar(require("./metadata"), exports);
18
22
  __exportStar(require("./options"), exports);
19
23
  __exportStar(require("./transports"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,4CAA0B;AAC1B,+CAA6B;AAC7B,4CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kEAA4E;AAAnE,kHAAA,cAAc,OAAA;AAAE,+GAAA,WAAW,OAAA;AAEpC,6CAA2B;AAC3B,4CAA0B;AAC1B,+CAA6B;AAC7B,4CAA0B"}
@@ -1 +1 @@
1
- {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/types/metadata.ts"],"names":[],"mappings":";;;AACA,yCAAmD;AAiBnD,SAAS,iBAAiB,CACxB,YAAiB;IAEjB,IAAI,IAAA,oBAAW,EAAC,YAAY,CAAC,EAAE;QAC7B,OAAO,YAAY,CAAC;KACrB;IACD,OAAO,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;QAChC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAA,oBAAW,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ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AC,QAAQ,EAAE,CAAC,CAAC;QAC9D,CAAC,CAAC,YAAY,EAAE,QAAQ,EAAE,CAAC;AAC/B,CAAC;AAEM,MAAM,yBAAyB,GAAG,CACvC,QAA0B,EACI,EAAE;IAChC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;IAEnD,OAAO;QACL,GAAG,IAAI;QACP,MAAM,EAAE;YACN,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE;YAEnB,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE;SAClC;QACD,GAAG,CAAC,IAAA,eAAM,EAAC,QAAQ,EAAE,cAAc,CAAC,IAAI;YACtC,+CAA+C;YAC/C,YAAY,EAAE,iBAAiB,CAAC,YAAY,CAAC;SAC9C,CAAC;KAC6B,CAAC;AACpC,CAAC,CAAC;AAjBW,QAAA,yBAAyB,6BAiBpC;AASK,MAAM,wBAAwB,GAAG,CAAC,EACvC,UAAU,EACV,GAAG,IAAI,EAGR,EAA+B,EAAE,CAAC,CAAC;IAClC,GAAG,IAAI;IACP,iEAAiE;IACjE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,iCAAyB,CAAC;CACrE,CAAC,CAAC;AATU,QAAA,wBAAwB,4BASlC"}
@@ -1,3 +1,4 @@
1
+ import type { ArgumentsHost } from '@nestjs/common';
1
2
  import type { Controller, INestApplication } from '@nestjs/common/interfaces';
2
3
  import type { AbstractHttpAdapter } from '@nestjs/core';
3
4
  import type { MicroserviceOptions } from '@nestjs/microservices';
@@ -13,6 +14,17 @@ export interface ITransport {
13
14
  * @returns protocol in text format
14
15
  */
15
16
  getProtocol(): string;
17
+ /**
18
+ * Detect is it context of this transport
19
+ * !!! Do NOT check on getType() === 'rpc', this type corresponds to all microservices
20
+ *
21
+ * @param {ArgumentsHost} ctx
22
+ * @returns {boolean}
23
+ * @example
24
+ * return ctx.getType() === 'http'
25
+ * return ctx.getArgByIndex(1) instanceof MyTransportContext
26
+ */
27
+ matchByContext(ctx: ArgumentsHost): boolean;
16
28
  /**
17
29
  * @returns error formatting algorithm
18
30
  */
@@ -1 +1 @@
1
- {"version":3,"file":"transports.js","sourceRoot":"","sources":["../../src/types/transports.ts"],"names":[],"mappings":";;;AA8GO,MAAM,kBAAkB,GAAG,CAAC,CAAa,EAA0B,EAAE,CAC1E,OAAQ,CAAuB,CAAC,mBAAmB,KAAK,UAAU;IAClE,OAAQ,CAAuB,CAAC,oBAAoB,KAAK,UAAU,CAAC;AAFzD,QAAA,kBAAkB,sBAEuC;AAE/D,MAAM,eAAe,GAAG,CAAC,CAAa,EAAuB,EAAE,CACpE,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;AADhB,QAAA,eAAe,mBACC;AAEtB,MAAM,uBAAuB,GAAG,CACrC,CAAa,EACgB,EAAE,CAC/B,OAAQ,CAA4B,CAAC,yBAAyB,KAAK,UAAU,CAAC;AAHnE,QAAA,uBAAuB,2BAG4C"}
1
+ {"version":3,"file":"transports.js","sourceRoot":"","sources":["../../src/types/transports.ts"],"names":[],"mappings":";;;AA6HO,MAAM,kBAAkB,GAAG,CAAC,CAAa,EAA0B,EAAE,CAC1E,OAAQ,CAAuB,CAAC,mBAAmB,KAAK,UAAU;IAClE,OAAQ,CAAuB,CAAC,oBAAoB,KAAK,UAAU,CAAC;AAFzD,QAAA,kBAAkB,sBAEuC;AAE/D,MAAM,eAAe,GAAG,CAAC,CAAa,EAAuB,EAAE,CACpE,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;AADhB,QAAA,eAAe,mBACC;AAEtB,MAAM,uBAAuB,GAAG,CACrC,CAAa,EACgB,EAAE,CAC/B,OAAQ,CAA4B,CAAC,yBAAyB,KAAK,UAAU,CAAC;AAHnE,QAAA,uBAAuB,2BAG4C"}
@@ -1 +1 @@
1
- {"version":3,"file":"unhandled-rejection.handler.js","sourceRoot":"","sources":["../src/unhandled-rejection.handler.ts"],"names":[],"mappings":";;AAAA,yCAAoC;AACpC,2CAA8C;AAE9C,MAAM,MAAM,GAAG,uBAAa,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAEvD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE;IAC9B,MAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;CAC5D;AAED,2DAA2D;AAC3D,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAW,EAAE,OAAO,EAAE,EAAE;IACxD,MAAM,CAAC,KAAK,CACV,IAAA,aAAI,EAAA;;;;OAID,EACH,EAAE,OAAO,EAAE,MAAM,EAAE,CACpB,CAAC;IAEF;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE;QACzC,OAAO;QACP,MAAM;KACP,CAAC,CAAC;IAEH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"unhandled-rejection.handler.js","sourceRoot":"","sources":["../src/unhandled-rejection.handler.ts"],"names":[],"mappings":";;AAAA,yCAAoC;AACpC,2CAA8C;AAE9C,MAAM,MAAM,GAAG,uBAAa,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAEvD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;IAC/B,MAAM,CAAC,IAAI,CAAC,6CAA6C,CAAC,CAAC;AAC7D,CAAC;AAED,2DAA2D;AAC3D,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAW,EAAE,OAAO,EAAE,EAAE;IACxD,MAAM,CAAC,KAAK,CACV,IAAA,aAAI,EAAA;;;;OAID,EACH,EAAE,OAAO,EAAE,MAAM,EAAE,CACpB,CAAC;IAEF;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE;QACzC,OAAO;QACP,MAAM;KACP,CAAC,CAAC;IAEH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdk/core",
3
- "version": "4.0.0-next.9",
3
+ "version": "4.0.0",
4
4
  "description": "Nestjs based microservice chassis",
5
5
  "license": "Apache License 2.0",
6
6
  "publishConfig": {
@@ -20,9 +20,9 @@
20
20
  "@opentelemetry/exporter-trace-otlp-http": "0.39.1",
21
21
  "@opentelemetry/propagator-b3": "1.13.0",
22
22
  "@opentelemetry/resources": "1.13.0",
23
- "@opentelemetry/sdk-node": "^0.39.1",
23
+ "@opentelemetry/sdk-node": "0.39.1",
24
24
  "@opentelemetry/sdk-trace-base": "1.13.0",
25
- "@opentelemetry/semantic-conventions": "1.13.0",
25
+ "@opentelemetry/semantic-conventions": "1.18.1",
26
26
  "dotenv": "^16.3.1",
27
27
  "lodash": "^4.17.21",
28
28
  "prom-client": "^14.2.0"
@@ -31,18 +31,18 @@
31
31
  "@nestjs/common": "^10.0.0",
32
32
  "@nestjs/core": "^10.0.0",
33
33
  "@nestjs/microservices": "^10.0.0",
34
- "@rsdk/autodoc.protocol": "^4.0.0-next.9",
35
- "@rsdk/common": "^4.0.0-next.9",
36
- "@rsdk/common.nestjs": "^4.0.0-next.9",
37
- "@rsdk/common.node": "^4.0.0-next.9",
38
- "@rsdk/decorators": "^4.0.0-next.9",
39
- "@rsdk/logging": "^4.0.0-next.9",
40
- "@rsdk/metadata": "^4.0.0-next.9",
41
- "@rsdk/nest-tools": "^4.0.0-next.9",
34
+ "@rsdk/autodoc.protocol": "^4.0.0",
35
+ "@rsdk/common": "^4.0.0",
36
+ "@rsdk/common.nestjs": "^4.0.0",
37
+ "@rsdk/common.node": "^4.0.0",
38
+ "@rsdk/decorators": "^4.0.0",
39
+ "@rsdk/logging": "^4.0.0",
40
+ "@rsdk/metadata": "^4.0.0",
41
+ "@rsdk/nest-tools": "^4.0.0",
42
42
  "axios": "^1.1.3",
43
43
  "pino": "^8.16.1",
44
44
  "reflect-metadata": "^0.1.13",
45
45
  "rxjs": "^7.0.0"
46
46
  },
47
- "gitHead": "889228ebf4076fafc1c7fce4406b1ea5a3d985ff"
47
+ "gitHead": "e38e5b762d2c4aab277f0f65a5be5abcbccba8a8"
48
48
  }
@@ -11,23 +11,32 @@ export class ReloadEvents extends EventEmitter {}
11
11
  // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
12
12
  export declare interface ReloadEvents {
13
13
  on(e: 'reload', fn: (source: ConfigSource, values: RawValues) => void): this;
14
+
14
15
  on(
15
16
  e: 'reload_failure',
16
17
  fn: (source: ConfigSource, err: ConfigSourceException) => void,
17
18
  ): this;
19
+
18
20
  on(e: 'merge', fn: (source: ConfigSource, changes: Changes) => void): this;
21
+
19
22
  on(e: 'update', fn: (section: Config, keys: string[]) => void): this;
23
+
20
24
  on(
21
25
  e: 'update_failure',
22
26
  fn: (section: Config, err: PropertyException) => void,
23
27
  ): this;
28
+
24
29
  emit(e: 'reload', source: ConfigSource, values: RawValues): boolean;
30
+
25
31
  emit(
26
32
  e: 'reload_failure',
27
33
  source: ConfigSource,
28
34
  err: ConfigSourceException,
29
35
  ): boolean;
36
+
30
37
  emit(e: 'merge', source: ConfigSource, changes: Changes): boolean;
38
+
31
39
  emit(e: 'update', section: Config, keys: string[]): boolean;
40
+
32
41
  emit(e: 'update_failure', section: Config, err: PropertyException): boolean;
33
42
  }
@@ -85,6 +85,8 @@ export abstract class ConfigSource {
85
85
  }
86
86
 
87
87
  abstract name(): string;
88
+
88
89
  abstract type(): SourceType;
90
+
89
91
  abstract loadRaw(): Promise<unknown>;
90
92
  }
@@ -70,7 +70,9 @@ export interface ParserMetadata {
70
70
  */
71
71
  export interface PropertyParser<T = any> {
72
72
  type(): string;
73
+
73
74
  description(): string;
75
+
74
76
  parse(value: unknown): T;
75
77
  }
76
78
 
@@ -83,5 +85,6 @@ export enum AppNameStrategyType {
83
85
 
84
86
  export interface AppNameStrategy {
85
87
  type: AppNameStrategyType;
88
+
86
89
  transform(appName: string): string;
87
90
  }
@@ -7,6 +7,7 @@ import { throwError } from 'rxjs';
7
7
 
8
8
  import { InternalException, PipelineException } from '../exceptions';
9
9
  import { InjectLogger } from '../logging';
10
+ import { ProtocolDetector } from '../transport/protocol.detector';
10
11
 
11
12
  import { FORMATTERS, SENDERS, TRANSFORMERS } from './constants';
12
13
  import { GlobalExceptionsConfig } from './global-exceptions.config';
@@ -25,6 +26,7 @@ export class GlobalExceptionsFilter implements ExceptionFilter {
25
26
  @InjectLogger(GlobalExceptionsFilter)
26
27
  private readonly logger: ILogger,
27
28
  private readonly config: GlobalExceptionsConfig,
29
+ private detector: ProtocolDetector,
28
30
  ) {}
29
31
 
30
32
  catch(ex: any, host: ArgumentsHost): Observable<any> {
@@ -53,7 +55,8 @@ export class GlobalExceptionsFilter implements ExceptionFilter {
53
55
  }
54
56
 
55
57
  private format(host: ArgumentsHost, ex: unknown): unknown {
56
- const formatter = this.formatters.find((x) => x.match(host, ex));
58
+ const protocol = this.detector.getProtocol(host);
59
+ const formatter = this.formatters.find((x) => x.protocol === protocol);
57
60
  if (formatter) {
58
61
  this.logger.trace(`Found formatter: ${formatter.constructor.name}`);
59
62
 
@@ -74,7 +77,8 @@ export class GlobalExceptionsFilter implements ExceptionFilter {
74
77
  }
75
78
 
76
79
  private send(host: ArgumentsHost, ex: any): Observable<unknown> {
77
- const sender = this.senders.find((x) => x.match(host));
80
+ const protocol = this.detector.getProtocol(host);
81
+ const sender = this.senders.find((x) => x.protocol === protocol);
78
82
 
79
83
  return sender?.send(host, ex) ?? throwError(() => ex);
80
84
  }
@@ -13,13 +13,9 @@ import type { PipelineException } from '../exceptions/base';
13
13
  */
14
14
  export interface IErrorsFormatter {
15
15
  /**
16
- * Matcher returns true if exception should be processed with
17
- * this formatter. Most common use is match by context type.
18
- *
19
- * @param host ArgumentsHost - nest.js wrapper over request context
20
- * @param exception Exception itself
16
+ * Platform Transport protocol from `getProtocol`
21
17
  */
22
- match(host: ArgumentsHost, exception?: unknown): boolean;
18
+ protocol: string;
23
19
 
24
20
  /**
25
21
  * Formatting algorithm that should match received exception with
@@ -40,12 +36,9 @@ export interface IErrorsFormatter {
40
36
  */
41
37
  export interface IErrorsSender {
42
38
  /**
43
- * Matcher returns true if exception should be processed with
44
- * this formatter. Most common use is match by context type.
45
- *
46
- * @param host ArgumentsHost - nest.js wrapper over request context
39
+ * Platform Transport protocol from `getProtocol`
47
40
  */
48
- match(host: ArgumentsHost): boolean;
41
+ protocol: string;
49
42
 
50
43
  /**
51
44
  * Implementation of sending error back to the client
package/src/index.ts CHANGED
@@ -1,5 +1,22 @@
1
1
  import './unhandled-rejection.handler';
2
2
 
3
+ export { Manifest } from './manifest/manifest';
4
+
5
+ export { ProtocolDetector } from './transport/protocol.detector';
6
+
7
+ export { X_REQUEST_ID } from './tracing/constants';
8
+
9
+ export {
10
+ RequestMetadata,
11
+ RequestMetadataStorage,
12
+ TracingModule,
13
+ saveAsyncHooksContext,
14
+ createSpan,
15
+ ActiveSpanModule,
16
+ ActiveSpanStorage,
17
+ Span,
18
+ } from './tracing';
19
+
3
20
  export {
4
21
  FileSystemCheckOptions,
5
22
  FileSystemIndicator,
@@ -36,9 +53,9 @@ export {
36
53
  Counter,
37
54
  Gauge,
38
55
  Histogram,
39
- Summary,
40
56
  Metric,
41
57
  MetricsModule,
58
+ Summary,
42
59
  register,
43
60
  } from './metrics';
44
61
 
@@ -49,3 +66,10 @@ export * from './types';
49
66
  export * from './app-metadata/decorators';
50
67
 
51
68
  export * from './app-metadata/app-metadata.const';
69
+ export { getTransportId } from './transport/get-transport-id';
70
+
71
+ export {
72
+ X_B3_PARENT_SPAN_ID,
73
+ X_B3_SPAN_ID,
74
+ X_B3_TRACE_ID,
75
+ } from '@opentelemetry/propagator-b3';
@@ -1,5 +1,4 @@
1
- import { LogLevel } from '@rsdk/logging';
2
- import { DEFAULT_LEVEL } from '@rsdk/logging/dist/defaults';
1
+ import { DEFAULT_LEVEL, LogLevel } from '@rsdk/logging';
3
2
 
4
3
  import {
5
4
  ArrayParser,
@@ -1,5 +1,5 @@
1
1
  import type { DynamicModule, NestModule } from '@nestjs/common';
2
- import { Inject, Module } from '@nestjs/common';
2
+ import { Inject } from '@nestjs/common';
3
3
  import type { MiddlewareConsumer } from '@nestjs/common/interfaces';
4
4
  import type { Constructor } from '@rsdk/common';
5
5
 
@@ -12,7 +12,6 @@ import { LoggingModule } from './logging';
12
12
  import { TracingModule } from './tracing';
13
13
  import { PlatformExtendedOptions } from './types';
14
14
 
15
- @Module({})
16
15
  export class PlatformModule implements NestModule {
17
16
  constructor(
18
17
  @Inject('PlatformExtendedOptions') private options: PlatformExtendedOptions,
@@ -0,0 +1,13 @@
1
+ import { Global, Module } from '@nestjs/common';
2
+
3
+ import { ActiveSpanStorage } from './services/active-span.storage';
4
+
5
+ /**
6
+ * Модуль для получения данных активного спана
7
+ */
8
+ @Global()
9
+ @Module({
10
+ providers: [ActiveSpanStorage],
11
+ exports: [ActiveSpanStorage],
12
+ })
13
+ export class ActiveSpanModule {}
@@ -1,6 +1,13 @@
1
+ import { Size } from '@rsdk/common';
2
+
1
3
  export enum Constants {
2
4
  TRACE_METADATA_ACTIVE = 'OPEN_TELEMETRY_TRACE_METADATA_ACTIVE',
5
+ REQUEST_METADATA_ASYNC_LOCAL_STORAGE_ACTIVE = 'REQUEST_METADATA_ASYNC_LOCAL_STORAGE_ACTIVE',
3
6
  NO_SPAN_METADATA = 'NO_SPAN_METADATA',
4
7
  }
5
8
 
6
- export const MAX_BYTES = 100 * 1_024; // 100kb;
9
+ /**
10
+ * Ид запроса - нужен для фильтрации запросов при поиске проблем от конкретного клиента
11
+ */
12
+ export const X_REQUEST_ID = 'x-requestid';
13
+ export const MAX_BYTES = new Size(100, 'kb');
@@ -1,21 +1,34 @@
1
+ import { MetadataScanner } from '@nestjs/core';
2
+
1
3
  import { SymbolKeyDecorationException } from '../../exceptions';
2
4
  import { TraceInjector } from '../services';
3
5
 
6
+ const metadataScanner = new MetadataScanner();
7
+
4
8
  /**
5
- * Explicitly adds instrumentation to method (don't work for classes!).
9
+ * Explicitly adds instrumentation.
6
10
  * Use for classes that you instantiate manually.
7
11
  * NOTE: Is redundant for injectables and other nest.js stuff
8
12
  */
9
- export const Span = (): MethodDecorator =>
13
+ export const Span = (): MethodDecorator & ClassDecorator =>
10
14
  // eslint-disable-next-line unicorn/consistent-function-scoping
11
15
  function (
12
16
  target: object,
13
- methodName: string | symbol,
14
- descriptor: TypedPropertyDescriptor<any>,
15
- ) {
17
+ methodName?: string | symbol,
18
+ descriptor?: TypedPropertyDescriptor<any>,
19
+ ): any {
16
20
  if (typeof methodName === 'symbol') {
17
21
  throw new SymbolKeyDecorationException();
18
22
  }
23
+ if (methodName && descriptor) {
24
+ TraceInjector.wrap(target, descriptor.value, descriptor);
25
+ } else {
26
+ const prototype = (target as any).prototype ?? target;
19
27
 
20
- TraceInjector.wrap(target, descriptor.value, descriptor);
28
+ for (const name of metadataScanner.getAllMethodNames(prototype)) {
29
+ if (name) {
30
+ TraceInjector.wrap(prototype, prototype[name]);
31
+ }
32
+ }
33
+ }
21
34
  };
@@ -1 +1,8 @@
1
+ export * from './active-span.module';
2
+ export * from './request-metadata.module';
3
+ export * from './services/active-span.storage';
4
+ export * from './services/request-metadata.storage';
1
5
  export * from './tracing.module';
6
+ export * from './utils/create-span';
7
+ export * from './utils/save-async-hooks-context';
8
+ export * from './decorators';
@@ -0,0 +1,13 @@
1
+ import { Global, Module } from '@nestjs/common';
2
+
3
+ import { RequestMetadataStorage } from './services/request-metadata.storage';
4
+
5
+ /**
6
+ * Модуль для хранения и получения данных из аскин локал стораджа
7
+ */
8
+ @Global()
9
+ @Module({
10
+ providers: [RequestMetadataStorage],
11
+ exports: [RequestMetadataStorage],
12
+ })
13
+ export class RequestMetadataModule {}
@@ -0,0 +1,32 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import type { Span } from '@opentelemetry/api';
3
+ import { api } from '@opentelemetry/sdk-node';
4
+
5
+ /**
6
+ * Обертка вокруг `api.trace.getActiveSpan()`
7
+ */
8
+ @Injectable()
9
+ export class ActiveSpanStorage {
10
+ /**
11
+ * Так как этот сервис используется в разных местах, чтобы не усложнять существующий код путем проксирования модулей и сервисов
12
+ * после создания ложим инстанс в эту статик переменную
13
+ */
14
+ private static instance: ActiveSpanStorage | undefined;
15
+
16
+ constructor() {
17
+ if (!ActiveSpanStorage.instance) {
18
+ ActiveSpanStorage.instance = this;
19
+ }
20
+ }
21
+
22
+ static getInstance(): ActiveSpanStorage | undefined {
23
+ return ActiveSpanStorage.instance;
24
+ }
25
+
26
+ /**
27
+ * Получает новое значение в контекст
28
+ */
29
+ getActiveSpan(): Span | undefined {
30
+ return api.trace.getActiveSpan();
31
+ }
32
+ }
@@ -1,3 +1,2 @@
1
1
  export * from './instrumentation.service';
2
- export * from './metadata.scanner';
3
2
  export * from './trace.injector';