Skip to content

Commit d27ea9a

Browse files
authored
Merge pull request #42 from hemicharly/feature/tracer
Feature: Merge feature/tracer into Develop
2 parents ed59174 + 2f9ff47 commit d27ea9a

File tree

55 files changed

+136
-55
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+136
-55
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ timesheet-in-transit-api/
3737
-- app/
3838
│ │-- src/
3939
│ │ │-- app.module.ts
40-
│ │ │-- config.env.ts
4140
│ │ │-- database.module.ts
4241
│ │ │-- index.ts
4342
│ │ │-- main.ts
@@ -47,7 +46,7 @@ timesheet-in-transit-api/
4746
│ │ │ │-- config/
4847
│ │ │ │-- consumers/
4948
│ │ │ │-- web/
50-
│ │ │ │ │-- common/
49+
│ │ │ │ │-- shared/
5150
│ │ │ │ │-- config/
5251
│ │ │ │ │-- rest/
5352
│ │ │-- core/
@@ -67,6 +66,9 @@ timesheet-in-transit-api/
6766
│ │ │ │-- integrations/
6867
│ │ │ │-- queue/
6968
│ │ │ │-- repositories/
69+
│ │ │-- shared/
70+
│ │ │ │-- audit/
71+
│ │ │ │-- config/
7072
```
7173

7274
### **modules**

README.pt-br.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ timesheet-in-transit-api/
3737
-- app/
3838
│ │-- src/
3939
│ │ │-- app.module.ts
40-
│ │ │-- config.env.ts
4140
│ │ │-- database.module.ts
4241
│ │ │-- index.ts
4342
│ │ │-- main.ts
@@ -47,7 +46,7 @@ timesheet-in-transit-api/
4746
│ │ │ │-- config/
4847
│ │ │ │-- consumers/
4948
│ │ │ │-- web/
50-
│ │ │ │ │-- common/
49+
│ │ │ │ │-- shared/
5150
│ │ │ │ │-- config/
5251
│ │ │ │ │-- rest/
5352
│ │ │-- core/
@@ -67,6 +66,9 @@ timesheet-in-transit-api/
6766
│ │ │ │-- integrations/
6867
│ │ │ │-- queue/
6968
│ │ │ │-- repositories/
69+
│ │ │-- shared/
70+
│ │ │ │-- audit/
71+
│ │ │ │-- config/
7072
```
7173

7274
### **modules**

app/src/core/usecases/notification/impl/notification.order.register.usecase.impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NotificationOrderCoreEntity } from 'src/core/domain/entities/notifications';
22
import { NotificationOrderRegisterUsecase } from '@core/usecases/notification';
3-
import { ProducerQueueProvider } from '@core/providers/queue/producer.queue.provider';
4-
import { configEnv } from '@src/config.env';
3+
import { ProducerQueueProvider } from '@core/providers/queue';
4+
import { configEnv } from '@shared/config';
55

66
export class NotificationOrderRegisterUsecaseImpl implements NotificationOrderRegisterUsecase {
77
constructor(private readonly sendQueueProvider: ProducerQueueProvider) {}

app/src/database.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Module } from '@nestjs/common';
22
import { TypeOrmModule } from '@nestjs/typeorm';
3-
import { configEnv } from '@src/config.env';
3+
import { configEnv } from '@src/shared/config';
44

