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

Telemetry for guest login. #110

Merged
Merged
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
25 changes: 22 additions & 3 deletions src/api/api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class ApiController {
@Query() params: SendOtpDto,
@Headers('x-application-id') applicationId?,
): Promise<any> {
const startTime = Date.now();
const startTime = ((performance.timeOrigin + performance.now()) * 1000);

let status: any,
isWhatsApp = false,
Expand Down Expand Up @@ -136,7 +136,7 @@ export class ApiController {
{
botId: params.botId,
orgId: params.orgId,
timeTaken: Date.now() - startTime,
timeTaken: ((performance.timeOrigin + performance.now()) * 1000) - startTime,
createdAt: Math.floor(new Date().getTime() / 1000),
phoneNumber: params.phone,
eventLog: `Response from OTP provider - ${status.providerSuccessResponse}`,
Expand Down Expand Up @@ -430,6 +430,7 @@ export class ApiController {
@Headers('authorization') authHeader,
@Headers('ADMIN-API-KEY') adminApiKey,
): Promise<any> {
const startTime = ((performance.timeOrigin + performance.now()) * 1000);
if (adminApiKey != this.configService.get('ADMIN_API_KEY')) {
const response: SignupResponse = new SignupResponse().init(uuidv4());
response.responseCode = ResponseCode.FAILURE;
Expand All @@ -438,7 +439,25 @@ export class ApiController {
response.params.status = ResponseStatus.failure;
return response;
}
return await this.apiService.loginWithUniqueId(user, authHeader);
let response = await this.apiService.loginWithUniqueId(user, authHeader);
if (this.configService.get('TELEMETRY_INTERNAL_BASE_URL')) {
this.telemetryService.sendEvent(
{
botId: user.botId,
orgId: null,
timeTaken: ((performance.timeOrigin + performance.now()) * 1000) - startTime,
createdAt: Math.floor(new Date().getTime() / 1000),
userId: response.result.data.user.id,
eventLog: `Status from Fusionauth - ${response.responseCode}`,
fingerprint: user.loginId
},
'E119',
'Guest Login',
'GuestLogin',
'PWA'
);
}
return response;
}

@Post('jwt/verify')
Expand Down
4 changes: 4 additions & 0 deletions src/api/dto/login.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ export class LoginWithUniqueIdDto {
@IsUUID()
@IsNotEmpty()
applicationId: string;

@IsOptional()
@IsUUID()
botId: string;
}
Loading