3838from skyvern .forge .sdk .schemas .tasks import Task
3939from skyvern .forge .sdk .schemas .workflow_runs import WorkflowRunBlock , WorkflowRunTimeline , WorkflowRunTimelineType
4040from skyvern .forge .sdk .trace import TraceManager
41+ from skyvern .forge .sdk .trace .experiment_utils import collect_experiment_metadata_safely
4142from skyvern .forge .sdk .workflow .exceptions import (
4243 ContextParameterSourceNotDefined ,
4344 InvalidWaitBlockTime ,
@@ -339,6 +340,12 @@ async def execute_workflow(
339340 ) -> WorkflowRun :
340341 """Execute a workflow."""
341342 organization_id = organization .organization_id
343+
344+ # Collect and add experiment metadata to the trace
345+ experiment_metadata = await collect_experiment_metadata_safely (app .EXPERIMENTATION_PROVIDER )
346+ if experiment_metadata :
347+ TraceManager .add_experiment_metadata (experiment_metadata )
348+
342349 LOG .info (
343350 "Executing workflow" ,
344351 workflow_run_id = workflow_run_id ,
@@ -1147,6 +1154,10 @@ async def mark_workflow_run_as_completed(self, workflow_run_id: str, run_with: s
11471154 workflow_run_id = workflow_run_id ,
11481155 workflow_status = "completed" ,
11491156 )
1157+
1158+ # Add workflow completion tag to Laminar trace
1159+ TraceManager .add_task_completion_tag (WorkflowRunStatus .completed )
1160+
11501161 return await self ._update_workflow_run_status (
11511162 workflow_run_id = workflow_run_id ,
11521163 status = WorkflowRunStatus .completed ,
@@ -1165,6 +1176,10 @@ async def mark_workflow_run_as_failed(
11651176 workflow_status = "failed" ,
11661177 failure_reason = failure_reason ,
11671178 )
1179+
1180+ # Add workflow failure tag to Laminar trace
1181+ TraceManager .add_task_completion_tag (WorkflowRunStatus .failed )
1182+
11681183 return await self ._update_workflow_run_status (
11691184 workflow_run_id = workflow_run_id ,
11701185 status = WorkflowRunStatus .failed ,
@@ -1197,6 +1212,10 @@ async def mark_workflow_run_as_terminated(
11971212 workflow_status = "terminated" ,
11981213 failure_reason = failure_reason ,
11991214 )
1215+
1216+ # Add workflow terminated tag to Laminar trace
1217+ TraceManager .add_task_completion_tag (WorkflowRunStatus .terminated )
1218+
12001219 return await self ._update_workflow_run_status (
12011220 workflow_run_id = workflow_run_id ,
12021221 status = WorkflowRunStatus .terminated ,
@@ -1210,6 +1229,10 @@ async def mark_workflow_run_as_canceled(self, workflow_run_id: str, run_with: st
12101229 workflow_run_id = workflow_run_id ,
12111230 workflow_status = "canceled" ,
12121231 )
1232+
1233+ # Add workflow canceled tag to Laminar trace
1234+ TraceManager .add_task_completion_tag (WorkflowRunStatus .canceled )
1235+
12131236 return await self ._update_workflow_run_status (
12141237 workflow_run_id = workflow_run_id ,
12151238 status = WorkflowRunStatus .canceled ,
@@ -1227,6 +1250,10 @@ async def mark_workflow_run_as_timed_out(
12271250 workflow_run_id = workflow_run_id ,
12281251 workflow_status = "timed_out" ,
12291252 )
1253+
1254+ # Add workflow timed out tag to Laminar trace
1255+ TraceManager .add_task_completion_tag (WorkflowRunStatus .timed_out )
1256+
12301257 return await self ._update_workflow_run_status (
12311258 workflow_run_id = workflow_run_id ,
12321259 status = WorkflowRunStatus .timed_out ,
0 commit comments