Skip to content

Commit

Permalink
chore: link spans to parent
Browse files Browse the repository at this point in the history
  • Loading branch information
KishenKumarrrrr committed Nov 25, 2024
1 parent e0a29e4 commit 8273ca2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
5 changes: 3 additions & 2 deletions backend/src/email/services/email-transactional.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ type CallbackMetaData = {
async function handleStatusCallbacks(
type: SesEventType,
id: string,
metadata: CallbackMetaData
metadata: CallbackMetaData,
parentSpan?: tracer.Span
): Promise<void> {
const handleStatusCallbacksSpan = tracer.startSpan('handleStatusCallbacks', {
childOf: tracer.scope().active() || undefined,
childOf: parentSpan,
})
const emailMessageTransactional = await EmailMessageTransactional.findByPk(id)
if (!emailMessageTransactional) {
Expand Down
26 changes: 16 additions & 10 deletions backend/src/email/utils/callback/parsers/ses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import config from '@core/config'
import { compareSha256Hash } from '@shared/utils/crypto'
import { EmailTransactionalService } from '@email/services/email-transactional.service'
import { SesEventType, Metadata } from '@email/interfaces/callback.interface'
import { tracer } from 'dd-trace'
import tracer from 'dd-trace'

const logger = loggerWithLabel(module)
const REFERENCE_ID_HEADER_V2 = 'X-SMTPAPI' // Case sensitive
Expand Down Expand Up @@ -136,12 +136,13 @@ const shouldBlacklist = ({
const parseNotificationAndEvent = async (
type: SesEventType,
message: any,
metadata: Metadata
metadata: Metadata,
parentSpan?: tracer.Span
): Promise<void> => {
const parseNotificationAndEventSpan = tracer.startSpan(
'parseNotificationAndEvent',
{
childOf: tracer.scope().active() || undefined,
childOf: parentSpan,
}
)
if (!isNotificationAndEventForMainRecipient(message, type)) {
Expand Down Expand Up @@ -270,14 +271,19 @@ const parseRecord = async (record: SesRecord): Promise<void> => {
type,
})
if (isTransactional) {
return EmailTransactionalService.handleStatusCallbacks(type, messageId, {
timestamp: new Date(record.Timestamp),
bounce: message.bounce,
complaint: message.complaint,
delivery: message.delivery,
})
return EmailTransactionalService.handleStatusCallbacks(
type,
messageId,
{
timestamp: new Date(record.Timestamp),
bounce: message.bounce,
complaint: message.complaint,
delivery: message.delivery,
},
parseRecordSpan
)
}
return parseNotificationAndEvent(type, message, metadata)
return parseNotificationAndEvent(type, message, metadata, parseRecordSpan)
}
parseRecordSpan.finish()
}
Expand Down

0 comments on commit 8273ca2

Please sign in to comment.