@rsdk/core 5.0.0-next.2 → 5.0.0-next.4
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 +14 -0
- package/dist/config/metadata/decorators/inject-property.decorator.d.ts +1 -1
- package/dist/config/metadata/decorators/property.decorator.d.ts +1 -1
- package/dist/config/parsers/url/exception.d.ts +0 -1
- package/dist/config/parsers/url/url.parser.d.ts +0 -1
- package/dist/config/reload/config-reload.events.d.ts +0 -1
- package/dist/exceptions.handling/global-exceptions.filter.d.ts +1 -1
- package/dist/exceptions.handling/global-exceptions.filter.js +2 -5
- package/dist/exceptions.handling/global-exceptions.filter.js.map +1 -1
- package/dist/health/indicators.abstract/ping.indicator.d.ts +0 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/dist/logging/logger-initializing.module.d.ts +1 -1
- package/dist/logging/logger-initializing.module.js +1 -1
- package/dist/logging/logger-initializing.module.js.map +1 -1
- package/dist/metrics/metadata/decorators/metric.decorator.js +1 -2
- package/dist/metrics/metadata/decorators/metric.decorator.js.map +1 -1
- package/dist/metrics/metric-initializing.module.d.ts +1 -1
- package/dist/metrics/metric-initializing.module.js +1 -1
- package/dist/metrics/metric-initializing.module.js.map +1 -1
- package/dist/platform.context.d.ts +5 -5
- package/dist/platform.context.js +28 -24
- package/dist/platform.context.js.map +1 -1
- package/dist/platform.module.d.ts +1 -1
- package/dist/platform.module.js +10 -9
- package/dist/platform.module.js.map +1 -1
- package/dist/tracing/constants.d.ts +12 -9
- package/dist/tracing/constants.js +13 -11
- package/dist/tracing/constants.js.map +1 -1
- package/dist/tracing/index.d.ts +3 -3
- package/dist/tracing/index.js +3 -3
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/opentelemetry/decorators/index.js.map +1 -0
- package/dist/tracing/{decorators → opentelemetry/decorators}/no-span.decorator.d.ts +1 -1
- package/dist/tracing/{decorators → opentelemetry/decorators}/no-span.decorator.js +3 -3
- package/dist/tracing/opentelemetry/decorators/no-span.decorator.js.map +1 -0
- package/dist/tracing/{decorators → opentelemetry/decorators}/span.decorator.js +5 -4
- package/dist/tracing/opentelemetry/decorators/span.decorator.js.map +1 -0
- package/dist/tracing/opentelemetry/index.d.ts +1 -0
- package/dist/tracing/{services → opentelemetry}/index.js +1 -1
- package/dist/tracing/opentelemetry/index.js.map +1 -0
- package/dist/tracing/opentelemetry/opentelemetry.helpers.d.ts +28 -0
- package/dist/tracing/opentelemetry/opentelemetry.helpers.js +77 -0
- package/dist/tracing/opentelemetry/opentelemetry.helpers.js.map +1 -0
- package/dist/tracing/opentelemetry/opentelemetry.metadata.d.ts +7 -0
- package/dist/tracing/opentelemetry/opentelemetry.metadata.js +27 -0
- package/dist/tracing/opentelemetry/opentelemetry.metadata.js.map +1 -0
- package/dist/tracing/opentelemetry/opentelemetry.wrapper.d.ts +6 -0
- package/dist/tracing/opentelemetry/opentelemetry.wrapper.js +71 -0
- package/dist/tracing/opentelemetry/opentelemetry.wrapper.js.map +1 -0
- package/dist/tracing/tracing.actx.d.ts +1 -0
- package/dist/tracing/tracing.actx.js +9 -0
- package/dist/tracing/tracing.actx.js.map +1 -0
- package/dist/tracing/tracing.interceptor.d.ts +20 -4
- package/dist/tracing/tracing.interceptor.js +59 -9
- package/dist/tracing/tracing.interceptor.js.map +1 -1
- package/dist/tracing/tracing.module.d.ts +10 -4
- package/dist/tracing/tracing.module.js +63 -21
- package/dist/tracing/tracing.module.js.map +1 -1
- package/dist/tracing/types.d.ts +9 -11
- package/dist/tracing/types.js +0 -20
- package/dist/tracing/types.js.map +1 -1
- package/dist/transport/protocol.detector.d.ts +13 -1
- package/dist/transport/protocol.detector.js +17 -24
- package/dist/transport/protocol.detector.js.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +1 -4
- package/dist/types/index.js.map +1 -1
- package/dist/types/options.d.ts +2 -0
- package/dist/types/plugins.d.ts +8 -3
- package/dist/types/plugins.js.map +1 -1
- package/dist/types/transports.d.ts +19 -9
- package/dist/types/transports.js +3 -1
- package/dist/types/transports.js.map +1 -1
- package/package.json +9 -4
- package/src/exceptions.handling/global-exceptions.filter.ts +5 -6
- package/src/index.ts +3 -3
- package/src/logging/logger-initializing.module.ts +2 -2
- package/src/metrics/metric-initializing.module.ts +2 -2
- package/src/platform.context.ts +41 -32
- package/src/platform.module.ts +9 -8
- package/src/tracing/constants.ts +15 -9
- package/src/tracing/index.ts +3 -3
- package/src/tracing/opentelemetry/decorators/no-span.decorator.ts +10 -0
- package/src/tracing/{decorators → opentelemetry/decorators}/span.decorator.ts +8 -4
- package/src/tracing/opentelemetry/index.ts +1 -0
- package/src/tracing/opentelemetry/opentelemetry.helpers.ts +89 -0
- package/src/tracing/opentelemetry/opentelemetry.metadata.ts +24 -0
- package/src/tracing/opentelemetry/opentelemetry.wrapper.ts +90 -0
- package/src/tracing/tracing.actx.ts +8 -0
- package/src/tracing/tracing.interceptor.ts +65 -8
- package/src/tracing/tracing.module.ts +64 -23
- package/src/tracing/types.ts +9 -28
- package/src/transport/protocol.detector.ts +19 -25
- package/src/types/index.ts +0 -2
- package/src/types/options.ts +3 -0
- package/src/types/plugins.ts +9 -2
- package/src/types/transports.ts +27 -11
- package/dist/tracing/decorators/index.js.map +0 -1
- package/dist/tracing/decorators/no-span.decorator.js.map +0 -1
- package/dist/tracing/decorators/span.decorator.js.map +0 -1
- package/dist/tracing/request-metadata.module.d.ts +0 -5
- package/dist/tracing/request-metadata.module.js +0 -21
- package/dist/tracing/request-metadata.module.js.map +0 -1
- package/dist/tracing/services/index.d.ts +0 -1
- package/dist/tracing/services/index.js.map +0 -1
- package/dist/tracing/services/trace.injector.d.ts +0 -12
- package/dist/tracing/services/trace.injector.js +0 -154
- package/dist/tracing/services/trace.injector.js.map +0 -1
- package/dist/tracing/tracing.config.d.ts +0 -6
- package/dist/tracing/tracing.config.js +0 -39
- package/dist/tracing/tracing.config.js.map +0 -1
- package/dist/tracing/utils/create-span.d.ts +0 -10
- package/dist/tracing/utils/create-span.js +0 -20
- package/dist/tracing/utils/create-span.js.map +0 -1
- package/dist/transport/get-transport-id.d.ts +0 -5
- package/dist/transport/get-transport-id.js +0 -14
- package/dist/transport/get-transport-id.js.map +0 -1
- package/dist/types/tracing.headers-extractor.d.ts +0 -15
- package/dist/types/tracing.headers-extractor.js +0 -67
- package/dist/types/tracing.headers-extractor.js.map +0 -1
- package/src/tracing/decorators/no-span.decorator.ts +0 -10
- package/src/tracing/request-metadata.module.ts +0 -8
- package/src/tracing/services/index.ts +0 -1
- package/src/tracing/services/trace.injector.ts +0 -190
- package/src/tracing/tracing.config.ts +0 -25
- package/src/tracing/utils/create-span.ts +0 -20
- package/src/transport/get-transport-id.ts +0 -20
- package/src/types/tracing.headers-extractor.ts +0 -51
- /package/dist/tracing/{decorators → opentelemetry/decorators}/index.d.ts +0 -0
- /package/dist/tracing/{decorators → opentelemetry/decorators}/index.js +0 -0
- /package/dist/tracing/{decorators → opentelemetry/decorators}/span.decorator.d.ts +0 -0
- /package/src/tracing/{decorators → opentelemetry/decorators}/index.ts +0 -0
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import type { ArgumentsHost } from '@nestjs/common';
|
|
2
2
|
import type { ITransport } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* This class is used to detect current protocol (transport type).
|
|
5
|
+
* Mostly used in global enhancers to decide: "to work of not to work"
|
|
6
|
+
*/
|
|
3
7
|
export declare class ProtocolDetector {
|
|
4
8
|
private transports;
|
|
5
9
|
constructor(transports: ITransport[]);
|
|
6
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Detects transport's protocol by ArgumentHost (context)
|
|
12
|
+
*/
|
|
7
13
|
getProtocol(context: ArgumentsHost): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Checks that transport's protocol matches the provided one.
|
|
16
|
+
* (just convenience method)
|
|
17
|
+
*/
|
|
18
|
+
matchProtocol(context: ArgumentsHost, protocol: string): boolean;
|
|
19
|
+
private getTransport;
|
|
8
20
|
}
|
|
@@ -1,38 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ProtocolDetector = void 0;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* This class is used to detect current protocol (transport type).
|
|
6
|
+
* Mostly used in global enhancers to decide: "to work of not to work"
|
|
7
|
+
*/
|
|
5
8
|
class ProtocolDetector {
|
|
6
9
|
transports;
|
|
7
10
|
constructor(transports) {
|
|
8
11
|
this.transports = transports;
|
|
9
12
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
return matched[0].tr;
|
|
32
|
-
}
|
|
13
|
+
/**
|
|
14
|
+
* Detects transport's protocol by ArgumentHost (context)
|
|
15
|
+
*/
|
|
33
16
|
getProtocol(context) {
|
|
34
17
|
return this.getTransport(context)?.getProtocol();
|
|
35
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Checks that transport's protocol matches the provided one.
|
|
21
|
+
* (just convenience method)
|
|
22
|
+
*/
|
|
23
|
+
matchProtocol(context, protocol) {
|
|
24
|
+
return this.getProtocol(context) === protocol;
|
|
25
|
+
}
|
|
26
|
+
getTransport(context) {
|
|
27
|
+
return this.transports.filter((x) => x.matchByContext(context)).pop();
|
|
28
|
+
}
|
|
36
29
|
}
|
|
37
30
|
exports.ProtocolDetector = ProtocolDetector;
|
|
38
31
|
//# sourceMappingURL=protocol.detector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.detector.js","sourceRoot":"","sources":["../../src/transport/protocol.detector.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"protocol.detector.js","sourceRoot":"","sources":["../../src/transport/protocol.detector.ts"],"names":[],"mappings":";;;AAIA;;;GAGG;AACH,MAAa,gBAAgB;IACP;IAApB,YAAoB,UAAwB;QAAxB,eAAU,GAAV,UAAU,CAAc;IAAG,CAAC;IAEhD;;OAEG;IACH,WAAW,CAAC,OAAsB;QAChC,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;IACnD,CAAC;IAED;;;OAGG;IACH,aAAa,CAAC,OAAsB,EAAE,QAAgB;QACpD,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC;IAChD,CAAC;IAEO,YAAY,CAAC,OAAsB;QACzC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;IACxE,CAAC;CACF;AArBD,4CAqBC"}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -14,10 +14,7 @@ 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.APP_PLUGINS = exports.APP_TRANSPORTS =
|
|
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
|
+
exports.APP_PLUGINS = exports.APP_TRANSPORTS = void 0;
|
|
21
18
|
__exportStar(require("./metadata"), exports);
|
|
22
19
|
__exportStar(require("./options"), exports);
|
|
23
20
|
__exportStar(require("./transports"), exports);
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,4CAA0B;AAC1B,+CAA6B;AAC7B,4CAA0B;AAC1B,yCAA6C;AAApC,2GAAA,cAAc,OAAA;AACvB,yCAA0C;AAAjC,wGAAA,WAAW,OAAA"}
|
package/dist/types/options.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RequiredFields } from '@rsdk/common';
|
|
2
2
|
import type { NestModuleDefinition } from '@rsdk/common.nestjs';
|
|
3
3
|
import type { ConfigModuleOptions } from '../config';
|
|
4
|
+
import type { TracingOptions } from '../tracing';
|
|
4
5
|
import type { PlatformAppPlugin } from './plugins';
|
|
5
6
|
import type { IPrimaryTransport, ITransport } from './transports';
|
|
6
7
|
/**
|
|
@@ -66,6 +67,7 @@ export interface PlatformOptions extends PlatformManifestPathOptions {
|
|
|
66
67
|
* Plugins extend application functionality.
|
|
67
68
|
*/
|
|
68
69
|
plugins?: PlatformAppPlugin[];
|
|
70
|
+
tracing?: TracingOptions;
|
|
69
71
|
}
|
|
70
72
|
export type PlatformAppOptions = RequiredFields<PlatformOptions, 'transports' | 'modules'>;
|
|
71
73
|
export type PlatformExtendedOptions = PlatformOptions & ManifestData & {
|
package/dist/types/plugins.d.ts
CHANGED
|
@@ -2,10 +2,11 @@ import type { DynamicModule, MiddlewareConsumer } from '@nestjs/common';
|
|
|
2
2
|
import type { Constructor } from '@rsdk/common';
|
|
3
3
|
import type { ResourceExtractor } from '@rsdk/metadata';
|
|
4
4
|
import type { IErrorsFormatter, IErrorsSender, IErrorsTransformer } from '../exceptions.handling';
|
|
5
|
-
import type {
|
|
5
|
+
import type { TracingHeaderMappings } from '../tracing';
|
|
6
|
+
import type { WithGenericHeaders } from './transports';
|
|
6
7
|
export type SpecifiedTransports = Readonly<string[]>;
|
|
7
8
|
export type AppropriateTransports = SpecifiedTransports | 'any';
|
|
8
|
-
export declare const hasSpecifiedTransports: (x: PlatformAppPlugin) => x is PlatformAppPlugin<
|
|
9
|
+
export declare const hasSpecifiedTransports: (x: PlatformAppPlugin) => x is PlatformAppPlugin<SpecifiedTransports>;
|
|
9
10
|
/**
|
|
10
11
|
* PlatformApp philosophy assumes that initialization
|
|
11
12
|
* should not be exposed outside the library. But there
|
|
@@ -20,8 +21,8 @@ export interface PlatformAppPlugin<T extends AppropriateTransports = Appropriate
|
|
|
20
21
|
*/
|
|
21
22
|
extractors?(): ResourceExtractor[];
|
|
22
23
|
tracingHeadersExtractors?(): {
|
|
23
|
-
extractor: ProtocolTracingHeadersExtractor;
|
|
24
24
|
protocol: string;
|
|
25
|
+
extractor: WithGenericHeaders;
|
|
25
26
|
}[];
|
|
26
27
|
/**
|
|
27
28
|
* Returns list of appropriate transports.
|
|
@@ -60,4 +61,8 @@ export interface PlatformAppPlugin<T extends AppropriateTransports = Appropriate
|
|
|
60
61
|
* @param consumer MiddlewareConsumer
|
|
61
62
|
*/
|
|
62
63
|
configureMiddleware?(consumer: MiddlewareConsumer): void;
|
|
64
|
+
/**
|
|
65
|
+
* Additional header mappings
|
|
66
|
+
*/
|
|
67
|
+
additionalTracingHeaders?(): TracingHeaderMappings[];
|
|
63
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/types/plugins.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/types/plugins.ts"],"names":[],"mappings":";;;AAgBO,MAAM,sBAAsB,GAAG,CACpC,CAAoB,EACyB,EAAE,CAAC,CAAC,CAAC,aAAa,EAAE,KAAK,KAAK,CAAC;AAFjE,QAAA,sBAAsB,0BAE2C"}
|
|
@@ -1,16 +1,30 @@
|
|
|
1
|
-
import type { ArgumentsHost
|
|
2
|
-
import type { Controller, INestApplication } from '@nestjs/common/interfaces';
|
|
1
|
+
import type { ArgumentsHost } from '@nestjs/common';
|
|
2
|
+
import type { Controller, ExecutionContext, INestApplication } from '@nestjs/common/interfaces';
|
|
3
3
|
import type { AbstractHttpAdapter } from '@nestjs/core';
|
|
4
4
|
import type { MicroserviceOptions } from '@nestjs/microservices';
|
|
5
5
|
import type { Constructor } from '@rsdk/common';
|
|
6
6
|
import type { ConfigContext } from '../config';
|
|
7
7
|
import type { IErrorsFormatter, IErrorsSender, IErrorsTransformer } from '../exceptions.handling';
|
|
8
|
-
import type { TracingHeaders } from '../tracing/types';
|
|
9
8
|
import type { NestModuleDefinitions } from './options';
|
|
9
|
+
export interface GenericHeaders {
|
|
10
|
+
get(key: string): string | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Every transport has generic some sort of headers/metadata
|
|
14
|
+
* that can be represented as key/value pairs. But implementation
|
|
15
|
+
* differs. This interface is made to generalize this headers
|
|
16
|
+
*
|
|
17
|
+
* NOTE: Not only transports but also plugins can implement
|
|
18
|
+
* this interface
|
|
19
|
+
*/
|
|
20
|
+
export interface WithGenericHeaders {
|
|
21
|
+
extractHeaders(context: ExecutionContext): GenericHeaders;
|
|
22
|
+
}
|
|
23
|
+
export declare const hasGenericHeaders: (x: unknown) => x is WithGenericHeaders;
|
|
10
24
|
/**
|
|
11
25
|
* Base functionality of HTTP or microservice transport
|
|
12
26
|
*/
|
|
13
|
-
export interface ITransport {
|
|
27
|
+
export interface ITransport extends WithGenericHeaders {
|
|
14
28
|
/**
|
|
15
29
|
* @returns protocol in text format
|
|
16
30
|
*/
|
|
@@ -42,7 +56,6 @@ export interface ITransport {
|
|
|
42
56
|
* Modules for register metrics, healthchecks, configs and supporting tools, such as clients
|
|
43
57
|
*/
|
|
44
58
|
modules?(): NestModuleDefinitions;
|
|
45
|
-
getHeaderExtractor(): ProtocolTracingHeadersExtractor;
|
|
46
59
|
}
|
|
47
60
|
/**
|
|
48
61
|
* Primary transport is transport that implements maintenance
|
|
@@ -59,7 +72,7 @@ export interface IPrimaryTransport extends ITransport {
|
|
|
59
72
|
*/
|
|
60
73
|
export interface IMicroserviceTransport extends ITransport {
|
|
61
74
|
/**
|
|
62
|
-
* @
|
|
75
|
+
* @returns options ready to be passed to
|
|
63
76
|
* NestFactory.createMicroservice() or
|
|
64
77
|
* app.connectMicroservice()
|
|
65
78
|
*/
|
|
@@ -103,6 +116,3 @@ export interface IHttpTransport extends IPrimaryTransport {
|
|
|
103
116
|
export declare const isPrimaryTransport: (t: ITransport) => t is IPrimaryTransport;
|
|
104
117
|
export declare const isHttpTransport: (t: ITransport) => t is IHttpTransport;
|
|
105
118
|
export declare const isMicroserviceTransport: (t: ITransport) => t is IMicroserviceTransport;
|
|
106
|
-
export interface ProtocolTracingHeadersExtractor {
|
|
107
|
-
extract(ctx: ExecutionContext): TracingHeaders;
|
|
108
|
-
}
|
package/dist/types/transports.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isMicroserviceTransport = exports.isHttpTransport = exports.isPrimaryTransport = void 0;
|
|
3
|
+
exports.isMicroserviceTransport = exports.isHttpTransport = exports.isPrimaryTransport = exports.hasGenericHeaders = void 0;
|
|
4
|
+
const hasGenericHeaders = (x) => typeof x?.getHeaders === 'function';
|
|
5
|
+
exports.hasGenericHeaders = hasGenericHeaders;
|
|
4
6
|
const isPrimaryTransport = (t) => typeof t.getHealthController === 'function' &&
|
|
5
7
|
typeof t.getMetricsController === 'function';
|
|
6
8
|
exports.isPrimaryTransport = isPrimaryTransport;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transports.js","sourceRoot":"","sources":["../../src/types/transports.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"transports.js","sourceRoot":"","sources":["../../src/types/transports.ts"],"names":[],"mappings":";;;AAmCO,MAAM,iBAAiB,GAAG,CAAC,CAAU,EAA2B,EAAE,CACvE,OAAQ,CAAS,EAAE,UAAU,KAAK,UAAU,CAAC;AADlC,QAAA,iBAAiB,qBACiB;AAgHxC,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/core",
|
|
3
|
-
"version": "5.0.0-next.
|
|
3
|
+
"version": "5.0.0-next.4",
|
|
4
4
|
"description": "Nestjs based microservice chassis",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"@nestjs/core": "^10.0.0",
|
|
25
25
|
"@nestjs/microservices": "^10.0.0",
|
|
26
26
|
"@opentelemetry/api": "1.7.0",
|
|
27
|
+
"@rsdk/actx": "*",
|
|
27
28
|
"@rsdk/autodoc.protocol": "*",
|
|
28
29
|
"@rsdk/common": "*",
|
|
29
30
|
"@rsdk/common.nestjs": "*",
|
|
@@ -32,9 +33,13 @@
|
|
|
32
33
|
"@rsdk/logging": "*",
|
|
33
34
|
"@rsdk/metadata": "*",
|
|
34
35
|
"@rsdk/nest-tools": "*",
|
|
35
|
-
"@rsdk/tracing": "*",
|
|
36
36
|
"reflect-metadata": "^0.1.12 || ^0.2.0",
|
|
37
|
-
"rxjs": "^7.
|
|
37
|
+
"rxjs": "^7.8.1"
|
|
38
38
|
},
|
|
39
|
-
"
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"@opentelemetry/api": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "8f0a0ae9d8d01ef98ce95cb4aa1c28638f376b69"
|
|
40
45
|
}
|
|
@@ -26,7 +26,7 @@ export class GlobalExceptionsFilter implements ExceptionFilter {
|
|
|
26
26
|
@InjectLogger(GlobalExceptionsFilter)
|
|
27
27
|
private readonly logger: ILogger,
|
|
28
28
|
private readonly config: GlobalExceptionsConfig,
|
|
29
|
-
private detector: ProtocolDetector,
|
|
29
|
+
private readonly detector: ProtocolDetector,
|
|
30
30
|
) {}
|
|
31
31
|
|
|
32
32
|
catch(ex: any, host: ArgumentsHost): Observable<any> {
|
|
@@ -80,11 +80,10 @@ export class GlobalExceptionsFilter implements ExceptionFilter {
|
|
|
80
80
|
host: ArgumentsHost,
|
|
81
81
|
protocol: string | undefined,
|
|
82
82
|
): IErrorsFormatter | undefined {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return f;
|
|
83
|
+
return (
|
|
84
|
+
this.formatters.find((x) => x.protocol === protocol) ??
|
|
85
|
+
this.formatters.find((x) => x.protocol === host.getType())
|
|
86
|
+
);
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
private send(host: ArgumentsHost, ex: any): Observable<unknown> {
|
package/src/index.ts
CHANGED
|
@@ -6,8 +6,7 @@ export { Manifest } from './manifest/manifest';
|
|
|
6
6
|
|
|
7
7
|
export { ProtocolDetector } from './transport/protocol.detector';
|
|
8
8
|
|
|
9
|
-
export {
|
|
10
|
-
export { TracingModule, createSpan, Span } from './tracing';
|
|
9
|
+
export { TracingHeaderMappings, Span, NoSpan } from './tracing';
|
|
11
10
|
|
|
12
11
|
export {
|
|
13
12
|
FileSystemCheckOptions,
|
|
@@ -58,4 +57,5 @@ export * from './types';
|
|
|
58
57
|
export * from './app-metadata/decorators';
|
|
59
58
|
|
|
60
59
|
export * from './app-metadata/app-metadata.const';
|
|
61
|
-
|
|
60
|
+
|
|
61
|
+
export { TracingHeaders } from './tracing';
|
|
@@ -6,6 +6,8 @@ import { LoggingConfig } from './logging.config';
|
|
|
6
6
|
|
|
7
7
|
@Module({})
|
|
8
8
|
export class LoggerInitializingModule {
|
|
9
|
+
private static logger = LoggerFactory.create(LoggerInitializingModule);
|
|
10
|
+
|
|
9
11
|
constructor(config: LoggingConfig) {
|
|
10
12
|
const cfg = (): void => {
|
|
11
13
|
LoggerInitializingModule.logger.info(
|
|
@@ -26,6 +28,4 @@ export class LoggerInitializingModule {
|
|
|
26
28
|
config.onUpdate(cfg);
|
|
27
29
|
cfg();
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
private static logger = LoggerFactory.create(LoggerInitializingModule);
|
|
31
31
|
}
|
|
@@ -5,6 +5,8 @@ import { MetricsModuleConfig } from './metrics.config';
|
|
|
5
5
|
|
|
6
6
|
@Module({})
|
|
7
7
|
export class MetricInitializingModule implements OnApplicationBootstrap {
|
|
8
|
+
private static isBootstrapped = false;
|
|
9
|
+
|
|
8
10
|
constructor(private readonly config: MetricsModuleConfig) {}
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -25,6 +27,4 @@ export class MetricInitializingModule implements OnApplicationBootstrap {
|
|
|
25
27
|
|
|
26
28
|
MetricInitializingModule.isBootstrapped = true;
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
private static isBootstrapped = false;
|
|
30
30
|
}
|
package/src/platform.context.ts
CHANGED
|
@@ -39,11 +39,14 @@ import {
|
|
|
39
39
|
* Агрегат для хранения опций приложения, а также методы для конфигурации и запуска приложения
|
|
40
40
|
*/
|
|
41
41
|
export class PlatformContext {
|
|
42
|
-
readonly logger = LoggerFactory.create('App');
|
|
43
|
-
private microservices = new Map<
|
|
42
|
+
private readonly logger = LoggerFactory.create('App');
|
|
43
|
+
private readonly microservices = new Map<
|
|
44
|
+
INestMicroservice,
|
|
45
|
+
IMicroserviceTransport
|
|
46
|
+
>();
|
|
44
47
|
|
|
45
48
|
private readonly httpTransport: IHttpTransport | undefined;
|
|
46
|
-
private aggregator: ContextAggregator;
|
|
49
|
+
private readonly aggregator: ContextAggregator;
|
|
47
50
|
|
|
48
51
|
private _extendedOptions?: PlatformExtendedOptions;
|
|
49
52
|
|
|
@@ -65,8 +68,8 @@ export class PlatformContext {
|
|
|
65
68
|
forceAppName?: string;
|
|
66
69
|
},
|
|
67
70
|
) {
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
this.assertTransportCompatibility(options);
|
|
72
|
+
this.assertPluginCompatibility(options);
|
|
70
73
|
|
|
71
74
|
this.httpTransport = options.transports?.find?.(isHttpTransport);
|
|
72
75
|
this.aggregator = new ContextAggregator(this);
|
|
@@ -76,9 +79,15 @@ export class PlatformContext {
|
|
|
76
79
|
if (this._extendedOptions) {
|
|
77
80
|
return this._extendedOptions;
|
|
78
81
|
}
|
|
82
|
+
|
|
79
83
|
const manifestData = Manifest.getData(this.options.manifestPath);
|
|
80
84
|
const { name, description, version } = manifestData;
|
|
81
85
|
const appName = this.strictnessOptions?.forceAppName ?? name;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* TODO: Вынести в функцию. Да и вообще непонятно, почему мы делаем эту проверку
|
|
89
|
+
* именно в геттере! Это же при создании контекста надо делать?
|
|
90
|
+
*/
|
|
82
91
|
const regexrResult = APP_NAME_PATTERN.exec(name);
|
|
83
92
|
const appScope = regexrResult?.[1] ?? 'test-scope';
|
|
84
93
|
if (this.strictnessOptions?.skipAssertAppName) {
|
|
@@ -102,33 +111,6 @@ export class PlatformContext {
|
|
|
102
111
|
return this._extendedOptions;
|
|
103
112
|
}
|
|
104
113
|
|
|
105
|
-
private static assertPluginCompatability(options: PlatformOptions): void {
|
|
106
|
-
if (!options.plugins) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const protocols = (options.transports ?? []).map((x) => x.getProtocol());
|
|
110
|
-
|
|
111
|
-
for (const plugin of options.plugins) {
|
|
112
|
-
if (!hasSpecifiedTransports(plugin)) {
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (intersection(plugin.forTransports(), protocols).length === 0) {
|
|
117
|
-
throw new NoMatchingTransportException(plugin);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
private static assertTransportCompatability(options: PlatformOptions): void {
|
|
123
|
-
const grouped = groupBy(options.transports, (x) => x.getProtocol());
|
|
124
|
-
|
|
125
|
-
for (const [protocol, implementations] of Object.entries(grouped)) {
|
|
126
|
-
if (implementations.length > 1) {
|
|
127
|
-
throw new DuplicateProtocolException(protocol, implementations.length);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
114
|
async getRsdkMetadataProvider(): Promise<RsdkMetadataProvider> {
|
|
133
115
|
return await this.aggregator.getRsdkMetadataProvider();
|
|
134
116
|
}
|
|
@@ -263,6 +245,33 @@ export class PlatformContext {
|
|
|
263
245
|
];
|
|
264
246
|
}
|
|
265
247
|
|
|
248
|
+
private assertPluginCompatibility(options: PlatformOptions): void {
|
|
249
|
+
if (!options.plugins) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const protocols = (options.transports ?? []).map((x) => x.getProtocol());
|
|
253
|
+
|
|
254
|
+
for (const plugin of options.plugins) {
|
|
255
|
+
if (!hasSpecifiedTransports(plugin)) {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (intersection(plugin.forTransports(), protocols).length === 0) {
|
|
260
|
+
throw new NoMatchingTransportException(plugin);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private assertTransportCompatibility(options: PlatformOptions): void {
|
|
266
|
+
const grouped = groupBy(options.transports, (x) => x.getProtocol());
|
|
267
|
+
|
|
268
|
+
for (const [protocol, implementations] of Object.entries(grouped)) {
|
|
269
|
+
if (implementations.length > 1) {
|
|
270
|
+
throw new DuplicateProtocolException(protocol, implementations.length);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
266
275
|
private getConfigContext(): Promise<ConfigContext> {
|
|
267
276
|
return this.aggregator.getConfigContext();
|
|
268
277
|
}
|
package/src/platform.module.ts
CHANGED
|
@@ -14,13 +14,16 @@ import type { PlatformAppPlugin, PlatformExtendedOptions } from './types';
|
|
|
14
14
|
import { APP_PLUGINS, APP_TRANSPORTS } from './types';
|
|
15
15
|
|
|
16
16
|
export class PlatformModule implements NestModule {
|
|
17
|
+
constructor(@Inject(APP_PLUGINS) private plugins: Set<PlatformAppPlugin>) {}
|
|
18
|
+
|
|
17
19
|
static forRoot(options: PlatformExtendedOptions): DynamicModule {
|
|
18
20
|
const imports: (DynamicModule | Constructor)[] = [
|
|
19
21
|
/**
|
|
20
|
-
* Последовательность принципиально важна так как в этом модуле происходит
|
|
22
|
+
* Последовательность принципиально важна так как в этом модуле происходит
|
|
23
|
+
* инициализация глобального асинхронного контекста (AsyncLocalStorage)
|
|
21
24
|
*/
|
|
22
25
|
AsyncContextModule,
|
|
23
|
-
TracingModule.forRoot(),
|
|
26
|
+
TracingModule.forRoot(options),
|
|
24
27
|
|
|
25
28
|
// Plugins
|
|
26
29
|
PlatformPluginModule.forOptions(options),
|
|
@@ -30,10 +33,10 @@ export class PlatformModule implements NestModule {
|
|
|
30
33
|
PlatformConfigModule.forRoot(options),
|
|
31
34
|
LoggerInitializingModule,
|
|
32
35
|
...(options.modules ?? []),
|
|
36
|
+
PlatformTransportModule.forOptions(options),
|
|
33
37
|
];
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
const exportingProviders = [
|
|
39
|
+
const providers = [
|
|
37
40
|
{
|
|
38
41
|
provide: APP_PLUGINS,
|
|
39
42
|
useValue: new Set(options.plugins),
|
|
@@ -48,13 +51,11 @@ export class PlatformModule implements NestModule {
|
|
|
48
51
|
module: PlatformModule,
|
|
49
52
|
imports,
|
|
50
53
|
global: true,
|
|
51
|
-
providers
|
|
52
|
-
exports:
|
|
54
|
+
providers,
|
|
55
|
+
exports: providers,
|
|
53
56
|
};
|
|
54
57
|
}
|
|
55
58
|
|
|
56
|
-
constructor(@Inject(APP_PLUGINS) private plugins: Set<PlatformAppPlugin>) {}
|
|
57
|
-
|
|
58
59
|
configure(consumer: MiddlewareConsumer): void {
|
|
59
60
|
for (const plugin of this.plugins) {
|
|
60
61
|
plugin?.configureMiddleware?.(consumer);
|
package/src/tracing/constants.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TracingOptions } from './tracing.module';
|
|
2
|
+
import type { TracingHeaderMappings } from './types';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Header mappings injection token
|
|
6
|
+
*/
|
|
7
|
+
export const HEADER_MAPPINGS = Symbol('HEADER_MAPPINGS');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Default mappings for tracing headers
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_TRACING_HEADERS: TracingHeaderMappings[] = [
|
|
13
|
+
['requestId', 'X-Request-Id', 'X-Requestid'],
|
|
14
|
+
];
|
|
8
15
|
|
|
9
16
|
/**
|
|
10
|
-
*
|
|
17
|
+
* Default tracing options
|
|
11
18
|
*/
|
|
12
|
-
export const
|
|
13
|
-
export const MAX_BYTES = new Size(100, 'kb');
|
|
19
|
+
export const DEFAULT_TRACING_OPTIONS: TracingOptions = { includeDefault: true };
|
package/src/tracing/index.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SetMetadata } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { OTEL_METADATA } from '../opentelemetry.metadata';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* OTELWrapper will ignore classes and methods annotated with
|
|
7
|
+
* this decorator.
|
|
8
|
+
*/
|
|
9
|
+
export const NoSpan = (): MethodDecorator =>
|
|
10
|
+
SetMetadata(OTEL_METADATA.NO_SPAN, true);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { MetadataScanner } from '@nestjs/core';
|
|
2
2
|
|
|
3
|
-
import { SymbolKeyDecorationException } from '
|
|
4
|
-
import {
|
|
3
|
+
import { SymbolKeyDecorationException } from '../../../exceptions';
|
|
4
|
+
import { OpentelemetryWrapper } from '../opentelemetry.wrapper';
|
|
5
5
|
|
|
6
6
|
const metadataScanner = new MetadataScanner();
|
|
7
7
|
|
|
8
|
+
const wrapper = new OpentelemetryWrapper();
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Explicitly adds instrumentation.
|
|
10
12
|
* Use for classes that you instantiate manually.
|
|
@@ -20,15 +22,17 @@ export const Span = (): MethodDecorator & ClassDecorator =>
|
|
|
20
22
|
if (typeof methodName === 'symbol') {
|
|
21
23
|
throw new SymbolKeyDecorationException();
|
|
22
24
|
}
|
|
25
|
+
|
|
23
26
|
if (methodName && descriptor) {
|
|
24
|
-
|
|
27
|
+
wrapper.wrap(target, descriptor.value, descriptor);
|
|
25
28
|
return;
|
|
26
29
|
}
|
|
30
|
+
|
|
27
31
|
const prototype = (target as any).prototype ?? target;
|
|
28
32
|
|
|
29
33
|
for (const name of metadataScanner.getAllMethodNames(prototype)) {
|
|
30
34
|
if (name) {
|
|
31
|
-
|
|
35
|
+
wrapper.wrap(prototype, prototype[name]);
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './decorators';
|