diff --git a/ee/lib/telesign/transaction_callback.rb b/ee/lib/telesign/transaction_callback.rb index 6401e10b6e909bb26d39e500f18e867ac0905414..619f477b1692944659206f373497e673fdde67ea 100644 --- a/ee/lib/telesign/transaction_callback.rb +++ b/ee/lib/telesign/transaction_callback.rb @@ -29,6 +29,7 @@ def log ::Gitlab::AppJsonLogger.info( class: self.class.name, + username: user&.username, message: 'IdentityVerification::Phone', event: 'Telesign transaction status update', telesign_reference_id: payload.reference_id, @@ -40,22 +41,30 @@ def log track_status_update_event end + private + + def phone_number_validation_record + Users::PhoneNumberValidation.by_reference_id(payload.reference_id) + end + strong_memoize_attr :phone_number_validation_record + + def user + phone_number_validation_record&.user + end + def track_status_update_event - record = Users::PhoneNumberValidation.by_reference_id(payload.reference_id) - return unless record + return unless phone_number_validation_record event = payload.failed_delivery? ? 'telesign_sms_delivery_failed' : 'telesign_sms_delivery_success' Gitlab::Tracking.event( 'IdentityVerification::Phone', event, - user: record.user, - extra: { country_code: record.country, status: payload.status } + user: user, + extra: { country_code: phone_number_validation_record.country, status: payload.status } ) end - private - def telesign_customer_id ::Gitlab::CurrentSettings.telesign_customer_xid end diff --git a/ee/spec/lib/telesign/transaction_callback_spec.rb b/ee/spec/lib/telesign/transaction_callback_spec.rb index 85f3a0b2f9a077c3b58ea68d70188ab854ec5c59..d7a85163134ef617823b5c7b58ddf204f87d63c2 100644 --- a/ee/spec/lib/telesign/transaction_callback_spec.rb +++ b/ee/spec/lib/telesign/transaction_callback_spec.rb @@ -95,7 +95,7 @@ end end - it 'logs with the correct payload' do + it 'logs with the correct payload and tracks the event', :aggregate_failures do expect_next_instance_of(Telesign::TransactionCallbackPayload, request_params) do |response| expect(response).to receive(:reference_id).and_return(reference_id, reference_id) expect(response).to receive(:status).and_return(status, status) @@ -107,6 +107,7 @@ expect(Gitlab::AppJsonLogger).to receive(:info).with( hash_including( class: 'Telesign::TransactionCallback', + username: phone_number_validation.user.username, message: 'IdentityVerification::Phone', event: 'Telesign transaction status update', telesign_reference_id: reference_id, @@ -152,7 +153,7 @@ context 'when there is no matching record for the received reference_id' do let(:reference_id) { 'non-existing-ref-id' } - it 'does not log' do + it 'does not track any event' do expect_next_instance_of(Telesign::TransactionCallbackPayload, request_params) do |response| expect(response).to receive(:reference_id).and_return(reference_id, reference_id) expect(response).to receive(:status).and_return(status)