Hello, I'm a newbie here. I have a task that has 5...
# ask-community
p
Hello, I'm a newbie here. I have a task that has 5 retries, and I want to make it fail gracefully without having a big stacktrace in the logs. Currently I just
raise
when the task is not good, and here is what I got
Copy code
14:21:23.335 | INFO    | prefect.engine - Created flow run 'hot-bullfrog' for flow 'data-refresh'
14:21:23.383 | INFO    | Flow run 'hot-bullfrog' - Created task run 'wait-for-connectors-0' for task 'wait-for-connectors'
14:21:23.384 | INFO    | Flow run 'hot-bullfrog' - Executing 'wait-for-connectors-0' immediately...
14:21:23.411 | ERROR   | Task run 'wait-for-connectors-0' - Encountered exception during execution:
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/prefect/engine.py", line 1760, in orchestrate_task_run
    result = await call.aresult()
             ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/prefect/_internal/concurrency/calls.py", line 291, in aresult
    return await asyncio.wrap_future(self.future)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/prefect/_internal/concurrency/calls.py", line 315, in _run_sync
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/north-star/data-tasks/data-refresh/tasks/wait_for_connectors.py", line 13, in wait_for_connectors
    raise
RuntimeError: No active exception to reraise
14:21:23.431 | INFO    | Task run 'wait-for-connectors-0' - Received non-final state 'AwaitingRetry' when proposing final state 'Failed' and will attempt to run again...
I want to have something like that
Copy code
14:21:23.335 | INFO    | prefect.engine - Created flow run 'hot-bullfrog' for flow 'data-refresh'
14:21:23.383 | INFO    | Flow run 'hot-bullfrog' - Created task run 'wait-for-connectors-0' for task 'wait-for-connectors'
14:21:23.384 | INFO    | Flow run 'hot-bullfrog' - Executing 'wait-for-connectors-0' immediately...
14:21:23.411 | ERROR   | Task run 'wait-for-connectors-0' - Encountered exception during execution:
14:21:23.431 | INFO    | Task run 'wait-for-connectors-0' - Received non-final state 'AwaitingRetry' when proposing final state 'Failed' and will attempt to run again...
b
Hey Pierre, I haven't done this myself, but think I can point you in the right direction. You could create a custom logging.yaml that filters out any log that contains "Traceback" in the message. Here's a discourse article which gives one example of how to suppress certain logs that match a given criteria https://discourse.prefect.io/t/how-do-i-suppress-created-task-run-logs/750
Keep in mind that it may remove the entire error log. You'll want to ensure that you log errors/exceptions separately, to avoid having them completely omitted from the logs
Like maybe setting a custom error-level message using get_run_logger https://docs.prefect.io/2.14.3/guides/logs/?h=logg#logging-in-flows
thank you 1