@rsdk/http.server 4.2.4 → 4.3.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/http-adapter/abstract-rsdk-http-adapter.d.ts +2 -1
- package/dist/http-adapter/abstract-rsdk-http-adapter.js +10 -0
- package/dist/http-adapter/abstract-rsdk-http-adapter.js.map +1 -1
- package/dist/http.headers.d.ts +23 -0
- package/dist/http.headers.js +43 -0
- package/dist/http.headers.js.map +1 -0
- package/dist/http.tracing-extractor.d.ts +6 -0
- package/dist/http.tracing-extractor.js +13 -0
- package/dist/http.tracing-extractor.js.map +1 -0
- package/dist/http.transport.d.ts +2 -1
- package/dist/http.transport.js +4 -0
- package/dist/http.transport.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/src/http-adapter/abstract-rsdk-http-adapter.ts +17 -1
- package/src/http.headers.ts +65 -0
- package/src/http.tracing-extractor.ts +16 -0
- package/src/http.transport.ts +6 -0
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.3.0-next.0](https://github.com/R-Vision/rsdk/compare/v4.2.5-next.0...v4.3.0-next.0) (2024-03-19)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* reworked cli system ([745ebf5](https://github.com/R-Vision/rsdk/commit/745ebf53635de135a4a9083f47ce833efe2d4411))
|
|
11
|
+
|
|
12
|
+
## [4.2.5-next.0](https://github.com/R-Vision/rsdk/compare/v4.2.4...v4.2.5-next.0) (2024-03-04)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @rsdk/http.server
|
|
15
|
+
|
|
6
16
|
## [4.2.4](https://github.com/R-Vision/rsdk/compare/v4.2.3...v4.2.4) (2024-02-28)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @rsdk/http.server
|
|
@@ -3,10 +3,11 @@ import type { Controller, INestApplication } from '@nestjs/common/interfaces';
|
|
|
3
3
|
import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
4
4
|
import type { AbstractHttpAdapter } from '@nestjs/core';
|
|
5
5
|
import type { Constructor, DeepPartial } from '@rsdk/common';
|
|
6
|
-
import type { ConfigContext, HttpOptions, IErrorsFormatter, IErrorsSender, IErrorsTransformer, IHttpTransport, NestModuleDefinitions } from '@rsdk/core';
|
|
6
|
+
import type { ConfigContext, HttpOptions, IErrorsFormatter, IErrorsSender, IErrorsTransformer, IHttpTransport, NestModuleDefinitions, ProtocolTracingHeadersExtractor } from '@rsdk/core';
|
|
7
7
|
import { HttpConfig } from '../http.config';
|
|
8
8
|
import type { SwaggerOptions } from '../http.transport';
|
|
9
9
|
export declare abstract class AbstractRsdkHttpTransport implements IHttpTransport {
|
|
10
|
+
getHeaderExtractor(): ProtocolTracingHeadersExtractor;
|
|
10
11
|
abstract readonly options?: {
|
|
11
12
|
cors?: CorsOptions;
|
|
12
13
|
globalPrefix?: string;
|
|
@@ -9,8 +9,18 @@ const node_fs_1 = require("node:fs");
|
|
|
9
9
|
const controllers_1 = require("../controllers");
|
|
10
10
|
const error_handling_1 = require("../error-handling");
|
|
11
11
|
const http_config_1 = require("../http.config");
|
|
12
|
+
const http_headers_1 = require("../http.headers");
|
|
12
13
|
const http_logger_interceptor_1 = require("../http-logger.interceptor");
|
|
13
14
|
class AbstractRsdkHttpTransport {
|
|
15
|
+
getHeaderExtractor() {
|
|
16
|
+
return {
|
|
17
|
+
extract(executionContext) {
|
|
18
|
+
// TODO:
|
|
19
|
+
const req = executionContext.switchToHttp().getRequest();
|
|
20
|
+
return new http_headers_1.HttpHeaders(req.headers).getTracingHeaders(req);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
14
24
|
matchByContext(ctx) {
|
|
15
25
|
return ctx.getType() === 'http';
|
|
16
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-rsdk-http-adapter.js","sourceRoot":"","sources":["../../src/http-adapter/abstract-rsdk-http-adapter.ts"],"names":[],"mappings":";;;AAIA,uCAA+C;AAC/C,6CAAgD;AAChD,4EAAmG;
|
|
1
|
+
{"version":3,"file":"abstract-rsdk-http-adapter.js","sourceRoot":"","sources":["../../src/http-adapter/abstract-rsdk-http-adapter.ts"],"names":[],"mappings":";;;AAIA,uCAA+C;AAC/C,6CAAgD;AAChD,4EAAmG;AAYnG,qCAAoE;AAEpE,qCAAwC;AAExC,gDAA6E;AAC7E,sDAI2B;AAC3B,gDAA4C;AAC5C,kDAA8C;AAE9C,wEAAmE;AAEnE,MAAsB,yBAAyB;IAC7C,kBAAkB;QAChB,OAAO;YACL,OAAO,CAAC,gBAA+B;gBACrC,QAAQ;gBACR,MAAM,GAAG,GAAG,gBAAgB,CAAC,YAAY,EAAE,CAAC,UAAU,EAAO,CAAC;gBAE9D,OAAO,IAAI,0BAAW,CACpB,GAAG,CAAC,OAAiC,CACtC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;YAC3B,CAAC;SACF,CAAC;IACJ,CAAC;IAqBD,cAAc,CAAC,GAAqB;QAClC,OAAO,GAAG,CAAC,OAAO,EAAE,KAAK,MAAM,CAAC;IAClC,CAAC;IAED,OAAO;QACL,OAAO;YACL;gBACE,MAAM,EAAE,yBAAgC;gBACxC,SAAS,EAAE;oBACT;wBACE,OAAO,EAAE,sBAAe;wBACxB,QAAQ,EAAE,+CAAqB;qBAChC;iBACF;aACF;SACF,CAAC;IACJ,CAAC;IAED,kBAAkB;QAChB,OAAO,IAAI,oCAAmB,EAAE,CAAC;IACnC,CAAC;IAED,eAAe;QACb,OAAO,IAAI,iCAAgB,EAAE,CAAC;IAChC,CAAC;IAED,oBAAoB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O,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC;YAE9B,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,uBAAa,CAAC,cAAc,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;YAE9D,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;gBAClB,IAAA,uBAAa,EAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YACpD,CAAC;YAED,IAAI,SAAS,EAAE,CAAC;gBACd,uBAAa,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,UAAU,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;IACH,CAAC;CAGF;AA5HD,8DA4HC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { MaybeReadonlyArray } from '@rsdk/common.node';
|
|
2
|
+
import { TracingHeaders } from '@rsdk/core/dist/tracing/types';
|
|
3
|
+
/**
|
|
4
|
+
* @description хелпер для нормализованного извлечения заголовков из http запроса
|
|
5
|
+
*/
|
|
6
|
+
export declare class HttpHeaders {
|
|
7
|
+
private headers;
|
|
8
|
+
constructor(headers: Record<string, string>);
|
|
9
|
+
get<K extends string>(key: MaybeReadonlyArray<K>): Record<K, string | undefined>;
|
|
10
|
+
get(key: string): string | undefined;
|
|
11
|
+
getTracingHeaders(req: any): TracingHeaders;
|
|
12
|
+
getHeaders(req: any): {
|
|
13
|
+
'x-b3-parentspanid'?: string;
|
|
14
|
+
'x-b3-spanid'?: string;
|
|
15
|
+
'x-b3-traceid'?: string;
|
|
16
|
+
attributes: {
|
|
17
|
+
[p: string]: any;
|
|
18
|
+
};
|
|
19
|
+
'x-requestid'?: string;
|
|
20
|
+
spanName: string;
|
|
21
|
+
};
|
|
22
|
+
private normalizedHeaders;
|
|
23
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpHeaders = void 0;
|
|
4
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
5
|
+
const types_1 = require("@rsdk/core/dist/tracing/types");
|
|
6
|
+
/**
|
|
7
|
+
* @description хелпер для нормализованного извлечения заголовков из http запроса
|
|
8
|
+
*/
|
|
9
|
+
class HttpHeaders {
|
|
10
|
+
headers;
|
|
11
|
+
constructor(headers) {
|
|
12
|
+
this.headers = headers;
|
|
13
|
+
this.normalizedHeaders = Object.fromEntries(Object.entries(headers).map(([k, v]) => [k.toLowerCase(), v]));
|
|
14
|
+
}
|
|
15
|
+
get(key) {
|
|
16
|
+
if (Array.isArray(key)) {
|
|
17
|
+
return Object.fromEntries(key.map((k) => [k, this.get(k)]));
|
|
18
|
+
}
|
|
19
|
+
return this.normalizedHeaders[key.toLowerCase()];
|
|
20
|
+
}
|
|
21
|
+
getTracingHeaders(req) {
|
|
22
|
+
return new types_1.TracingHeaders(this.getHeaders(req));
|
|
23
|
+
}
|
|
24
|
+
getHeaders(req) {
|
|
25
|
+
const httpRoute = req.route?.path ||
|
|
26
|
+
req.routeOptions?.url ||
|
|
27
|
+
req.routerPath ||
|
|
28
|
+
req.originalUrl;
|
|
29
|
+
const headers = this.get(types_1.tracingHeaders);
|
|
30
|
+
return {
|
|
31
|
+
spanName: req.method + ' ' + httpRoute,
|
|
32
|
+
...headers,
|
|
33
|
+
attributes: {
|
|
34
|
+
[semantic_conventions_1.SemanticAttributes.HTTP_METHOD]: req.method,
|
|
35
|
+
[semantic_conventions_1.SemanticAttributes.HTTP_ROUTE]: httpRoute,
|
|
36
|
+
[semantic_conventions_1.SemanticAttributes.HTTP_URL]: req.originalUrl || req.url,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
normalizedHeaders;
|
|
41
|
+
}
|
|
42
|
+
exports.HttpHeaders = HttpHeaders;
|
|
43
|
+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,CAAC,MAAO,GAAG,GAAG,GAAG,SAAS;YACvC,GAAG,OAAO;YACV,UAAU,EAAE;gBACV,CAAC,yCAAkB,CAAC,WAAW,CAAC,EAAE,GAAG,CAAC,MAAO;gBAC7C,CAAC,yCAAkB,CAAC,UAAU,CAAC,EAAE,SAAS;gBAC1C,CAAC,yCAAkB,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,GAAG;aAC1D;SACF,CAAC;IACJ,CAAC;IAEO,iBAAiB,CAAyB;CACnD;AArDD,kCAqDC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ArgumentsHost } from '@nestjs/common';
|
|
2
|
+
import type { ProtocolTracingHeadersExtractor } from '@rsdk/core';
|
|
3
|
+
import type { TracingHeaders } from '@rsdk/core/dist/tracing/types';
|
|
4
|
+
export declare class HttpTracingExtractor implements ProtocolTracingHeadersExtractor {
|
|
5
|
+
extract(executionContext: ArgumentsHost): TracingHeaders;
|
|
6
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpTracingExtractor = void 0;
|
|
4
|
+
const http_headers_1 = require("./http.headers");
|
|
5
|
+
class HttpTracingExtractor {
|
|
6
|
+
extract(executionContext) {
|
|
7
|
+
// TODO:
|
|
8
|
+
const req = executionContext.switchToHttp().getRequest();
|
|
9
|
+
return new http_headers_1.HttpHeaders(req.headers).getTracingHeaders(req);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.HttpTracingExtractor = HttpTracingExtractor;
|
|
13
|
+
//# sourceMappingURL=http.tracing-extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.tracing-extractor.js","sourceRoot":"","sources":["../src/http.tracing-extractor.ts"],"names":[],"mappings":";;;AAIA,iDAA6C;AAE7C,MAAa,oBAAoB;IAC/B,OAAO,CAAC,gBAA+B;QACrC,QAAQ;QACR,MAAM,GAAG,GAAG,gBAAgB,CAAC,YAAY,EAAE,CAAC,UAAU,EAAO,CAAC;QAE9D,OAAO,IAAI,0BAAW,CACpB,GAAG,CAAC,OAAiC,CACtC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;CACF;AATD,oDASC"}
|
package/dist/http.transport.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-option
|
|
|
4
4
|
import type { AbstractHttpAdapter } from '@nestjs/core';
|
|
5
5
|
import { DocumentBuilder as OriginalDocumentBuilder } from '@nestjs/swagger';
|
|
6
6
|
import type { Constructor, DeepPartial } from '@rsdk/common';
|
|
7
|
-
import type { ConfigContext, HttpOptions, IErrorsFormatter, IErrorsSender, IErrorsTransformer, IHttpTransport } from '@rsdk/core';
|
|
7
|
+
import type { ConfigContext, HttpOptions, IErrorsFormatter, IErrorsSender, IErrorsTransformer, IHttpTransport, ProtocolTracingHeadersExtractor } from '@rsdk/core';
|
|
8
8
|
export interface ParsersConfig {
|
|
9
9
|
body: {
|
|
10
10
|
json: boolean;
|
|
@@ -30,6 +30,7 @@ export interface HttpTransportOptions {
|
|
|
30
30
|
export declare class HttpTransport implements IHttpTransport {
|
|
31
31
|
private readonly adapter;
|
|
32
32
|
private readonly options;
|
|
33
|
+
getHeaderExtractor(): ProtocolTracingHeadersExtractor;
|
|
33
34
|
constructor(adapter: AbstractHttpAdapter, options?: HttpTransportOptions);
|
|
34
35
|
matchByContext(ctx: ExecutionContext): boolean;
|
|
35
36
|
getProtocol(): string;
|
package/dist/http.transport.js
CHANGED
|
@@ -13,12 +13,16 @@ const node_fs_1 = require("node:fs");
|
|
|
13
13
|
const controllers_1 = require("./controllers");
|
|
14
14
|
const error_handling_1 = require("./error-handling");
|
|
15
15
|
const http_config_1 = require("./http.config");
|
|
16
|
+
const http_tracing_extractor_1 = require("./http.tracing-extractor");
|
|
16
17
|
/**
|
|
17
18
|
* @deprecated use concrete implementation from @rsdk/http.server.<implementation>, example: @rsdk/http.server.{express,fastify}
|
|
18
19
|
*/
|
|
19
20
|
class HttpTransport {
|
|
20
21
|
adapter;
|
|
21
22
|
options;
|
|
23
|
+
getHeaderExtractor() {
|
|
24
|
+
return new http_tracing_extractor_1.HttpTracingExtractor();
|
|
25
|
+
}
|
|
22
26
|
constructor(adapter, options = {}) {
|
|
23
27
|
this.adapter = adapter;
|
|
24
28
|
this.options = options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.transport.js","sourceRoot":"","sources":["../src/http.transport.ts"],"names":[],"mappings":";;;;;;AACA,2CAA+C;AAI/C,6CAGyB;
|
|
1
|
+
{"version":3,"file":"http.transport.js","sourceRoot":"","sources":["../src/http.transport.ts"],"names":[],"mappings":";;;;;;AACA,2CAA+C;AAI/C,6CAGyB;AAWzB,qCAAoE;AACpE,6CAA+C;AAC/C,kEAAyC;AACzC,qCAAwC;AAExC,+CAA4E;AAC5E,qDAI0B;AAC1B,+CAA2C;AAC3C,qEAAgE;AA8ChE;;GAEG;AACH,MAAa,aAAa;IAML;IACA;IANnB,kBAAkB;QAChB,OAAO,IAAI,6CAAoB,EAAE,CAAC;IACpC,CAAC;IAED,YACmB,OAA4B,EAC5B,UAAgC,EAAE;QADlC,YAAO,GAAP,OAAO,CAAqB;QAC5B,YAAO,GAAP,OAAO,CAA2B;IAClD,CAAC;IAEJ,cAAc,CAAC,GAAqB;QAClC,OAAO,GAAG,CAAC,OAAO,EAAE,KAAK,MAAM,CAAC;IAClC,CAAC;IAED,WAAW;QACT,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,kBAAkB;QAChB,OAAO,IAAI,oCAAmB,EAAE,CAAC;IACnC,CAAC;IAED,eAAe;QACb,OAAO,IAAI,iCAAgB,EAAE,CAAC;IAChC,CAAC;IAED,oBAAoB;QAClB,OAAO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a,CAAC,OAAO,CAAC,wBAAU,CAAC,CAAC;QAEzD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACxB,CAAC;CACF;AAtHD,sCAsHC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,8 +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.AbstractRsdkHttpTransport = void 0;
|
|
17
|
+
exports.HttpHeaders = exports.AbstractRsdkHttpTransport = void 0;
|
|
18
18
|
var abstract_rsdk_http_adapter_1 = require("./http-adapter/abstract-rsdk-http-adapter");
|
|
19
19
|
Object.defineProperty(exports, "AbstractRsdkHttpTransport", { enumerable: true, get: function () { return abstract_rsdk_http_adapter_1.AbstractRsdkHttpTransport; } });
|
|
20
20
|
__exportStar(require("./http.transport"), exports);
|
|
21
|
+
var http_headers_1 = require("./http.headers");
|
|
22
|
+
Object.defineProperty(exports, "HttpHeaders", { enumerable: true, get: function () { return http_headers_1.HttpHeaders; } });
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wFAAsF;AAA7E,uIAAA,yBAAyB,OAAA;AAElC,mDAAiC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,wFAAsF;AAA7E,uIAAA,yBAAyB,OAAA;AAElC,mDAAiC;AACjC,+CAA6C;AAApC,2GAAA,WAAW,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/http.server",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0-next.0",
|
|
4
4
|
"description": "HTTP transport for rsdk apps (needs some of HTTP adapters)",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
"@nestjs/common": "^10.0.0",
|
|
15
15
|
"@nestjs/core": "^10.0.0",
|
|
16
16
|
"@nestjs/swagger": "^7.0.0",
|
|
17
|
-
"@
|
|
18
|
-
"@rsdk/
|
|
19
|
-
"@rsdk/
|
|
17
|
+
"@opentelemetry/semantic-conventions": "1.18.1",
|
|
18
|
+
"@rsdk/common": "^4.3.0-next.0",
|
|
19
|
+
"@rsdk/core": "^4.3.0-next.0",
|
|
20
|
+
"@rsdk/logging": "^4.3.0-next.0",
|
|
20
21
|
"body-parser": "^1.20.1",
|
|
21
22
|
"cookie-parser": "^1.4.6",
|
|
22
|
-
"reflect-metadata": "^0.1.
|
|
23
|
+
"reflect-metadata": "^0.1.12 || ^0.2.0",
|
|
23
24
|
"rxjs": "^7.8.1"
|
|
24
25
|
},
|
|
25
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "68619cc6fc60db01568eede7df182d9882e857dd"
|
|
26
27
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExecutionContext } from '@nestjs/common';
|
|
1
|
+
import type { ArgumentsHost, ExecutionContext } from '@nestjs/common';
|
|
2
2
|
import type { Controller, INestApplication } from '@nestjs/common/interfaces';
|
|
3
3
|
import type { CorsOptions } from '@nestjs/common/interfaces/external/cors-options.interface';
|
|
4
4
|
import type { AbstractHttpAdapter } from '@nestjs/core';
|
|
@@ -14,8 +14,10 @@ import type {
|
|
|
14
14
|
IErrorsTransformer,
|
|
15
15
|
IHttpTransport,
|
|
16
16
|
NestModuleDefinitions,
|
|
17
|
+
ProtocolTracingHeadersExtractor,
|
|
17
18
|
} from '@rsdk/core';
|
|
18
19
|
import { APP_DESCRIPTION, APP_NAME, APP_VERSION } from '@rsdk/core';
|
|
20
|
+
import type { TracingHeaders } from '@rsdk/core/dist/tracing/types';
|
|
19
21
|
import { writeFileSync } from 'node:fs';
|
|
20
22
|
|
|
21
23
|
import { HealthHttpController, MetricsHttpController } from '../controllers';
|
|
@@ -25,10 +27,24 @@ import {
|
|
|
25
27
|
HttpErrorsTransformer,
|
|
26
28
|
} from '../error-handling';
|
|
27
29
|
import { HttpConfig } from '../http.config';
|
|
30
|
+
import { HttpHeaders } from '../http.headers';
|
|
28
31
|
import type { SwaggerOptions } from '../http.transport';
|
|
29
32
|
import { HttpLoggerInterceptor } from '../http-logger.interceptor';
|
|
30
33
|
|
|
31
34
|
export abstract class AbstractRsdkHttpTransport implements IHttpTransport {
|
|
35
|
+
getHeaderExtractor(): ProtocolTracingHeadersExtractor {
|
|
36
|
+
return {
|
|
37
|
+
extract(executionContext: ArgumentsHost): TracingHeaders {
|
|
38
|
+
// TODO:
|
|
39
|
+
const req = executionContext.switchToHttp().getRequest<any>();
|
|
40
|
+
|
|
41
|
+
return new HttpHeaders(
|
|
42
|
+
req.headers as Record<string, string>,
|
|
43
|
+
).getTracingHeaders(req);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
32
48
|
abstract readonly options?: {
|
|
33
49
|
// CORS middleware options
|
|
34
50
|
cors?: CorsOptions;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
|
|
2
|
+
import type { MaybeReadonlyArray } from '@rsdk/common.node';
|
|
3
|
+
import {
|
|
4
|
+
type Headers,
|
|
5
|
+
TracingHeaders,
|
|
6
|
+
tracingHeaders,
|
|
7
|
+
} from '@rsdk/core/dist/tracing/types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @description хелпер для нормализованного извлечения заголовков из http запроса
|
|
11
|
+
*/
|
|
12
|
+
export class HttpHeaders {
|
|
13
|
+
constructor(private headers: Record<string, string>) {
|
|
14
|
+
this.normalizedHeaders = Object.fromEntries(
|
|
15
|
+
Object.entries(headers).map(([k, v]) => [k.toLowerCase(), v]),
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get<K extends string>(
|
|
20
|
+
key: MaybeReadonlyArray<K>,
|
|
21
|
+
): Record<K, string | undefined>;
|
|
22
|
+
|
|
23
|
+
get(key: string): string | undefined;
|
|
24
|
+
|
|
25
|
+
get(
|
|
26
|
+
key: string | MaybeReadonlyArray<string>,
|
|
27
|
+
): Record<string, string | undefined> | string | undefined {
|
|
28
|
+
if (Array.isArray(key)) {
|
|
29
|
+
return Object.fromEntries(key.map((k) => [k, this.get(k)]));
|
|
30
|
+
}
|
|
31
|
+
return this.normalizedHeaders[(key as string).toLowerCase()];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getTracingHeaders(req: any): TracingHeaders {
|
|
35
|
+
return new TracingHeaders(this.getHeaders(req));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getHeaders(req: any): {
|
|
39
|
+
'x-b3-parentspanid'?: string;
|
|
40
|
+
'x-b3-spanid'?: string;
|
|
41
|
+
'x-b3-traceid'?: string;
|
|
42
|
+
attributes: { [p: string]: any };
|
|
43
|
+
'x-requestid'?: string;
|
|
44
|
+
spanName: string;
|
|
45
|
+
} {
|
|
46
|
+
const httpRoute =
|
|
47
|
+
req.route?.path ||
|
|
48
|
+
req.routeOptions?.url ||
|
|
49
|
+
req.routerPath ||
|
|
50
|
+
req.originalUrl;
|
|
51
|
+
const headers = this.get(tracingHeaders) as Partial<Headers>;
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
spanName: req.method! + ' ' + httpRoute,
|
|
55
|
+
...headers,
|
|
56
|
+
attributes: {
|
|
57
|
+
[SemanticAttributes.HTTP_METHOD]: req.method!,
|
|
58
|
+
[SemanticAttributes.HTTP_ROUTE]: httpRoute,
|
|
59
|
+
[SemanticAttributes.HTTP_URL]: req.originalUrl || req.url,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private normalizedHeaders: Record<string, string>;
|
|
65
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ArgumentsHost } from '@nestjs/common';
|
|
2
|
+
import type { ProtocolTracingHeadersExtractor } from '@rsdk/core';
|
|
3
|
+
import type { TracingHeaders } from '@rsdk/core/dist/tracing/types';
|
|
4
|
+
|
|
5
|
+
import { HttpHeaders } from './http.headers';
|
|
6
|
+
|
|
7
|
+
export class HttpTracingExtractor implements ProtocolTracingHeadersExtractor {
|
|
8
|
+
extract(executionContext: ArgumentsHost): TracingHeaders {
|
|
9
|
+
// TODO:
|
|
10
|
+
const req = executionContext.switchToHttp().getRequest<any>();
|
|
11
|
+
|
|
12
|
+
return new HttpHeaders(
|
|
13
|
+
req.headers as Record<string, string>,
|
|
14
|
+
).getTracingHeaders(req);
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/http.transport.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
IErrorsSender,
|
|
16
16
|
IErrorsTransformer,
|
|
17
17
|
IHttpTransport,
|
|
18
|
+
ProtocolTracingHeadersExtractor,
|
|
18
19
|
} from '@rsdk/core';
|
|
19
20
|
import { APP_DESCRIPTION, APP_NAME, APP_VERSION } from '@rsdk/core';
|
|
20
21
|
import { json, urlencoded } from 'body-parser';
|
|
@@ -28,6 +29,7 @@ import {
|
|
|
28
29
|
HttpErrorsTransformer,
|
|
29
30
|
} from './error-handling';
|
|
30
31
|
import { HttpConfig } from './http.config';
|
|
32
|
+
import { HttpTracingExtractor } from './http.tracing-extractor';
|
|
31
33
|
|
|
32
34
|
export interface ParsersConfig {
|
|
33
35
|
body: {
|
|
@@ -77,6 +79,10 @@ export interface HttpTransportOptions {
|
|
|
77
79
|
* @deprecated use concrete implementation from @rsdk/http.server.<implementation>, example: @rsdk/http.server.{express,fastify}
|
|
78
80
|
*/
|
|
79
81
|
export class HttpTransport implements IHttpTransport {
|
|
82
|
+
getHeaderExtractor(): ProtocolTracingHeadersExtractor {
|
|
83
|
+
return new HttpTracingExtractor();
|
|
84
|
+
}
|
|
85
|
+
|
|
80
86
|
constructor(
|
|
81
87
|
private readonly adapter: AbstractHttpAdapter,
|
|
82
88
|
private readonly options: HttpTransportOptions = {},
|
package/src/index.ts
CHANGED