@@ -584,6 +584,44 @@ func (e *Engine) handleAllTriggerEvents(ctx context.Context) {
584584
585585// startExecution initiates a new workflow execution, blocking until completed
586586func (e * Engine ) startExecution (ctx context.Context , wrappedTriggerEvent enqueuedTriggerEvent ) {
587+ fullExecutionID , err := events .GenerateExecutionIDWithTriggerIndex (e .cfg .WorkflowID , wrappedTriggerEvent .event .Event .ID , wrappedTriggerEvent .triggerIndex )
588+ if err != nil {
589+ e .logger ().Errorw ("Failed to generate execution ID" , "err" , err , "triggerID" , wrappedTriggerEvent .triggerCapID )
590+ return
591+ }
592+
593+ // Fetch organization ID for this execution
594+ organizationID := contexts .CREValue (ctx ).Org
595+ if e .cfg .OrgResolver != nil {
596+ orgID , gerr := e .cfg .OrgResolver .Get (ctx , e .cfg .WorkflowOwner )
597+ if gerr != nil {
598+ e .logger ().Warnw ("Failed to resolve organization ID, continuing without it" , "workflowOwner" , e .cfg .WorkflowOwner , "err" , gerr )
599+ } else {
600+ organizationID = orgID
601+
602+ creCtx := contexts .CREValue (ctx )
603+ creCtx .Org = organizationID
604+ ctx = contexts .WithCRE (ctx , creCtx )
605+ }
606+ }
607+ loggerLabels := maps .Clone (* e .loggerLabels .Load ())
608+ loggerLabels [platform .KeyOrganizationID ] = organizationID
609+ e .loggerLabels .Store (& loggerLabels )
610+ lggr := e .logger ().With (platform .KeyOrganizationID , organizationID )
611+
612+ var executionTimestamp int64
613+ if tsErr := e .cfg .LocalLimiters .ExecutionTimestampsEnabled .AllowErr (ctx ); tsErr == nil {
614+ executionTimeProvider := NewDonTimeProvider (e .cfg .DonTimeStore , fullExecutionID , e .logger ())
615+ donTime , dtErr := executionTimeProvider .GetDONTime ()
616+ if dtErr != nil {
617+ executionTimestamp = e .cfg .Clock .Now ().UnixMilli ()
618+ e .logger ().Warnw ("Failed to get DON time for execution timestamp, falling back to local time" , "err" , dtErr )
619+ } else {
620+ executionTimestamp = donTime .UnixMilli ()
621+ e .logger ().Debugw ("Execution timestamp assigned" , "executionTimestamp" , executionTimestamp )
622+ }
623+ }
624+
587625 triggerEvent := wrappedTriggerEvent .event .Event
588626 executionID , err := events .GenerateExecutionID (e .cfg .WorkflowID , triggerEvent .ID )
589627 if err != nil {
@@ -612,25 +650,6 @@ func (e *Engine) startExecution(ctx context.Context, wrappedTriggerEvent enqueue
612650 }
613651 }()
614652
615- // Fetch organization ID for this execution
616- organizationID := contexts .CREValue (ctx ).Org
617- if e .cfg .OrgResolver != nil {
618- orgID , gerr := e .cfg .OrgResolver .Get (ctx , e .cfg .WorkflowOwner )
619- if gerr != nil {
620- e .logger ().Warnw ("Failed to resolve organization ID, continuing without it" , "workflowOwner" , e .cfg .WorkflowOwner , "err" , gerr )
621- } else {
622- organizationID = orgID
623-
624- creCtx := contexts .CREValue (ctx )
625- creCtx .Org = organizationID
626- ctx = contexts .WithCRE (ctx , creCtx )
627- }
628- }
629- loggerLabels := maps .Clone (* e .loggerLabels .Load ())
630- loggerLabels [platform .KeyOrganizationID ] = organizationID
631- e .loggerLabels .Store (& loggerLabels )
632- lggr := e .logger ().With (platform .KeyOrganizationID , organizationID )
633-
634653 e .metrics .UpdateTotalWorkflowsGauge (ctx , executingWorkflows .Add (1 ))
635654 defer e .metrics .UpdateTotalWorkflowsGauge (ctx , executingWorkflows .Add (- 1 ))
636655
@@ -718,8 +737,8 @@ func (e *Engine) startExecution(ctx context.Context, wrappedTriggerEvent enqueue
718737 return
719738 }
720739 execHelper := & ExecutionHelper {
721- Engine : e , WorkflowExecutionID : executionID , UserLogChan : userLogChan ,
722- TimeProvider : timeProvider , SecretsFetcher : e .secretsFetcher (executionID ),
740+ Engine : e , WorkflowExecutionID : executionID , ExecutionTimestamp : executionTimestamp ,
741+ UserLogChan : userLogChan , TimeProvider : timeProvider , SecretsFetcher : e .secretsFetcher (executionID ),
723742 }
724743 execHelper .initLimiters (e .cfg .LocalLimiters )
725744 var result * sdkpb.ExecutionResult
0 commit comments