@@ -472,7 +472,7 @@ func (s *Service) CreateDeployment(ctx context.Context, form *gen.CreateDeployme
472472 return nil , err
473473 }
474474
475- s .captureDeploymentProcessedEvent (ctx , logger , authCtx .OrganizationSlug , * authCtx .ProjectSlug , "create" , dep )
475+ s .captureDeploymentProcessedEvent (ctx , logger , authCtx .OrganizationSlug , * authCtx .ProjectSlug , "create" , dep , nil )
476476
477477 return & gen.CreateDeploymentResult {
478478 Deployment : dep ,
@@ -590,6 +590,7 @@ func (s *Service) Evolve(ctx context.Context, form *gen.EvolvePayload) (*gen.Evo
590590 }
591591
592592 var cloneID uuid.UUID
593+ var previousDeployment * types.Deployment
593594
594595 latestDeploymentID , err := tx .GetLatestDeploymentID (ctx , projectID )
595596 switch {
@@ -630,6 +631,11 @@ func (s *Service) Evolve(ctx context.Context, form *gen.EvolvePayload) (*gen.Evo
630631 return nil , oops .E (oops .CodeUnexpected , err , "error getting latest deployment" ).Log (ctx , logger )
631632 // 3️⃣ We found a latest deployment, we need to clone it
632633 default :
634+ previousDeployment , err = mv .DescribeDeployment (ctx , logger , tx , mv .ProjectID (projectID ), mv .DeploymentID (latestDeploymentID ))
635+ if err != nil {
636+ return nil , err
637+ }
638+
633639 newID , err := cloneDeployment (
634640 ctx , s .tracer , logger , tx ,
635641 ProjectID (projectID ), DeploymentID (latestDeploymentID ),
@@ -685,7 +691,7 @@ func (s *Service) Evolve(ctx context.Context, form *gen.EvolvePayload) (*gen.Evo
685691 return nil , err
686692 }
687693
688- s .captureDeploymentProcessedEvent (ctx , logger , authCtx .OrganizationSlug , * authCtx .ProjectSlug , "evolve" , dep )
694+ s .captureDeploymentProcessedEvent (ctx , logger , authCtx .OrganizationSlug , * authCtx .ProjectSlug , "evolve" , dep , previousDeployment )
689695
690696 return & gen.EvolveResult {Deployment : dep }, nil
691697}
@@ -768,7 +774,7 @@ func (s *Service) Redeploy(ctx context.Context, payload *gen.RedeployPayload) (*
768774 dep .Status = status
769775 }
770776
771- s .captureDeploymentProcessedEvent (ctx , logger , authCtx .OrganizationSlug , * authCtx .ProjectSlug , "redeploy" , dep )
777+ s .captureDeploymentProcessedEvent (ctx , logger , authCtx .OrganizationSlug , * authCtx .ProjectSlug , "redeploy" , dep , nil )
772778
773779 return & gen.RedeployResult {Deployment : dep }, nil
774780}
@@ -883,21 +889,43 @@ func validatePackageInclusion(ctx context.Context, logger *slog.Logger, targetPr
883889 return nil
884890}
885891
886- func (s * Service ) captureDeploymentProcessedEvent (ctx context.Context , logger * slog.Logger , organizationSlug string , projectSlug string , deploymentType string , dep * types.Deployment ) {
887- if err := s .posthog .CaptureEvent (ctx , "deployment_processed" , dep .ID , map [string ]any {
888- "deployment_id" : dep .ID ,
889- "project_id" : dep .ProjectID ,
890- "organization_id" : dep .OrganizationID ,
891- "organization_slug" : organizationSlug ,
892- "project_slug" : projectSlug ,
893- "deployment_type" : deploymentType ,
894- "status" : dep .Status ,
895- "openapiv3_tool_count" : dep .Openapiv3ToolCount ,
896- "functions_tool_count" : dep .FunctionsToolCount ,
897- "functions_asset_count" : len (dep .FunctionsAssets ),
898- "openapiv3_asset_count" : len (dep .Openapiv3Assets ),
899- "logs_url" : fmt .Sprintf ("%s/%s/%s/deployments/%s" , os .Getenv ("GRAM_SITE_URL" ), organizationSlug , projectSlug , dep .ID ),
900- }); err != nil {
892+ func (s * Service ) captureDeploymentProcessedEvent (
893+ ctx context.Context ,
894+ logger * slog.Logger ,
895+ organizationSlug string ,
896+ projectSlug string ,
897+ deploymentType string ,
898+ dep * types.Deployment ,
899+ previousDeployment * types.Deployment ,
900+ ) {
901+ prevDeploymentHasFunctions := previousDeployment != nil && len (previousDeployment .FunctionsAssets ) > 0
902+ firstDeploymentWithFunctions := ! prevDeploymentHasFunctions && len (dep .FunctionsAssets ) > 0
903+
904+ properties := map [string ]any {
905+ "deployment_id" : dep .ID ,
906+ "project_id" : dep .ProjectID ,
907+ "organization_id" : dep .OrganizationID ,
908+ "organization_slug" : organizationSlug ,
909+ "project_slug" : projectSlug ,
910+ "deployment_type" : deploymentType ,
911+ "status" : dep .Status ,
912+ "openapiv3_tool_count" : dep .Openapiv3ToolCount ,
913+ "functions_tool_count" : dep .FunctionsToolCount ,
914+ "functions_asset_count" : len (dep .FunctionsAssets ),
915+ "openapiv3_asset_count" : len (dep .Openapiv3Assets ),
916+ "first_deployment_with_functions" : firstDeploymentWithFunctions ,
917+ "logs_url" : fmt .Sprintf ("%s/%s/%s/deployments/%s" , os .Getenv ("GRAM_SITE_URL" ), organizationSlug , projectSlug , dep .ID ),
918+ }
919+
920+ if previousDeployment != nil {
921+ properties ["previous_status" ] = previousDeployment .Status
922+ properties ["previous_openapiv3_tool_count" ] = previousDeployment .Openapiv3ToolCount
923+ properties ["previous_functions_tool_count" ] = previousDeployment .FunctionsToolCount
924+ properties ["previous_functions_asset_count" ] = len (previousDeployment .FunctionsAssets )
925+ properties ["previous_openapiv3_asset_count" ] = len (previousDeployment .Openapiv3Assets )
926+ }
927+
928+ if err := s .posthog .CaptureEvent (ctx , "deployment_processed" , dep .ID , properties ); err != nil {
901929 logger .ErrorContext (ctx , "error capturing deployment_processed event" , attr .SlogError (err ))
902930 }
903931}
0 commit comments