55
@Module({
66
imports: [

app/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from './app.module';
2-
export * from './config.env';
32
export * from './database.module';
43
export * from './main';
54
export * from './seed.module';

app/src/infrastructure/integrations/config/abstract/integration.config.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { DynamicModule, Module, Type } from '@nestjs/common';
99
* @example
1010
*
1111
* ```typescript
12-
* import { Module } from '@nestjs/common';
12+
* import { Module } from '@nestjs/shared';
1313
* import { WebhookIntegrationClientProviderImpl } from '@infrastructure/integrations/webhook-client/impl';
1414
* import { IntegrationConfigModule } from 'src/infrastructure/integrations/config/abstract';
1515
* import { WebhookConfigModule } from '@infrastructure/integrations/webhook-client/config';

app/src/infrastructure/integrations/common/audit/integration.audit.common.ts renamed to app/src/infrastructure/integrations/shared/audit/integration.audit.common.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { HttpService } from '@nestjs/axios';
22
import { Logger } from '@nestjs/common';
33
import { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
4-
import { IntegrationLoggerDto } from '@infrastructure/integrations/common/audit';
4+
import { IntegrationLoggerDto } from '@infrastructure/integrations/shared/audit';
5+
import { TracerContextAudit } from '@shared/audit';
56

67
/**
78
* Class responsible for managing API integration audit logs.
@@ -11,10 +12,10 @@ import { IntegrationLoggerDto } from '@infrastructure/integrations/common/audit'
1112
*
1213
* ```typescript
1314
* import { WebhookIntegrationClientProvider } from '@core/providers/integrations';
14-
* import { Injectable, Logger } from '@nestjs/common';
15+
* import { Injectable, Logger } from '@nestjs/shared';
1516
* import { firstValueFrom } from 'rxjs';
1617
* import { HttpService } from '@nestjs/axios';
17-
* import { IntegrationAuditCommon } from '@infrastructure/integrations/common/audit';
18+
* import { IntegrationAuditCommon } from '@infrastructure/integrations/shared/audit';
1819
*
1920
* @Injectable()
2021
* export class WebhookIntegrationClientProviderImpl implements WebhookIntegrationClientProvider {
@@ -83,6 +84,7 @@ export class IntegrationAuditCommon {
8384
config.headers = {};
8485
}
8586
config.headers['request-start-time'] = process.hrtime();
87+
config.headers['x-tracer-id'] = TracerContextAudit.getContextTracerId();
8688
return config;
8789
}
8890

@@ -126,7 +128,7 @@ export class IntegrationAuditCommon {
126128
*/
127129
private logAudit(config: AxiosRequestConfig, responseData: any, status: number, startTime: [number, number], isError: boolean = false): void {
128130
const integrationLoggerDto = this.createIntegrationLoggerDto(config, responseData, status, startTime);
129-
const logMessage = `[AUDIT LOG] ${JSON.stringify(integrationLoggerDto)}`;
131+
const logMessage = JSON.stringify(integrationLoggerDto);
130132
if (isError) {
131133
this.logger.error(logMessage);
132134
return;
@@ -144,8 +146,9 @@ export class IntegrationAuditCommon {
144146
* @returns An `IntegrationLoggerDto` object containing the audit information.
145147
*/
146148
private createIntegrationLoggerDto(config: AxiosRequestConfig, responseData: any, status: number, startTime: [number, number]): IntegrationLoggerDto {
149+
const tracerId = <string>config.headers['x-tracer-id'];
147150
const method = `${config.method?.toUpperCase()} ${config.url}`;
148-
return new IntegrationLoggerDto(this.application, method, config.headers, config.params, config.data, responseData, status, startTime);
151+
return new IntegrationLoggerDto(tracerId, this.application, method, config.headers, config.params, config.data, responseData, status, startTime);
149152
}
150153

151154
/**

app/src/infrastructure/integrations/common/audit/integration.logger.dto.ts renamed to app/src/infrastructure/integrations/shared/audit/integration.logger.dto.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const SENSITIVE_FIELDS = new Set([
2626
* @class IntegrationLoggerDto
2727
*/
2828
export class IntegrationLoggerDto {
29+
readonly tracerId: string;
30+
2931
/**
3032
* Date and time when the log was created.
3133
* @type {string}
@@ -84,6 +86,7 @@ export class IntegrationLoggerDto {
8486
* Constructor for the `IntegrationLoggerDto` class.
8587
* Initializes the properties and masks sensitive fields from the provided data.
8688
*
89+
* @param {string} tracerId The tracer id log.
8790
* @param {string} application The name of the application generating the log.
8891
* @param {string} endpoint The API endpoint called.
8992
* @param {any} headers The request headers.
@@ -93,7 +96,8 @@ export class IntegrationLoggerDto {
9396
* @param {number} statusCode The HTTP status code of the response.
9497
* @param {[number, number]} startTime The start time of the request for calculating duration.
9598
*/
96-
constructor(application: string, endpoint: string, headers: any, queryParameters: any, requestBody: any, responseBody: any, statusCode: number, startTime: [number, number]) {
99+
constructor(tracerId: string, application: string, endpoint: string, headers: any, queryParameters: any, requestBody: any, responseBody: any, statusCode: number, startTime: [number, number]) {
100+
this.tracerId = tracerId; // Sets the tracerId
97101
this.timestamp = new Date().toJSON(); // Marks the timestamp of the log
98102
this.application = application; // Sets the application name
99103
this.endpoint = endpoint; // Sets the accessed endpoint

app/src/infrastructure/integrations/webhook-client/config/webhook.config.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Module } from '@nestjs/common';
22
import { HttpModule } from '@nestjs/axios';
3-
import { configEnv } from '@src/config.env';
3+
import { configEnv } from '@src/shared/config';
44

55
@Module({
66
imports: [

0 commit comments

Comments
 (0)