Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true,
"version": "4.0.1",
"version": "4.1.0",
"packages": [
"packages/*"
],
Expand Down
8 changes: 4 additions & 4 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-auth",
"version": "4.0.1",
"version": "4.1.0",
"description": "Multiversx SDK Nestjs auth package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -38,9 +38,9 @@
"jsonwebtoken": "^9.0.0"
},
"peerDependencies": {
"@multiversx/sdk-nestjs-cache": "^4.0.0",
"@multiversx/sdk-nestjs-common": "^4.0.0",
"@multiversx/sdk-nestjs-monitoring": "^4.0.0",
"@multiversx/sdk-nestjs-cache": "^4.1.0",
"@multiversx/sdk-nestjs-common": "^4.1.0",
"@multiversx/sdk-nestjs-monitoring": "^4.1.0",
"@nestjs/common": "^10.x"
},
"publishConfig": {
Expand Down
8 changes: 4 additions & 4 deletions packages/cache/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-cache",
"version": "4.0.1",
"version": "4.1.0",
"description": "Multiversx SDK Nestjs cache package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -40,9 +40,9 @@
"uuid": "^8.3.2"
},
"peerDependencies": {
"@multiversx/sdk-nestjs-common": "^4.0.0",
"@multiversx/sdk-nestjs-monitoring": "^4.0.0",
"@multiversx/sdk-nestjs-redis": "^4.0.0",
"@multiversx/sdk-nestjs-common": "^4.1.0",
"@multiversx/sdk-nestjs-monitoring": "^4.1.0",
"@multiversx/sdk-nestjs-redis": "^4.1.0",
"@nestjs/common": "^10.x",
"@nestjs/core": "^10.x"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-common",
"version": "4.0.1",
"version": "4.1.0",
"description": "Multiversx SDK Nestjs common package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -40,7 +40,7 @@
"winston": "^3.7.2"
},
"peerDependencies": {
"@multiversx/sdk-nestjs-monitoring": "^4.0.0",
"@multiversx/sdk-nestjs-monitoring": "^4.1.0",
"@nestjs/common": "^10.x",
"@nestjs/config": "^3.x",
"@nestjs/core": "^10.x",
Expand Down
4 changes: 2 additions & 2 deletions packages/elastic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-elastic",
"version": "4.0.1",
"version": "4.1.0",
"description": "Multiversx SDK Nestjs elastic package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -31,7 +31,7 @@
"typescript": "^4.3.5"
},
"peerDependencies": {
"@multiversx/sdk-nestjs-http": "^4.0.0",
"@multiversx/sdk-nestjs-http": "^4.1.0",
"@nestjs/common": "^10.x"
},
"publishConfig": {
Expand Down
6 changes: 3 additions & 3 deletions packages/http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-http",
"version": "4.0.1",
"version": "4.1.0",
"description": "Multiversx SDK Nestjs http package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -38,8 +38,8 @@
"axios": "^1.7.4"
},
"peerDependencies": {
"@multiversx/sdk-nestjs-common": "^4.0.0",
"@multiversx/sdk-nestjs-monitoring": "^4.0.0",
"@multiversx/sdk-nestjs-common": "^4.1.0",
"@multiversx/sdk-nestjs-monitoring": "^4.1.0",
"@nestjs/common": "^10.x",
"@nestjs/core": "^10.x"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/monitoring/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-monitoring",
"version": "4.0.1",
"version": "4.1.0",
"description": "Multiversx SDK Nestjs monitoring package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions packages/monitoring/src/interceptors/entities/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './logging.interceptor.context';
export * from './request.cpu.time.interceptor.context';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ExecutionContext } from "@nestjs/common";

