From 10e11d4add99e45d0881ec2000a870ca877bed3c Mon Sep 17 00:00:00 2001 From: Bastien Dumont <bdumont@grandlyon.com> Date: Fri, 26 Jul 2024 17:04:40 +0200 Subject: [PATCH] fix: missing startTransaction --- src/core/core.js | 97 ++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/src/core/core.js b/src/core/core.js index 53d7743..e6830f9 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -87,58 +87,59 @@ async function createConsent({ boToken, boUrlGRDF, }) { - const transaction = Sentry.startTransaction({ - op: 'konnector', - name: 'createConsent', - tags: { pce }, - }) - const startDateString = moment(startDate).format('YYYY-MM-DD') - const endDateString = moment(endDate).format('YYYY-MM-DD') + return Sentry.startSpan( + { + name: 'createConsent', + }, + async span => { + const startDateString = moment(startDate).format('YYYY-MM-DD') + const endDateString = moment(endDate).format('YYYY-MM-DD') - // Handle some accounts running everyday with no consent (previous accounts from oauth) - if (!lastname) { - log('error', 'No lastname provided, stopping consent creation') - throw errors.USER_ACTION_NEEDED - } + // Handle some accounts running everyday with no consent (previous accounts from oauth) + if (!lastname) { + log('error', 'No lastname provided, stopping consent creation') + throw errors.USER_ACTION_NEEDED + } - const { ID: consentId } = await createBoConsent({ - boUrlGRDF, - boToken, - pce, - firstname, - lastname, - postalCode, - endDate, - }).catch(err => { - log('error', `Failed to create BO consent, ${err}`) - throw errors.MAINTENANCE - }) + const { ID: consentId } = await createBoConsent({ + boUrlGRDF, + boToken, + pce, + firstname, + lastname, + postalCode, + endDate, + }).catch(err => { + log('error', `Failed to create BO consent, ${err}`) + throw errors.MAINTENANCE + }) - // Save BO consentId into account - const accountData = await getAccount(ACCOUNT_ID) - await saveAccountData(ACCOUNT_ID, { - ...accountData.data, - consentId: consentId, - }) + // Save BO consentId into account + const accountData = await getAccount(ACCOUNT_ID) + await saveAccountData(ACCOUNT_ID, { + ...accountData.data, + consentId: consentId, + }) - await createGRDFConsent({ - bearerToken, - email, - lastname, - pce, - postalCode, - startDate: startDateString, - endDate: endDateString, - }).catch(async err => { - await deleteBoConsent({ - boUrlGRDF, - boToken, - consentId: consentId, - }) - throw err - }) - transaction.finish() - throw errors.CHALLENGE_ASKED + await createGRDFConsent({ + bearerToken, + email, + lastname, + pce, + postalCode, + startDate: startDateString, + endDate: endDateString, + }).catch(async err => { + await deleteBoConsent({ + boUrlGRDF, + boToken, + consentId: consentId, + }) + throw err + }) + throw errors.CHALLENGE_ASKED + } + ) } module.exports = { handleConsents, createConsent } -- GitLab