Skip to content

Commit b3d3cb1

Browse files
authored
refactor: Uses withReporting to force named functions for tracing (calcom#21219)
1 parent 79d6952 commit b3d3cb1

35 files changed

Lines changed: 844 additions & 384 deletions

packages/app-store/routing-forms/lib/handleResponse.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { emailSchema } from "@calcom/lib/emailSchema";
55
import logger from "@calcom/lib/logger";
66
import { findTeamMembersMatchingAttributeLogic } from "@calcom/lib/raqb/findTeamMembersMatchingAttributeLogic";
77
import { safeStringify } from "@calcom/lib/safeStringify";
8-
import monitorCallbackAsync from "@calcom/lib/sentryWrapper";
8+
import { withReporting } from "@calcom/lib/sentryWrapper";
99
import { prisma } from "@calcom/prisma";
1010
import type { App_RoutingForms_Form } from "@calcom/prisma/client";
1111
import { RoutingFormSettings } from "@calcom/prisma/zod-utils";
@@ -32,10 +32,6 @@ export type Form = SerializableForm<
3232

3333
const moduleLogger = logger.getSubLogger({ prefix: ["routing-forms/lib/handleResponse"] });
3434

35-
export const handleResponse = (...args: Parameters<typeof _handleResponse>) => {
36-
return monitorCallbackAsync(_handleResponse, ...args);
37-
};
38-
3935
const _handleResponse = async ({
4036
response,
4137
form,
@@ -185,7 +181,7 @@ const _handleResponse = async ({
185181
})(),
186182
]);
187183

188-
await monitorCallbackAsync(getRoutedMembers);
184+
await withReporting(getRoutedMembers, "getRoutedMembers")();
189185
} else {
190186
// It currently happens for a Router route. Such a route id isn't present in the form.routes
191187
}
@@ -202,8 +198,7 @@ const _handleResponse = async ({
202198
},
203199
});
204200

