Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task #200127 : Sentry Setup with BreadCrumbs and captureException for All Cron Job #402

Open
wants to merge 22 commits into
base: feat-sentry
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1caed1a
task #200127: debug and solved invalid parameter bug, added same user…
rushi-tekdi Oct 8, 2023
a030bc4
task #200127: attendance photo match cron job added
rushi-tekdi Oct 9, 2023
e673638
Task #200127: added cron job schedule time for face indexing and mark…
rushi-tekdi Oct 10, 2023
e810caf
Task #200127: AWS Rekogonizition API POC to detect face similarities…
rushi-tekdi Oct 11, 2023
29cd714
Task #200127: changed env files and its dependent variables in code, …
rushi-tekdi Oct 13, 2023
2d58f42
Task #200127: solved sonar smells
rushi-tekdi Oct 13, 2023
37a8ea8
Task #200127: solved sonar smells
rushi-tekdi Oct 13, 2023
1cc990a
Task #200127: solved comments
rushi-tekdi Oct 13, 2023
e7ea518
Task #200127: solved comments
rushi-tekdi Oct 13, 2023
e4dc855
Task #200127: cron job files rename
rushi-tekdi Oct 16, 2023
0aa6585
Sentry Test
rushi-tekdi Oct 16, 2023
ba2baa1
sentry test
rushi-tekdi Oct 16, 2023
3febf1c
test sentry
rushi-tekdi Oct 16, 2023
4eed58a
sentry test
rushi-tekdi Oct 16, 2023
00d563b
Task #200127: added sentry breadcrumbs, transactions, capture exceptions
rushi-tekdi Oct 18, 2023
774bee4
Task #200127: solved conflicts in PR
rushi-tekdi Oct 19, 2023
3b858dc
Task #200127: solved sonarcloud 3 smells
rushi-tekdi Oct 19, 2023
1a9cdd2
Task #200127: removed sentry tracing, addedd JSON.strigify in all bre…
rushi-tekdi Oct 19, 2023
e50572b
Task #200127: removed sentry filter, updated sentry breadcrumb servic…
rushi-tekdi Oct 22, 2023
a2541aa
Task #200127: solved sonarclound smells
rushi-tekdi Oct 23, 2023
5a80c9b
Update sentry.service.ts
manojLondhe Oct 23, 2023
90ce495
Update aws-rekognition.service.ts
manojLondhe Oct 27, 2023
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: 2 additions & 0 deletions src/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { CommentsModule } from './comments/comments.module';
import { CampModule } from './camp/camp.module';
import { ReferencesModule } from './references/references.module';
import { PcrscoresModule } from './pcrscores/pcrscores.module';
import { SentryModule } from './services/sentry/sentry.module';

