From 8273ca2ce18afdbb14d7842ed87c68ca1a99922d Mon Sep 17 00:00:00 2001 From: KishenKumarrrrr Date: Mon, 25 Nov 2024 13:28:36 +0800 Subject: [PATCH] chore: link spans to parent --- .../services/email-transactional.service.ts | 5 ++-- .../src/email/utils/callback/parsers/ses.ts | 26 ++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/backend/src/email/services/email-transactional.service.ts b/backend/src/email/services/email-transactional.service.ts index 087302e08..3d31a983c 100644 --- a/backend/src/email/services/email-transactional.service.ts +++ b/backend/src/email/services/email-transactional.service.ts @@ -129,10 +129,11 @@ type CallbackMetaData = { async function handleStatusCallbacks( type: SesEventType, id: string, - metadata: CallbackMetaData + metadata: CallbackMetaData, + parentSpan?: tracer.Span ): Promise { const handleStatusCallbacksSpan = tracer.startSpan('handleStatusCallbacks', { - childOf: tracer.scope().active() || undefined, + childOf: parentSpan, }) const emailMessageTransactional = await EmailMessageTransactional.findByPk(id) if (!emailMessageTransactional) { diff --git a/backend/src/email/utils/callback/parsers/ses.ts b/backend/src/email/utils/callback/parsers/ses.ts index 6602018e7..cf3f54965 100644 --- a/backend/src/email/utils/callback/parsers/ses.ts +++ b/backend/src/email/utils/callback/parsers/ses.ts @@ -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 @@ -136,12 +136,13 @@ const shouldBlacklist = ({ const parseNotificationAndEvent = async ( type: SesEventType, message: any, - metadata: Metadata + metadata: Metadata, + parentSpan?: tracer.Span ): Promise => { const parseNotificationAndEventSpan = tracer.startSpan( 'parseNotificationAndEvent', { - childOf: tracer.scope().active() || undefined, + childOf: parentSpan, } ) if (!isNotificationAndEventForMainRecipient(message, type)) { @@ -270,14 +271,19 @@ const parseRecord = async (record: SesRecord): Promise => { 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() }