chore: New booking perf tracing (#18212)

* chore: Add perf tracing for handleNewBooking

* Added a few more to the event manager

* Added the sentry wrapper that enables perf tracing

* Revert "Added a few more to the event manager"

This reverts commit ccf3ee5200466b8b1d51f5663363fbb9dfd9a06f.

* Fixed where we wrap sentry

* Reverse sentry wrapper
This commit is contained in:
Keith Williams
2024-12-17 08:51:00 +01:00
committed by GitHub
parent 80815bd8a5
commit 14acf4e9bc
2 changed files with 25 additions and 14 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
import { wrapApiHandlerWithSentry } from "@sentry/nextjs";
import type { NextApiRequest, NextApiResponse } from "next";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
@@ -21,4 +22,4 @@ async function handler(req: NextApiRequest & { userId?: number }, res: NextApiRe
return booking;
}
export default defaultResponder(handler);
export default defaultResponder(wrapApiHandlerWithSentry(handler, "/api/book/event"));
@@ -16,6 +16,7 @@ import { DailyLocationType } from "@calcom/app-store/locations";
import { getAppFromSlug } from "@calcom/app-store/utils";
import EventManager from "@calcom/core/EventManager";
import { getEventName } from "@calcom/core/event";
import monitorCallbackAsync from "@calcom/core/sentryWrapper";
import dayjs from "@calcom/dayjs";
import { scheduleMandatoryReminder } from "@calcom/ee/workflows/lib/reminders/scheduleMandatoryReminder";
import {
@@ -1145,7 +1146,7 @@ async function handler(
try {
if (!isDryRun) {
booking = await createBooking({
booking = await monitorCallbackAsync(createBooking, {
uid,
rescheduledBy: reqBody.rescheduledBy,
routingFormResponseId: routingFormResponseId,
@@ -1182,7 +1183,7 @@ async function handler(
// If it's a round robin event, record the reason for the host assignment
if (eventType.schedulingType === SchedulingType.ROUND_ROBIN) {
if (reqBody.crmOwnerRecordType && reqBody.crmAppSlug && contactOwnerEmail && routingFormResponseId) {
await AssignmentReasonRecorder.CRMOwnership({
await monitorCallbackAsync(AssignmentReasonRecorder.CRMOwnership, {
bookingId: booking.id,
crmAppSlug: reqBody.crmAppSlug,
teamMemberEmail: contactOwnerEmail,
@@ -1190,7 +1191,7 @@ async function handler(
routingFormResponseId,
});
} else if (routingFormResponseId && teamId) {
await AssignmentReasonRecorder.routingFormRoute({
await monitorCallbackAsync(AssignmentReasonRecorder.routingFormRoute, {
bookingId: booking.id,
routingFormResponseId,
organizerId: organizerUser.id,
@@ -1265,7 +1266,7 @@ async function handler(
}
// After polling videoBusyTimes, credentials might have been changed due to refreshment, so query them again.
const credentials = await refreshCredentials(allCredentials);
const credentials = await monitorCallbackAsync(refreshCredentials, allCredentials);
const eventManager = !isDryRun
? new EventManager({ ...organizerUser, credentials }, eventType?.metadata?.apps)
: buildDryRunEventManager();
@@ -1641,7 +1642,8 @@ async function handler(
);
if (!isDryRun) {
await sendScheduledEmailsAndSMS(
await monitorCallbackAsync(
sendScheduledEmailsAndSMS,
{
...evt,
additionalInformation,
@@ -1682,8 +1684,13 @@ async function handler(
})
);
if (!isDryRun) {
await sendOrganizerRequestEmail({ ...evt, additionalNotes }, eventType.metadata);
await sendAttendeeRequestEmailAndSMS({ ...evt, additionalNotes }, attendeesList[0], eventType.metadata);
await monitorCallbackAsync(sendOrganizerRequestEmail, { ...evt, additionalNotes }, eventType.metadata);
await monitorCallbackAsync(
sendAttendeeRequestEmailAndSMS,
{ ...evt, additionalNotes },
attendeesList[0],
eventType.metadata
);
}
}
@@ -1802,8 +1809,11 @@ async function handler(
// We are here so, booking doesn't require payment and booking is also created in DB already, through createBooking call
if (isConfirmedByDefault) {
const subscribersMeetingEnded = await getWebhooks(subscriberOptionsMeetingEnded);
const subscribersMeetingStarted = await getWebhooks(subscriberOptionsMeetingStarted);
const subscribersMeetingEnded = await monitorCallbackAsync(getWebhooks, subscriberOptionsMeetingEnded);
const subscribersMeetingStarted = await monitorCallbackAsync(
getWebhooks,
subscriberOptionsMeetingStarted
);
let deleteWebhookScheduledTriggerPromise: Promise<unknown> = Promise.resolve();
const scheduleTriggerPromises = [];
@@ -1847,13 +1857,13 @@ async function handler(
});
// Send Webhook call if hooked to BOOKING_CREATED & BOOKING_RESCHEDULED
await handleWebhookTrigger({ subscriberOptions, eventTrigger, webhookData });
await monitorCallbackAsync(handleWebhookTrigger, { subscriberOptions, eventTrigger, webhookData });
} else {
// if eventType requires confirmation we will trigger the BOOKING REQUESTED Webhook
const eventTrigger: WebhookTriggerEvents = WebhookTriggerEvents.BOOKING_REQUESTED;
subscriberOptions.triggerEvent = eventTrigger;
webhookData.status = "PENDING";
await handleWebhookTrigger({ subscriberOptions, eventTrigger, webhookData });
await monitorCallbackAsync(handleWebhookTrigger, { subscriberOptions, eventTrigger, webhookData });
}
try {
@@ -1910,7 +1920,7 @@ async function handler(
}
try {
await scheduleWorkflowReminders({
await monitorCallbackAsync(scheduleWorkflowReminders, {
workflows,
smsReminderNumber: smsReminderNumber || null,
calendarEvent: evtWithMetadata,
@@ -1926,7 +1936,7 @@ async function handler(
try {
if (isConfirmedByDefault && (booking.location === DailyLocationType || booking.location?.trim() === "")) {
await scheduleNoShowTriggers({
await monitorCallbackAsync(scheduleNoShowTriggers, {
booking: { startTime: booking.startTime, id: booking.id },
triggerForUser,
organizerUser: { id: organizerUser.id },