José Duarte
08/29/2022, 4:07 PMprefect.exceptions.MissingContextError: Logger 'dystematic.pdbt.ftp' attempted to send logs to Orion without a flow run id. The Orion log handler can only send logs within flow run contexts unless the flow run id is manually provided.
This isn’t covered in the post nor the docs.
The reason I want to use the regular Python logs is because I cannot use the Prefect one when launching from the console as I get:
RuntimeError: There is no active flow or task run context.
Bianca Hoch
08/29/2022, 5:52 PMget_run_logger
. This article may be helpful for you.José Duarte
08/30/2022, 9:23 AMPREFECT_LOGGING_EXTRA_LOGGERS
variable (described in the blog post but not [explicitly] in the documentation), the flow runs fine but does not output logs
• If I do set the PREFECT_LOGGING_EXTRA_LOGGERS
variable to the package(s) I want to log, I will:
◦ Get the logs (as expected)
◦ A UserWarning
:
/Users/<REDACTED>/ftp.py:83: UserWarning: Logger 'dystematic.pdbt.ftp' attempted to send logs to Orion without a flow run id. The Orion log handler can only send logs within flow run contexts unless the flow run id is manually provided.
◦ On download of the second file, an error, which effectively stops the flow from progressing:
prefect.exceptions.MissingContextError: Logger 'dystematic.pdbt.ftp' attempted to send logs to Orion without a flow run id. The Orion log handler can only send logs within flow run contexts unless the flow run id is manually provided.
However:
• If I set the variable to PREFECT_LOGGING_EXTRA_LOGGERS = snowflake
, Snowflake’s logs work, and I doubt, their connector is importing Prefect’s get_run_logger
I’ve read:
• https://discourse.prefect.io/t/how-to-use-logging-in-prefect-a-tutorial-by-andrew-brookins/197/3
• https://www.prefect.io/guide/blog/logs-the-prefect-way/
• https://discourse.prefect.io/t/can-i-define-the-logger-globally/114
• https://orion-docs.prefect.io/concepts/logs/
Furthermore, it’s the second time I get sent an article and my issue is marked as “solved” (or whatever ✅ means) without any reply from me — I still need time to read, evaluate and test the solution offered in the article, marking the issue as “solved” does not help me nor anyone that might read it in the future.
cc’ing @Bianca Hoch @Jeff HaleAnna Geller
08/30/2022, 2:40 PMMissingContextError: Logger 'dystematic.pdbt.ftp' attempted to send logs to Orion without a flow run id.
This shows that you are using a non-Prefect logger. Could you try switching to Prefect logger this way?
from prefect import get_run_logger
logger = get_run_logger()
import prefect
from prefect import task, flow, get_run_logger
from prefect.logging.loggers import disable_run_logger
@task
def your_task():
logger = get_run_logger()
<http://logger.info|logger.info>("Prefect Version = %s", prefect.__version__)
@flow
def hi():
your_task()
if __name__ == "__main__":
with disable_run_logger():
your_task.fn()
José Duarte
08/30/2022, 2:54 PMAnna Geller
08/30/2022, 3:02 PM