@@ -1961,8 +1961,13 @@ def logs_captured(self, *loggers: logging.Logger):
19611961 l .setLevel (prev_levels [i ])
19621962
19631963 def find_log (self , starts_with : str ) -> Optional [logging .LogRecord ]:
1964+ return self .find (lambda l : l .message .startswith (starts_with ))
1965+
1966+ def find (
1967+ self , pred : Callable [[logging .LogRecord ], bool ]
1968+ ) -> Optional [logging .LogRecord ]:
19641969 for record in cast (List [logging .LogRecord ], self .log_queue .queue ):
1965- if record . message . startswith ( starts_with ):
1970+ if pred ( record ):
19661971 return record
19671972 return None
19681973
@@ -2058,6 +2063,7 @@ async def run(self) -> None:
20582063 if not task_fail_once_workflow_has_failed :
20592064 task_fail_once_workflow_has_failed = True
20602065 raise RuntimeError ("Intentional workflow task failure" )
2066+ task_fail_once_workflow_has_failed = False
20612067
20622068 # Execute activity that will fail once
20632069 await workflow .execute_activity (
@@ -7975,6 +7981,33 @@ async def test_quick_activity_swallows_cancellation(client: Client):
79757981 temporalio .worker ._workflow_instance ._raise_on_cancelling_completed_activity_override = False
79767982
79777983
7984+ async def test_workflow_logging_trace_identifier (client : Client ):
7985+ with LogCapturer ().logs_captured (
7986+ temporalio .worker ._workflow_instance .logger
7987+ ) as capturer :
7988+ async with new_worker (
7989+ client ,
7990+ TaskFailOnceWorkflow ,
7991+ activities = [task_fail_once_activity ],
7992+ ) as worker :
7993+ await client .execute_workflow (
7994+ TaskFailOnceWorkflow .run ,
7995+ id = f"workflow_failure_trace_identifier" ,
7996+ task_queue = worker .task_queue ,
7997+ )
7998+
7999+ def workflow_failure (l : logging .LogRecord ):
8000+ if (
8001+ hasattr (l , "__temporal_error_identifier" )
8002+ and getattr (l , "__temporal_error_identifier" ) == "WorkflowTaskFailure"
8003+ ):
8004+ assert l .msg .startswith ("Failed activation on workflow" )
8005+ return True
8006+ return False
8007+
8008+ assert capturer .find (workflow_failure ) is not None
8009+
8010+
79788011@activity .defn
79798012def use_in_workflow () -> bool :
79808013 return workflow .in_workflow ()
0 commit comments