Hi, how do I enable debug logging for boto+prefect...
# prefect-community
m
Hi, how do I enable debug logging for boto+prefect in my flow when running locally with
flow.run()
? I’ve tried adding this code from the boto3 docs to my flow:
Copy code
import boto3
boto3.set_stream_logger()  # sets logging.DEBUG
However, ^ that code hasn’t changed the
flow.run()
output. For background, I’m trying to use localstack as an AWS stand-in for local pipeline development. The
S3Download
task is giving me errors and I want to debug the boto3 connection to find out if the S3 service URL, bucket, and key are correct.
1
k
You probably need both:
Copy code
PREFECT__LOGGING__LEVEL=DEBUG
and
Copy code
PREFECT__LOGGING__EXTRA_LOGGERS="['boto3']"
as seen here
m
That appears to have worked for Prefect built-in debug logging, however I see no boto3 log output.
Does
PREFECT__LOGGING__EXTRA_LOGGERS
work for
flow.run()
?
k
How are you setting it? Command line or inside the Python script? It should
m
command line:
Copy code
❯ env PREFECT__LOGGING__LEVEL=DEBUG PREFECT__LOGGING__EXTRA_LOGGERS="['boto3']" poetry run python flows/main.py
k
what executor are you using?
m
The default, I think? My flow is trivial (redacted version follows):
Copy code
boto3.set_stream_logger()
boto_config = {'endpoint_url': "<https://localhost.localstack.cloud>", "verify": False}
download = S3Download(bucket="my-bucket", boto_kwargs=boto_config}

with Flow(name="my-flow") as flow:
   download(key="mydata.csv")

if __name__ == "__main__":
    flow.run()
[2022-07-05 17:50:07-0400] DEBUG - prefect.FlowRunner | Using executor type LocalExecutor
k
Can you try it if you do:
Copy code
import os
os['PREFECT__LOGGING__EXTRA_LOGGERS'] = "['boto3']"
in the script before importing prefect and see if that works?
If you don’t see it attached to the prefect logger though, you should at least be seeing the boto3 logs in the stdout. Do you see anything?
m
Nothing. The only active loggers are the prefect.TaskRunner and prefect.FlowRunner loggers
k
How about removing the Flow and just doing:
Copy code
S3Download(bucket="my-bucket", boto_kwargs=boto_config}).run()
directly so there is no prefect involved. do you see it then?
m
I know the
PREFECT__LOGGING__EXTRA_LOGGERS
envvar is set correctly, I verified that in the flow.
I placed your line above flow.run(). It raises the raw Python traceback. There are no logs at all.
Maybe boto has no logging for this stuff 😕
k
Maybe man if it’s not raised when you do that
But I don’t see anything
in the console
I’ll just use the PyCharm debugger and set a breakpoint in the boto request code
k
Maybe you can try adding a logger.info and seeing if it shows?
m
Oh cool, this example works as long as ‘mylogger’ is in the EXTRA_LOGGERS list
Copy code
import logging
    log = logging.getLogger('mylogger')
    <http://log.info|log.info>("MY LOGGER")

    S3Download(bucket="my-bucket", boto_kwargs=boto_config).run(key="mydata.csv")
    flow.run()
however I am still not getting anything from boto3
k
I am not sure how to get those out if they don’t even appear in the stdout when running the task.run manually without Prefect
m
Got it! The key was the
botocore
logger, not the
boto3
logger.
k
Oof ok lol.
Nice work!
m
Hey, I just followed the docs, they say
boto3
🤷 🙂
Thanks for all the help
👍 1