205-
await monitorCallbackAsync(
206-
onFormSubmission,
201+
await onFormSubmission(
207202
{ ...serializableFormWithFields, userWithEmails },
208203
dbFormResponse.response as FormResponse,
209204
dbFormResponse.id,
@@ -247,3 +242,5 @@ const _handleResponse = async ({
247242
throw e;
248243
}
249244
};
245+
246+
export const handleResponse = withReporting(_handleResponse, "handleResponse");

packages/app-store/routing-forms/trpc/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
66
import { sendGenericWebhookPayload } from "@calcom/features/webhooks/lib/sendPayload";
77
import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
88
import logger from "@calcom/lib/logger";
9+
import { withReporting } from "@calcom/lib/sentryWrapper";
910
import { WebhookTriggerEvents } from "@calcom/prisma/client";
1011
import type { Ensure } from "@calcom/types/utils";
1112

@@ -84,7 +85,7 @@ export function getFieldResponse({
8485
* Not called in preview mode or dry run mode
8586
* It takes care of sending webhooks and emails for form submissions
8687
*/
87-
export async function onFormSubmission(
88+
async function _onFormSubmission(
8889
form: Ensure<
8990
SerializableForm<App_RoutingForms_Form> & { user: Pick<User, "id" | "email">; userWithEmails?: string[] },
9091
"fields"
@@ -206,6 +207,7 @@ export async function onFormSubmission(
206207
}
207208
}
208209
}
210+
export const onFormSubmission = withReporting(_onFormSubmission, "onFormSubmission");
209211

210212
export const sendResponseEmail = async (
211213
form: Pick<App_RoutingForms_Form, "id" | "name" | "fields">,

packages/emails/email-manager.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getEventName } from "@calcom/lib/event";
88
import { formatCalEvent } from "@calcom/lib/formatCalendarEvent";
99
import logger from "@calcom/lib/logger";
1010
import { safeStringify } from "@calcom/lib/safeStringify";
11+
import { withReporting } from "@calcom/lib/sentryWrapper";
1112
import type { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
1213
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
1314

@@ -98,7 +99,7 @@ const eventTypeDisableHostEmail = (metadata?: EventTypeMetadata) => {
9899
return !!metadata?.disableStandardEmails?.all?.host;
99100
};
100101

101-
export const sendScheduledEmailsAndSMS = async (
102+
const _sendScheduledEmailsAndSMS = async (
102103
calEvent: CalendarEvent,
103104
eventNameObject?: EventNameObjectType,
104105
hostEmailDisabled?: boolean,
@@ -145,6 +146,11 @@ export const sendScheduledEmailsAndSMS = async (
145146
await successfullyScheduledSms.sendSMSToAttendees();
146147
};
147148

149+
export const sendScheduledEmailsAndSMS = withReporting(
150+
_sendScheduledEmailsAndSMS,
151+
"sendScheduledEmailsAndSMS"
152+
);
153+
148154
// for rescheduled round robin booking that assigned new members
149155
export const sendRoundRobinScheduledEmailsAndSMS = async ({
150156
calEvent,
@@ -245,7 +251,7 @@ export const sendRoundRobinCancelledEmailsAndSMS = async (
245251
await Promise.all(emailsAndSMSToSend);
246252
};
247253

248-
export const sendRescheduledEmailsAndSMS = async (
254+
const _sendRescheduledEmailsAndSMS = async (
249255
calEvent: CalendarEvent,
250256
eventTypeMetadata?: EventTypeMetadata
251257
) => {
@@ -276,6 +282,10 @@ export const sendRescheduledEmailsAndSMS = async (
276282
const successfullyReScheduledSms = new EventSuccessfullyReScheduledSMS(calEvent);
277283
await successfullyReScheduledSms.sendSMSToAttendees();
278284
};
285+
export const sendRescheduledEmailsAndSMS = withReporting(
286+
_sendRescheduledEmailsAndSMS,
287+
"sendRescheduledEmailsAndSMS"
288+
);
279289

280290
export const sendRescheduledSeatEmailAndSMS = async (
281291
calEvent: CalendarEvent,
@@ -370,10 +380,7 @@ export const sendCancelledSeatEmailsAndSMS = async (
370380
await cancelledSeatSMS.sendSMSToAttendee(cancelledAttendee);
371381
};
372382

373-
export const sendOrganizerRequestEmail = async (
374-
calEvent: CalendarEvent,
375-
eventTypeMetadata?: EventTypeMetadata
376-
) => {
383+
const _sendOrganizerRequestEmail = async (calEvent: CalendarEvent, eventTypeMetadata?: EventTypeMetadata) => {
377384
if (eventTypeDisableHostEmail(eventTypeMetadata)) return;
378385
const calendarEvent = formatCalEvent(calEvent);
379386

@@ -390,7 +397,12 @@ export const sendOrganizerRequestEmail = async (
390397
await Promise.all(emailsToSend);
391398
};
392399

393-
export const sendAttendeeRequestEmailAndSMS = async (
400+
export const sendOrganizerRequestEmail = withReporting(
401+
_sendOrganizerRequestEmail,
402+
"sendOrganizerRequestEmail"
403+
);
404+
405+
const _sendAttendeeRequestEmailAndSMS = async (
394406
calEvent: CalendarEvent,
395407
attendee: Person,
396408
eventTypeMetadata?: EventTypeMetadata
@@ -403,6 +415,11 @@ export const sendAttendeeRequestEmailAndSMS = async (
403415
await eventRequestSms.sendSMSToAttendee(attendee);
404416
};
405417

418+
export const sendAttendeeRequestEmailAndSMS = withReporting(
419+
_sendAttendeeRequestEmailAndSMS,
420+
"sendAttendeeRequestEmailAndSMS"
421+
);
422+
406423
export const sendDeclinedEmailsAndSMS = async (
407424
calEvent: CalendarEvent,
408425
eventTypeMetadata?: EventTypeMetadata

packages/features/bookings/lib/getAllCredentialsForUsersOnEvent/refreshCredentials.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import async from "async";
22

33
import { isDelegationCredential } from "@calcom/lib/delegationCredential/clientAndServer";
44
import { buildAllCredentials } from "@calcom/lib/delegationCredential/server";
5+
import { withReporting } from "@calcom/lib/sentryWrapper";
56
import type { CredentialForCalendarService } from "@calcom/types/Credential";
67

78
import { refreshCredential } from "./refreshCredential";
@@ -11,9 +12,10 @@ import { refreshCredential } from "./refreshCredential";
1112
*
1213
* @param credentials
1314
*/
14-
export async function refreshCredentials(
15+
// Define the function with underscore prefix
16+
const _refreshCredentials = async (
1517
credentials: Array<CredentialForCalendarService>
16-
): Promise<Array<CredentialForCalendarService>> {
18+
): Promise<Array<CredentialForCalendarService>> => {
1719
const nonDelegationCredentials = credentials.filter(
1820
(cred) => !isDelegationCredential({ credentialId: cred.id })
1921
);
@@ -22,4 +24,6 @@ export async function refreshCredentials(
2224
);
2325
const refreshedDbCredentials = await async.mapLimit(nonDelegationCredentials, 5, refreshCredential);
2426
return buildAllCredentials({ delegationCredentials, existingCredentials: refreshedDbCredentials });
25-
}
27+
};
28+
29+
export const refreshCredentials = withReporting(_refreshCredentials, "refreshCredentials");

0 commit comments

Comments
 (0)