@rsdk/grpc.server 3.7.0 → 3.8.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 CHANGED
@@ -3,6 +3,12 @@
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
+ ## [3.8.0](https://github.com/R-Vision/rsdk/compare/v3.7.0...v3.8.0) (2023-11-15)
7
+
8
+ ### Features
9
+
10
+ * added configuration for request logging and move to trace level all request logging ([#158](https://github.com/R-Vision/rsdk/issues/158)) ([0304672](https://github.com/R-Vision/rsdk/commit/0304672c112fd626642a2d44b0384fbf188e71b4))
11
+
6
12
  ## [3.7.0](https://github.com/R-Vision/rsdk/compare/v3.6.1...v3.7.0) (2023-11-15)
7
13
 
8
14
  ### Features
@@ -1,8 +1,10 @@
1
1
  import type { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common/interfaces';
2
2
  import { ILogger } from '@rsdk/logging';
3
3
  import type { Observable } from 'rxjs';
4
+ import { GRPCConfig } from './grpc.config';
4
5
  export declare class GrpcLoggerInterceptor implements NestInterceptor {
5
6
  private logger;
6
- constructor(logger: ILogger);
7
+ private grpcConfig;
8
+ constructor(logger: ILogger, grpcConfig: GRPCConfig);
7
9
  intercept(context: ExecutionContext, next: CallHandler<any>): Observable<any> | Promise<Observable<any>>;
8
10
  }
@@ -15,45 +15,58 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.GrpcLoggerInterceptor = void 0;
16
16
  const core_1 = require("@rsdk/core");
17
17
  const rxjs_1 = require("rxjs");
18
+ const grpc_config_1 = require("./grpc.config");
18
19
  let GrpcLoggerInterceptor = exports.GrpcLoggerInterceptor = class GrpcLoggerInterceptor {
19
20
  logger;
20
- constructor(logger) {
21
+ grpcConfig;
22
+ constructor(logger, grpcConfig) {
21
23
  this.logger = logger;
24
+ this.grpcConfig = grpcConfig;
22
25
  }
23
26
  intercept(context, next) {
27
+ if (!this.grpcConfig.requestLogging) {
28
+ return next.handle();
29
+ }
24
30
  const isRpc = context.getType() === 'rpc';
25
31
  if (!isRpc) {
26
32
  return next.handle();
27
33
  }
28
34
  const rpc = context.switchToRpc();
29
- const now = Date.now();
35
+ const startDate = Date.now();
30
36
  const rpcContext = rpc.getContext();
31
37
  const serializedCtx = rpcContext?.toJSON?.() ?? rpcContext;
32
38
  const requestForLog = {
33
39
  data: rpc.getData(),
34
40
  ctx: serializedCtx,
35
41
  };
36
- this.logger.debug('received rpc request', {
42
+ this.logger.trace('received rpc request', {
37
43
  request: requestForLog,
38
- timestamp: now,
44
+ timestamp: startDate,
39
45
  });
40
- return next.handle().pipe((0, rxjs_1.catchError)((err) => {
41
- this.logger.debug('handled rpc request with error', {
46
+ return next.handle().pipe((0, rxjs_1.catchError)((error) => {
47
+ const endDate = Date.now();
48
+ this.logger.trace('handled rpc request with error', {
42
49
  request: requestForLog,
43
- start: now,
44
- end: Date.now() - now,
45
- err,
50
+ startDate,
51
+ endDate,
52
+ duration: endDate - startDate,
53
+ error,
46
54
  });
47
- return (0, rxjs_1.throwError)(() => err);
48
- }), (0, rxjs_1.tap)(() => this.logger.debug('handled rpc request', {
49
- request: requestForLog,
50
- start: now,
51
- end: Date.now() - now,
52
- })));
55
+ return (0, rxjs_1.throwError)(() => error);
56
+ }), (0, rxjs_1.tap)((response) => {
57
+ const endDate = Date.now();
58
+ this.logger.trace('handled rpc request', {
59
+ request: requestForLog,
60
+ startDate,
61
+ endDate,
62
+ duration: endDate - startDate,
63
+ response,
64
+ });
65
+ }));
53
66
  }
54
67
  };
55
68
  exports.GrpcLoggerInterceptor = GrpcLoggerInterceptor = __decorate([
56
69
  __param(0, (0, core_1.InjectLogger)(GrpcLoggerInterceptor)),
57
- __metadata("design:paramtypes", [Object])
70
+ __metadata("design:paramtypes", [Object, grpc_config_1.GRPCConfig])
58
71
  ], GrpcLoggerInterceptor);
59
72
  //# sourceMappingURL=grpc-logger.interceptor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"grpc-logger.interceptor.js","sourceRoot":"","sources":["../src/grpc-logger.interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,qCAA0C;AAG1C,+BAAmD;AAEnD,IAAa,qBAAqB,mCAAlC,MAAa,qBAAqB;IACyB;IAAzD,YAAyD,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;IAE5E,SAAS,CACP,OAAyB,EACzB,IAAsB;QAEtB,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,EAAE,KAAK,KAAK,CAAC;QAC1C,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;SACtB;QAED,MAAM,GAAG,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;QAElC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,EAAE,CAAC;QACpC,MAAM,aAAa,GAAG,UAAU,EAAE,MAAM,EAAE,EAAE,IAAI,UAAU,CAAC;QAC3D,MAAM,aAAa,GAAG;YACpB,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE;YACnB,GAAG,EAAE,aAAa;SACnB,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE;YACxC,OAAO,EAAE,aAAa;YACtB,SAAS,EAAE,GAAG;SACf,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CACvB,IAAA,iBAAU,EAAC,CAAC,GAAG,EAAE,EAAE;YACjB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,EAAE;gBAClD,OAAO,EAAE,aAAa;gBACtB,KAAK,EAAE,GAAG;gBACV,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG;gBACrB,GAAG;aACJ,CAAC,CAAC;YACH,OAAO,IAAA,iBAAU,EAAC,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M,aAAa,GAAG;YACpB,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE;YACnB,GAAG,EAAE,aAAa;SACnB,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE;YACxC,OAAO,EAAE,aAAa;YACtB,SAAS,EAAE,SAAS;SACrB,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CACvB,IAAA,iBAAU,EAAC,CAAC,KAAK,EAAE,EAAE;YACnB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAE3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,EAAE;gBAClD,OAAO,EAAE,aAAa;gBACtB,SAAS;gBACT,OAAO;gBACP,QAAQ,EAAE,OAAO,GAAG,SAAS;gBAC7B,KAAK;aACN,CAAC,CAAC;YACH,OAAO,IAAA,iBAAU,EAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC,CAAC,EACF,IAAA,UAAG,EAAC,CAAC,QAAQ,EAAE,EAAE;YACf,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAE3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,EAAE;gBACvC,OAAO,EAAE,aAAa;gBACtB,SAAS;gBACT,OAAO;gBACP,QAAQ,EAAE,OAAO,GAAG,SAAS;gBAC7B,QAAQ;aACT,CAAC,CAAC;QACL,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAA;gCA3DY,qBAAqB;IAE7B,WAAA,IAAA,mBAAY,EAAC,qBAAqB,CAAC,CAAA;6CAChB,wBAAU;GAHrB,qBAAqB,CA2DjC"}
@@ -3,4 +3,5 @@ export declare class GRPCConfig extends Config {
3
3
  readonly address: string;
4
4
  readonly maxRecv: number;
5
5
  readonly maxSend: number;
6
+ readonly requestLogging: boolean;
6
7
  }
@@ -18,6 +18,7 @@ let GRPCConfig = exports.GRPCConfig = class GRPCConfig extends core_1.Config {
18
18
  address;
19
19
  maxRecv;
20
20
  maxSend;
21
+ requestLogging;
21
22
  };
22
23
  __decorate([
23
24
  (0, core_1.Property)('GRPC_ADDRESS', new grpc_common_1.GrpcAddressParser(), {
@@ -43,6 +44,13 @@ __decorate([
43
44
  }),
44
45
  __metadata("design:type", Number)
45
46
  ], GRPCConfig.prototype, "maxSend", void 0);
47
+ __decorate([
48
+ (0, core_1.Property)('GRPC_REQUEST_LOGGING', new core_1.BoolParser(), {
49
+ defaultValue: false,
50
+ description: 'Enable trace logging all requests',
51
+ }),
52
+ __metadata("design:type", Boolean)
53
+ ], GRPCConfig.prototype, "requestLogging", void 0);
46
54
  exports.GRPCConfig = GRPCConfig = __decorate([
47
55
  (0, core_1.ConfigSection)({
48
56
  tags: [core_1.ConfigTag.infrastructure, core_1.ConfigTag.transport, core_1.ConfigTag.grpcServer],
@@ -1 +1 @@
1
- {"version":3,"file":"grpc.config.js","sourceRoot":"","sources":["../src/grpc.config.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAG2C;AAC3C,yCAAoC;AACpC,qCAMoB;AACpB,mDAAsD;AAK/C,IAAM,UAAU,wBAAhB,MAAM,UAAW,SAAQ,aAAM;IAQ3B,OAAO,CAAU;IAMjB,OAAO,CAAU;IAMjB,OAAO,CAAU;CAC3B,CAAA;AAbU;IAPR,IAAA,eAAQ,EAAC,cAAc,EAAE,IAAI,+BAAiB,EAAE,EAAE;QACjD,YAAY,EAAE,eAAe;QAC7B,WAAW,EAAE,IAAA,aAAI,EAAA;;;KAGhB;KACF,CAAC;;2CACwB;AAMjB;IAJR,IAAA,eAAQ,EAAC,iCAAiC,EAAE,IAAI,gBAAS,EAAE,EAAE;QAC5D,YAAY,EAAE,8CAAkC;QAChD,WAAW,EAAE,iCAAiC;KAC/C,CAAC;;2CACwB;AAMjB;IAJR,IAAA,eAAQ,EAAC,8BAA8B,EAAE,IAAI,gBAAS,EAAE,EAAE;QACzD,YAAY,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,EAAE,gBAAS,CAAC,UAAU,CAAC;KAC5E,CAAC;GACW,UAAU,CA2BtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdk/grpc.server",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "Grpc transport for platform, clients and common grpc stuff",
5
5
  "license": "Apache License 2.0",
6
6
  "publishConfig": {
@@ -28,5 +28,5 @@
28
28
  "nice-grpc-opentelemetry": "^0.1.3",
29
29
  "rxjs": "^7.0.0"
30
30
  },
31
- "gitHead": "32a88f5cc5a2c606bbad44d3ff8d22a4334acccc"
31
+ "gitHead": "2ea4aa82c26a18c1211054ea01652d40af0a82f3"
32
32
  }
@@ -8,13 +8,21 @@ import { ILogger } from '@rsdk/logging';
8
8
  import type { Observable } from 'rxjs';
9
9
  import { catchError, tap, throwError } from 'rxjs';
10
10
 
11
+ import { GRPCConfig } from './grpc.config';
12
+
11
13
  export class GrpcLoggerInterceptor implements NestInterceptor {
12
- constructor(@InjectLogger(GrpcLoggerInterceptor) private logger: ILogger) {}
14
+ constructor(
15
+ @InjectLogger(GrpcLoggerInterceptor) private logger: ILogger,
16
+ private grpcConfig: GRPCConfig,
17
+ ) {}
13
18
 
14
19
  intercept(
15
20
  context: ExecutionContext,
16
21
  next: CallHandler<any>,
17
22
  ): Observable<any> | Promise<Observable<any>> {
23
+ if (!this.grpcConfig.requestLogging) {
24
+ return next.handle();
25
+ }
18
26
  const isRpc = context.getType() === 'rpc';
19
27
  if (!isRpc) {
20
28
  return next.handle();
@@ -22,7 +30,7 @@ export class GrpcLoggerInterceptor implements NestInterceptor {
22
30
 
23
31
  const rpc = context.switchToRpc();
24
32
 
25
- const now = Date.now();
33
+ const startDate = Date.now();
26
34
  const rpcContext = rpc.getContext();
27
35
  const serializedCtx = rpcContext?.toJSON?.() ?? rpcContext;
28
36
  const requestForLog = {
@@ -30,28 +38,35 @@ export class GrpcLoggerInterceptor implements NestInterceptor {
30
38
  ctx: serializedCtx,
31
39
  };
32
40
 
33
- this.logger.debug('received rpc request', {
41
+ this.logger.trace('received rpc request', {
34
42
  request: requestForLog,
35
- timestamp: now,
43
+ timestamp: startDate,
36
44
  });
37
45
 
38
46
  return next.handle().pipe(
39
- catchError((err) => {
40
- this.logger.debug('handled rpc request with error', {
47
+ catchError((error) => {
48
+ const endDate = Date.now();
49
+
50
+ this.logger.trace('handled rpc request with error', {
41
51
  request: requestForLog,
42
- start: now,
43
- end: Date.now() - now,
44
- err,
52
+ startDate,
53
+ endDate,
54
+ duration: endDate - startDate,
55
+ error,
45
56
  });
46
- return throwError(() => err);
57
+ return throwError(() => error);
47
58
  }),
48
- tap(() =>
49
- this.logger.debug('handled rpc request', {
59
+ tap((response) => {
60
+ const endDate = Date.now();
61
+
62
+ this.logger.trace('handled rpc request', {
50
63
  request: requestForLog,
51
- start: now,
52
- end: Date.now() - now,
53
- }),
54
- ),
64
+ startDate,
65
+ endDate,
66
+ duration: endDate - startDate,
67
+ response,
68
+ });
69
+ }),
55
70
  );
56
71
  }
57
72
  }
@@ -4,6 +4,7 @@ import {
4
4
  } from '@grpc/grpc-js/build/src/constants';
5
5
  import { text } from '@rsdk/common';
6
6
  import {
7
+ BoolParser,
7
8
  Config,
8
9
  ConfigSection,
9
10
  ConfigTag,
@@ -36,4 +37,10 @@ export class GRPCConfig extends Config {
36
37
  description: 'Max gRPC message size (send)',
37
38
  })
38
39
  readonly maxSend!: number;
40
+
41
+ @Property('GRPC_REQUEST_LOGGING', new BoolParser(), {
42
+ defaultValue: false,
43
+ description: 'Enable trace logging all requests',
44
+ })
45
+ readonly requestLogging!: boolean;
39
46
  }