Hi team, I am encountering the issue that the task...
# ask-community
f
Hi team, I am encountering the issue that the tasks runs are missing in the Prefect run logs. The flow executes as expected but the just the logs for the task runs are not recorded. The same issue was raised https://github.com/PrefectHQ/prefect/issues/15153 and I followed the debug steps but no luck. I verified that the running container can talk to the postgress database. No task runs were recorded in the db when I use prefect client to check. Does anyone know the fix? Config: • Self-hosting Prefect API server + Prefect worker + Postgress db in the ECS. • The prefect version "3.7.20" (derived using
curl https://<prefect-server-url>/api/admin/version
)
🤔 1
1
l
Hi, I have the exact same issue and i just joined the community to ask the same question so i will be following the thread. Hopefully we can solve it! 🙂
In my case i have self-hosted server and worker on separate linux based VMs and i discovered that if i run a flow from the VM the flow finishes at the set_state call to the API (i have enabled debug logging for all Python loggers and i can see the API calls along with the flow logs). However if i run the exact same flow from my windows machine, there is one more call at the end that sends the logs to the API. This definitely looks like a configuration but i have PREFECT_LOGGING_TO_API_ENABLED set to True for both environments.
I have solved the issue but i am not 100% sure why it's happening, my suspicion is that the prefect logger was not initialized until the moment i called it (after which all logs appeared). If the following steps solve the issue for you as well i would suggest that it is a bug indeed. What i did (maybe not all steps are needed but this worked for me): • find if there is a logging.yaml file in the ~/.prefect directory and delete it (for me the file was in /home/user/.prefect/ • create a minimal flow with the following code and execute it directly in the python environment by calling python flow.py • note - the moment
print("Prefect logger handlers:", logging.getLogger("prefect").__dict__)
is called, the logger is created so play around with that and see if this actually solves the problem for you 🤞
Copy code
import os
import logging, prefect
from prefect import flow, get_run_logger

# Configure Python logging globally
logging.basicConfig(
    level=<http://logging.INFO|logging.INFO>,  # capture DEBUG and above
    format="%(asctime)s | %(levelname)s | %(name)s | %(message)s"
)

from prefect.settings import PREFECT_API_URL, PREFECT_LOGGING_TO_API_ENABLED
print("Prefect:", prefect.__version__)
print("API URL:", PREFECT_API_URL.value())
print("Logging to API:", PREFECT_LOGGING_TO_API_ENABLED.value())
print("Prefect logger handlers:", logging.getLogger("prefect").__dict__)


@flow
def debug_env():
    # Get Prefect logger
    logger = get_run_logger()

    # Environment variables
    <http://logger.info|logger.info>(f"PREFECT_API_URL={os.environ.get('PREFECT_API_URL')}")
    <http://logger.info|logger.info>(f"PREFECT_LOGGING_TO_API_ENABLED={os.environ.get('PREFECT_LOGGING_TO_API_ENABLED')}")
    <http://logger.info|logger.info>(f"PREFECT_LOGGING_SETTINGS_PATH={os.environ.get('PREFECT_LOGGING_SETTINGS_PATH')}")

if __name__ == "__main__":
    debug_env()
I hope that this helps you and I'll be curios to hear what was the result for you.