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

feat: custom spans #2287

Merged
merged 17 commits into from
Nov 27, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: add more spans
KishenKumarrrrr committed Nov 25, 2024
commit e0a29e486375d3670d0e8e2022d1998e4e318264
170 changes: 85 additions & 85 deletions backend/src/email/services/email-transactional.service.ts
Original file line number Diff line number Diff line change
@@ -131,107 +131,107 @@ async function handleStatusCallbacks(
id: string,
metadata: CallbackMetaData
): Promise<void> {
tracer.wrap('handleStatusCallbacks', async () => {
const emailMessageTransactional = await EmailMessageTransactional.findByPk(
id
)
if (!emailMessageTransactional) {
throw new Error(`Failed to find emailMessageTransactional for id: ${id}`)
}
const handleStatusCallbacksSpan = tracer.startSpan('handleStatusCallbacks', {
childOf: tracer.scope().active() || undefined,
})
const emailMessageTransactional = await EmailMessageTransactional.findByPk(id)
if (!emailMessageTransactional) {
throw new Error(`Failed to find emailMessageTransactional for id: ${id}`)
}

const mainRecipientDelivered = metadata.delivery?.recipients?.find(
(e) => e === emailMessageTransactional.recipient
)
const mainRecipientBounced = metadata.bounce?.bouncedRecipients?.find(
const mainRecipientDelivered = metadata.delivery?.recipients?.find(
(e) => e === emailMessageTransactional.recipient
)
const mainRecipientBounced = metadata.bounce?.bouncedRecipients?.find(
(e) => e.emailAddress === emailMessageTransactional.recipient
)
const mainRecipientComplained =
metadata.complaint?.complainedRecipients?.find(
(e) => e.emailAddress === emailMessageTransactional.recipient
)
const mainRecipientComplained =
metadata.complaint?.complainedRecipients?.find(
(e) => e.emailAddress === emailMessageTransactional.recipient
)

switch (type) {
case SesEventType.Delivery:
if (mainRecipientDelivered) {
await EmailMessageTransactional.update(
{
status: TransactionalEmailMessageStatus.Delivered,
deliveredAt: metadata.timestamp,
},
{
where: { id },
}
)
}
break
case SesEventType.Bounce:
// check that bounce applies to the main recipient
if (mainRecipientBounced) {
await EmailMessageTransactional.update(
{
status: TransactionalEmailMessageStatus.Bounced,
errorCode:
metadata.bounce?.bounceType === 'Permanent'
? 'Hard bounce'
: 'Soft bounce',
errorSubType: metadata.bounce?.bounceSubType,
},
{
where: { id },
}
)
}
break
case SesEventType.Complaint:
// check that complaint applies to the main recipient
if (mainRecipientComplained) {
await EmailMessageTransactional.update(
{
status: TransactionalEmailMessageStatus.Complaint,
errorCode: metadata.complaint?.complaintFeedbackType,
errorSubType: metadata.complaint?.complaintSubType,
},
{
where: { id },
}
)
}
break
case SesEventType.Open:
// Cannot check that open applies to the main recipient
// we only update the DB if there was no previous error
switch (type) {
case SesEventType.Delivery:
if (mainRecipientDelivered) {
await EmailMessageTransactional.update(
{
status: TransactionalEmailMessageStatus.Opened,
openedAt: metadata.timestamp,
status: TransactionalEmailMessageStatus.Delivered,
deliveredAt: metadata.timestamp,
},
{
where: { id, errorCode: null },
where: { id },
}
)
break
case SesEventType.Send:
// Cannot check that send applies to the main recipient
// we only update the DB if there was no previous error
}
break
case SesEventType.Bounce:
// check that bounce applies to the main recipient
if (mainRecipientBounced) {
await EmailMessageTransactional.update(
{
status: TransactionalEmailMessageStatus.Sent,
sentAt: metadata.timestamp,
status: TransactionalEmailMessageStatus.Bounced,
errorCode:
metadata.bounce?.bounceType === 'Permanent'
? 'Hard bounce'
: 'Soft bounce',
errorSubType: metadata.bounce?.bounceSubType,
},
{
where: { id, errorCode: null },
where: { id },
}
)
break
default:
logger.warn({
message: 'Unable to handle messages with this type',
type,
id,
metadata,
})
}
})
}
break
case SesEventType.Complaint:
// check that complaint applies to the main recipient
if (mainRecipientComplained) {
await EmailMessageTransactional.update(
{
status: TransactionalEmailMessageStatus.Complaint,
errorCode: metadata.complaint?.complaintFeedbackType,
errorSubType: metadata.complaint?.complaintSubType,
},
{
where: { id },
}
)
}
break
case SesEventType.Open:
// Cannot check that open applies to the main recipient
// we only update the DB if there was no previous error
await EmailMessageTransactional.update(
{
status: TransactionalEmailMessageStatus.Opened,
openedAt: metadata.timestamp,
},
{
where: { id, errorCode: null },
}
)
break
case SesEventType.Send:
// Cannot check that send applies to the main recipient
// we only update the DB if there was no previous error
await EmailMessageTransactional.update(
{
status: TransactionalEmailMessageStatus.Sent,
sentAt: metadata.timestamp,
},
{
where: { id, errorCode: null },
}
)
break
default:
logger.warn({
message: 'Unable to handle messages with this type',
type,
id,
metadata,
})
}
handleStatusCallbacksSpan.finish()
}

async function listMessages({

Unchanged files with check annotations Beta

void fetchGovsgMessages(search, selectedPage).finally(() => {
setLoading(false)
})
}, [])

Check warning on line 112 in frontend/src/components/dashboard/create/govsg/GovsgMessages.tsx

GitHub Actions / test-frontend

React Hook useEffect has missing dependencies: 'fetchGovsgMessages', 'search', and 'selectedPage'. Either include them or remove the dependency array
const handlePageChange = (index: number) => {
void fetchGovsgMessages(search, index)
campaignId: number
}): (data: CSVParams[]) => Promise<void> {
return async function (data: CSVParams[]): Promise<void> {
const paramsWithoutPasscode = template.params!.filter(

Check warning on line 112 in backend/src/govsg/services/govsg.service.ts

GitHub Actions / test-backend

Forbidden non-null assertion

Check warning on line 112 in backend/src/govsg/services/govsg.service.ts

GitHub Actions / Deploy backend to AWS Elastic Beanstalk / lint-test

Forbidden non-null assertion
(param) => param !== 'passcode'
) // TODO: Un-hardcode this
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion