@@ -20,6 +20,8 @@ import getOrgIdFromMemberOrTeamId from "@calcom/lib/getOrgIdFromMemberOrTeamId";
2020import { getTeamIdFromEventType } from "@calcom/lib/getTeamIdFromEventType" ;
2121import logger from "@calcom/lib/logger" ;
2222import { safeStringify } from "@calcom/lib/safeStringify" ;
23+ import type { TraceContext } from "@calcom/lib/tracing" ;
24+ import { distributedTracing } from "@calcom/lib/tracing/factory" ;
2325import type { PrismaClient } from "@calcom/prisma" ;
2426import type { Prisma } from "@calcom/prisma/client" ;
2527import type { SchedulingType } from "@calcom/prisma/enums" ;
@@ -74,6 +76,7 @@ export async function handleConfirmation(args: {
7476 paid ?: boolean ;
7577 emailsEnabled ?: boolean ;
7678 platformClientParams ?: PlatformClientParams ;
79+ traceContext : TraceContext ;
7780} ) {
7881 const {
7982 user,
@@ -85,6 +88,7 @@ export async function handleConfirmation(args: {
8588 paid,
8689 emailsEnabled = true ,
8790 platformClientParams,
91+ traceContext,
8892 } = args ;
8993 const eventType = booking . eventType ;
9094 const eventTypeMetadata = EventTypeMetaDataSchema . parse ( eventType ?. metadata || { } ) ;
@@ -96,13 +100,17 @@ export async function handleConfirmation(args: {
96100 const metadata : AdditionalInformation = { } ;
97101 const workflows = await getAllWorkflowsFromEventType ( eventType , booking . userId ) ;
98102
103+ const spanContext = distributedTracing . createSpan ( traceContext , "handle_confirmation" ) ;
104+
105+ const tracingLogger = distributedTracing . getTracingLogger ( spanContext ) ;
106+
99107 if ( results . length > 0 && results . every ( ( res ) => ! res . success ) ) {
100108 const error = {
101109 errorCode : "BookingCreatingMeetingFailed" ,
102110 message : "Booking failed" ,
103111 } ;
104112
105- log . error ( `Booking ${ user . username } failed` , safeStringify ( { error, results } ) ) ;
113+ tracingLogger . error ( `Booking ${ user . username } failed` , safeStringify ( { error, results } ) ) ;
106114 } else {
107115 if ( results . length ) {
108116 // TODO: Handle created event metadata more elegantly
@@ -139,7 +147,7 @@ export async function handleConfirmation(args: {
139147 ) ;
140148 }
141149 } catch ( error ) {
142- log . error ( error ) ;
150+ tracingLogger . error ( error ) ;
143151 }
144152 }
145153 let updatedBookings : {
@@ -358,6 +366,7 @@ export async function handleConfirmation(args: {
358366 hideBranding : ! ! updatedBookings [ index ] . eventType ?. owner ?. hideBranding ,
359367 seatReferenceUid : evt . attendeeSeatId ,
360368 isPlatformNoEmail : ! emailsEnabled && Boolean ( platformClientParams ?. platformClientId ) ,
369+ traceContext : spanContext ,
361370 } ) ;
362371 }
363372
@@ -487,7 +496,7 @@ export async function handleConfirmation(args: {
487496 sub ,
488497 payload
489498 ) . catch ( ( e ) => {
490- log . error (
499+ tracingLogger . error (
491500 `Error executing webhook for event: ${ WebhookTriggerEvents . BOOKING_CREATED } , URL: ${ sub . subscriberUrl } , bookingId: ${ evt . bookingId } , bookingUid: ${ evt . uid } , platformClientId: ${ platformClientParams ?. platformClientId } ` ,
492501 safeStringify ( e )
493502 ) ;
@@ -547,7 +556,7 @@ export async function handleConfirmation(args: {
547556 sub ,
548557 payload
549558 ) . catch ( ( e ) => {
550- log . error (
559+ tracingLogger . error (
551560 `Error executing webhook for event: ${ WebhookTriggerEvents . BOOKING_PAID } , URL: ${ sub . subscriberUrl } , bookingId: ${ evt . bookingId } , bookingUid: ${ evt . uid } ` ,
552561 safeStringify ( e )
553562 ) ;
@@ -586,7 +595,10 @@ export async function handleConfirmation(args: {
586595 creditCheckFn : creditService . hasAvailableCredits . bind ( creditService ) ,
587596 } ) ;
588597 } catch ( error ) {
589- log . error ( "Error while scheduling workflow reminders for booking paid" , safeStringify ( error ) ) ;
598+ tracingLogger . error (
599+ "Error while scheduling workflow reminders for booking paid" ,
600+ safeStringify ( error )
601+ ) ;
590602 }
591603 }
592604 } catch ( error ) {
0 commit comments