@Module({
imports: [
Expand Down Expand Up @@ -56,6 +57,7 @@ import { PcrscoresModule } from './pcrscores/pcrscores.module';
CampModule,
ReferencesModule,
PcrscoresModule,
SentryModule,
],
controllers: [],
providers: [],
Expand Down
3 changes: 2 additions & 1 deletion src/src/cron/cron.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { FaFaceIndexingCron } from './faFaceIndexing.cron';
import { FaAttendanceProcessingCron } from './faAttendanceProcessing.cron';
import { AwsRekognitionModule } from '../services/aws-rekognition/aws-rekognition.module';
import { HasuraModule } from '../services/hasura/hasura.module';
import { SentryModule } from '../services/sentry/sentry.module';
@Module({
imports: [AwsRekognitionModule, HasuraModule],
imports: [AwsRekognitionModule, HasuraModule, SentryModule],
providers: [
FaUserIndexingCron,
FaFaceIndexingCron,
Expand Down
48 changes: 38 additions & 10 deletions src/src/cron/faAttendanceProcessing.cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Cron } from '@nestjs/schedule';
import { ConfigService } from '@nestjs/config';
import { AwsRekognitionService } from '../services/aws-rekognition/aws-rekognition.service';
import { HasuraService } from '../services/hasura/hasura.service';
import { SentryService } from '../services/sentry/sentry.service';

@Injectable()
export class FaAttendanceProcessingCron {
Expand All @@ -12,6 +13,7 @@ export class FaAttendanceProcessingCron {
private configService: ConfigService,
private awsRekognitionService: AwsRekognitionService,
private hasuraService: HasuraService,
private sentryService: SentryService,
) {
this.prefixed = this.configService.get<string>(
'AWS_REKOGNITION_CUSTOM_PREFIX',
Expand All @@ -21,11 +23,20 @@ export class FaAttendanceProcessingCron {
//3rd cron runs for each hour's 25th minute eg: 10:25am, 11::25am
@Cron('25 * * * *')
async markAttendanceCron() {
const transaction = this.sentryService.startTransaction(
'Cron Job 3',
'Mark attendance',
);
try {
/*----------------------- Mark attendance of from face index of users in collection -----------------------*/
console.log(
'cron job 3: markAttendanceCron started at time ' + new Date(),
);
this.sentryService.addBreadcrumb(
'Cron Job 3',
'markAttendanceCron started at time ' + new Date(),
'info',
);
const collectionId = this.configService.get<string>(
'AWS_REKOGNITION_COLLECTION_ID',
);
Expand All @@ -37,8 +48,12 @@ export class FaAttendanceProcessingCron {
),
),
);
//console.log('attendance users');
//console.dir(usersForAttendance, { depth: 99 });
this.sentryService.addBreadcrumb(
'Cron Job 3',
'response usersForAttendance ' +
JSON.stringify(usersForAttendance),
'info',
);
// Step-2 Iterate thorugh them
for (const user of usersForAttendance) {
const userId = String(user.id);
Expand Down Expand Up @@ -109,11 +124,9 @@ export class FaAttendanceProcessingCron {
}
}
} catch (error) {
console.log(
'Error occurred in markAttendanceCron.',
error,
error.stack,
);
this.sentryService.captureException(error);
} finally {
(await transaction).finish();
}
}

Expand All @@ -140,13 +153,18 @@ export class FaAttendanceProcessingCron {
}
}
`;
this.sentryService.addBreadcrumb(
'Cron Job 3',
'updateQuery: ' + updateQuery,
'info',
);
try {
return (
(await this.hasuraService.getData({ query: updateQuery })).data
.update_attendance_by_pk.id === attendanceId
);
} catch (error) {
console.log('markAttendance:', error, error.stack);
this.sentryService.captureException(error);
return [];
}
}
Expand All @@ -168,13 +186,18 @@ export class FaAttendanceProcessingCron {
}
}
`;
this.sentryService.addBreadcrumb(
'Cron Job 3',
'updateQuery: ' + updateQuery,
'info',
);
try {
return (
(await this.hasuraService.getData({ query: updateQuery })).data
.update_attendance_by_pk.id === attendanceId
);
} catch (error) {
console.log('markAttendance:', error, error.stack);
this.sentryService.captureException(error);
return [];
}
}
Expand Down Expand Up @@ -203,12 +226,17 @@ export class FaAttendanceProcessingCron {
}
}
`;
this.sentryService.addBreadcrumb(
'Cron Job 3',
'query: ' + query,
'info',
);
try {
const users = (await this.hasuraService.getData({ query }))?.data
?.users;
return users;
} catch (error) {
console.log('getAllUsersForAttendance:', error, error.stack);
this.sentryService.captureException(error);
return [];
}
}
Expand Down
90 changes: 57 additions & 33 deletions src/src/cron/faFaceIndexing.cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Cron } from '@nestjs/schedule';
import { ConfigService } from '@nestjs/config';
import { AwsRekognitionService } from '../services/aws-rekognition/aws-rekognition.service';
import { HasuraService } from '../services/hasura/hasura.service';
import { SentryService } from '../services/sentry/sentry.service';

@Injectable()
export class FaFaceIndexingCron {
Expand All @@ -12,6 +13,7 @@ export class FaFaceIndexingCron {
private configService: ConfigService,
private awsRekognitionService: AwsRekognitionService,
private hasuraService: HasuraService,
private sentryService: SentryService,
) {
this.prefixed = this.configService.get<string>(
'AWS_REKOGNITION_CUSTOM_PREFIX',
Expand All @@ -21,12 +23,21 @@ export class FaFaceIndexingCron {
//2nd cron runs for each hour's 15th minute eg: 10:15am, 11::15am
@Cron('15 * * * *')
async indexRekognitionUsers() {
const transaction = this.sentryService.startTransaction(
'Cron Job 2',
'Create Face Index',
);
try {
/*----------------------- Create face index of users in collection -----------------------*/
console.log(
'cron job 2: indexRekognitionUsers started at time ' +
new Date(),
);
this.sentryService.addBreadcrumb(
'Cron Job 2',
'indexRekognitionUsers started at time ' + new Date(),
'info',
);
const collectionId = this.configService.get<string>(
'AWS_REKOGNITION_COLLECTION_ID',
);
Expand All @@ -40,8 +51,11 @@ export class FaFaceIndexingCron {
),
),
);
//console.dir(usersToIndexFaces, { depth: 99 });
//console.log('usersToINdexfaces-->>', usersToIndexFaces);
this.sentryService.addBreadcrumb(
'Cron Job 2',
'response usersToIndexFaces ' + JSON.stringify(usersToIndexFaces),
'info',
);

// Step-2: Iterate through them and index faces one by one
for (const user of usersToIndexFaces) {
Expand Down Expand Up @@ -184,11 +198,9 @@ export class FaFaceIndexingCron {
}
}
} catch (error) {
console.log(
'Error occurred in indexRekognitionUsers.',
error,
error.stack,
);
this.sentryService.captureException(error);
} finally {
(await transaction).finish();
}
}

Expand Down Expand Up @@ -248,10 +260,19 @@ export class FaFaceIndexingCron {
}
}
`;
this.sentryService.addBreadcrumb(
'Cron Job 2',
'query: ' + query,
'info',
);
try {
let users = (await this.hasuraService.getData({ query }))?.data
?.users;
//console.log('fetchindex------>>>>>', users);
this.sentryService.addBreadcrumb(
'Cron Job 2',
'fetchindex: ' + JSON.stringify(users),
'info',
);
users.forEach((user) => {
for (const key of [
'profile_photo_1',
Expand All @@ -265,18 +286,14 @@ export class FaFaceIndexingCron {
}
}
});
/*console.log(
'\n>>>>>> Batch of users for whom face photos to be indexed:\n',
users,
);*/

this.sentryService.addBreadcrumb(
'Cron Job 2',
'Batch of users for whom face photos to be indexed: ' + JSON.stringify(users),
'info',
);
return users;
} catch (error) {
console.log(
`END - Get batch of users for whom face photos to be indexed.'. Error!\n`,
error,
error.stack,
);
this.sentryService.captureException(error);
return [];
}
}
Expand All @@ -294,7 +311,11 @@ export class FaFaceIndexingCron {
faceId,
)
).success;
//console.log('photoDisassociated------>>>>>', photoDisassociated);
this.sentryService.addBreadcrumb(
'Cron Job 2',
'photoDisassociated: ' + JSON.stringify(photoDisassociated),
'info',
);
let response = { success: false };
// Delete face from collection
if (photoDisassociated) {
Expand All @@ -320,7 +341,11 @@ export class FaFaceIndexingCron {
collectionId,
imageName,
);
//console.log('addFaceResponse111------>>>>>', addFaceResponse);
this.sentryService.addBreadcrumb(
'Cron Job 2',
'addFaceResponse111: ' + JSON.stringify(addFaceResponse),
'info',
);
const response = { success: false, faceId: addFaceResponse.faceId };
// Associate face to user
if (addFaceResponse.success) {
Expand All @@ -340,11 +365,6 @@ export class FaFaceIndexingCron {
userId: number,
{ fa_photos_last_processed_at },
) {
/*console.log(
'START - Mark fa last processed timestamp for user with: userId, as',
userId,
);*/

let updateQuery = `
mutation MyMutation {
update_users_by_pk(
Expand All @@ -360,17 +380,16 @@ export class FaFaceIndexingCron {
}
}
`;

this.sentryService.addBreadcrumb(
'Cron Job 2',
'updateQuery: ' + updateQuery,
'info',
);
try {
return (await this.hasuraService.getData({ query: updateQuery }))
.data.update_users_by_pk;
} catch (error) {
console.log(
`END - Mark fa last processed timestamp for user'. Error!\n`,
error,
error.stack,
);

this.sentryService.captureException(error);
return [];
}
}
Expand Down Expand Up @@ -400,11 +419,16 @@ export class FaFaceIndexingCron {
}
}
`;
this.sentryService.addBreadcrumb(
'Cron Job 2',
'updateQuery: ' + updateQuery,
'info',
);
try {
return (await this.hasuraService.getData({ query: updateQuery }))
.data.update_users_by_pk;
} catch (error) {
console.log('markUserAsIndexed:', error, error.stack);
this.sentryService.captureException(error);
return [];
}
}
Expand Down
Loading