export class LoggingInterceptorContext {
apiFunction: string = '';
durationMs: number = 0;
origin: string = '';
statusCode: number = 0;
context!: ExecutionContext;

constructor(init?: Partial<LoggingInterceptorContext>) {
Object.assign(this, init);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ExecutionContext } from '@nestjs/common';

export class RequestCpuTimeInterceptorContext {
apiFunction: string = '';
durationMs: number = 0;
context!: ExecutionContext;

constructor(init?: Partial<RequestCpuTimeInterceptorContext>) {
Object.assign(this, init);
}
}
1 change: 1 addition & 0 deletions packages/monitoring/src/interceptors/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './entities';
export * from './log.requests.interceptor';
export * from './logging.interceptor';
export * from './request.cpu.time.interceptor';
22 changes: 22 additions & 0 deletions packages/monitoring/src/interceptors/logging.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { Observable, throwError } from "rxjs";
import { catchError, tap } from "rxjs/operators";
import { MetricsService } from "../metrics";
import { PerformanceProfiler } from "../profilers/performance.profiler";
import { LoggingInterceptorContext } from "./entities/logging.interceptor.context";

@Injectable()
export class LoggingInterceptor implements NestInterceptor {
constructor(
private readonly metricsService: MetricsService,
private readonly onRequest?: (context: LoggingInterceptorContext) => void,
) { }

intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
Expand Down Expand Up @@ -38,13 +40,33 @@ export class LoggingInterceptor implements NestInterceptor {
const res = http.getResponse();

this.metricsService.setApiCall(apiFunction, origin, res.statusCode, profiler.duration);

if (this.onRequest) {
this.onRequest(new LoggingInterceptorContext({
apiFunction,
durationMs: profiler.duration,
origin,
statusCode: res.statusCode,
context,
}));
}
}),
catchError(err => {
profiler.stop();

const statusCode = err.status ?? HttpStatus.INTERNAL_SERVER_ERROR;
this.metricsService.setApiCall(apiFunction, origin, statusCode, profiler.duration);

if (this.onRequest) {
this.onRequest(new LoggingInterceptorContext({
apiFunction,
durationMs: profiler.duration,
origin,
statusCode,
context,
}));
}

return throwError(() => err);
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { Observable, throwError } from "rxjs";
import { catchError, tap } from 'rxjs/operators';
import { MetricsService } from '../metrics';
import { CpuProfiler } from "../profilers/cpu.profiler";
import { RequestCpuTimeInterceptorContext } from "./entities";

@Injectable()
export class RequestCpuTimeInterceptor implements NestInterceptor {
constructor(
private readonly metricsService: MetricsService
private readonly metricsService: MetricsService,
private readonly onRequest?: (context: RequestCpuTimeInterceptorContext) => void,
) { }

intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
Expand All @@ -29,6 +31,14 @@ export class RequestCpuTimeInterceptor implements NestInterceptor {
const duration = profiler.stop();
this.metricsService.setApiCpuTime(apiFunction, duration);

if (this.onRequest) {
this.onRequest(new RequestCpuTimeInterceptorContext({
apiFunction,
durationMs: duration,
context,
}));
}

if (!request.res.headersSent) {
request.res.set('X-Request-Cpu-Time', duration);
}
Expand All @@ -37,10 +47,17 @@ export class RequestCpuTimeInterceptor implements NestInterceptor {
const duration = profiler.stop();
this.metricsService.setApiCpuTime(apiFunction, duration);

if (this.onRequest) {
this.onRequest(new RequestCpuTimeInterceptorContext({
apiFunction,
durationMs: duration,
context,
}));
}

if (!request.res.headersSent) {
request.res.set('X-Request-Cpu-Time', duration);
}

return throwError(() => err);
})
);
Expand Down
4 changes: 2 additions & 2 deletions packages/rabbitmq/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-rabbitmq",
"version": "4.0.1",
"version": "4.1.0",
"description": "Multiversx SDK Nestjs rabbitmq client package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down Expand Up @@ -37,7 +37,7 @@
"uuid": "^8.3.2"
},
"peerDependencies": {
"@multiversx/sdk-nestjs-common": "^4.0.0",
"@multiversx/sdk-nestjs-common": "^4.1.0",
"@nestjs/common": "^10.x"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/redis/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-nestjs-redis",
"version": "4.0.1",
"version": "4.1.0",
"description": "Multiversx SDK Nestjs redis client package",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down