Hi there, Im following the quickstart tutorial usi...
# prefect-getting-started
e
Hi there, Im following the quickstart tutorial using the self hosted UI and I dont seem to be able to see any logs for my run, https://docs.prefect.io/2.14.3/getting-started/quickstart/#__tabbed_1_2:~:text=You%20should%20see%20lo[…]20UI%20that%20look%20similar%20to%20this%3A . All I see is
This run didn't generate Logs
could someone please help with how I can view the logs ? The version Im using is
prefect-2.14.3
t
hey Emma! You'll have to add an argument into the flow decorator. It'll look something like this:
*@flow*(log_prints=True)
e
Hi Tess, thanks for getting back. Yes I have that already, its in the code snippet of the quickstart.
@flow(name="Repo Info", log_prints=True)
Ive also noticed that if I run the script straight in the terminal without the
.serve
I don’t see any logs from prefect, nor the prints. ie removing the
.serve
here:
Copy code
if __name__ == "__main__":
  # create your first scheduled deployment
  repo_info()
and just running
python my_flow.py
I would have expected to see some logging in the terminal
t
Sorry, I should clarify -- what kind of logs are you hoping to see? The log_prints parameter is to view print statements in your code as logs. Also, would you be able to provide some sample code? Thanks!
e
Here is the code:
Copy code
import httpx
from prefect import flow, task


@task(retries=2)
def get_repo_info(repo_owner: str, repo_name: str):
    """Get info about a repo - will retry twice after failing"""
    url = f"<https://api.github.com/repos/{repo_owner}/{repo_name}>"
    api_response = httpx.get(url)
    api_response.raise_for_status()
    repo_info = api_response.json()
    return repo_info


@task
def get_contributors(repo_info: dict):
    contributors_url = repo_info["contributors_url"]
    response = httpx.get(contributors_url)
    response.raise_for_status()
    contributors = response.json()
    return contributors


@flow(name="Repo Info", log_prints=True)
def repo_info(repo_owner: str = "PrefectHQ", repo_name: str = "prefect"):
    """
    Given a GitHub repository, logs the number of stargazers
    and contributors for that repo.
    """
    repo_info = get_repo_info(repo_owner, repo_name)
    print(f"Stars 🌠 : {repo_info['stargazers_count']}")

    contributors = get_contributors(repo_info)
    print(f"Number of contributors πŸ‘·: {len(contributors)}")


if __name__ == "__main__":
    # create your first deployment
    repo_info.serve(name="my-first-deployment")
which is taken straight from: https://docs.prefect.io/latest/getting-started/quickstart/#step-3-write-a-flow and according to the same page, I expect to see:
Copy code
09:44:37.947 | INFO    | Flow run 'piquant-sawfly' - Downloading flow code from storage at '/my_path'
09:44:38.900 | INFO    | Flow run 'piquant-sawfly' - Created task run 'get_repo_info-0' for task 'get_repo_info'
09:44:38.901 | INFO    | Flow run 'piquant-sawfly' - Executing 'get_repo_info-0' immediately...
09:44:39.365 | INFO    | Task run 'get_repo_info-0' - Finished in state Completed()
09:44:39.385 | INFO    | Flow run 'piquant-sawfly' - Stars 🌠 : 12736
09:44:39.454 | INFO    | Flow run 'piquant-sawfly' - Created task run 'get_contributors-0' for task 'get_contributors'
09:44:39.454 | INFO    | Flow run 'piquant-sawfly' - Executing 'get_contributors-0' immediately...
09:44:40.411 | INFO    | Task run 'get_contributors-0' - Finished in state Completed()
09:44:40.414 | INFO    | Flow run 'piquant-sawfly' - Number of contributors πŸ‘·: 30
09:44:40.527 | INFO    | Flow run 'piquant-sawfly' - Finished in state Completed('All states completed.')
09:44:43.018 | INFO    | prefect.flow_runs.runner - Process 9867 exited cleanly.
which is here: https://docs.prefect.io/latest/getting-started/quickstart/#step-3-write-a-flow:~:text=You%20should%20s[…]20UI%20that%20look%20similar%20to%20this%3A
Instead what I see is:
t
Hmm odd. Ok, I think the next best thing is to do the following: 1. Create a new virtual environment with Prefect 2. Try the prefect cloud login again 3. re run the same script This will just ensure that there's nothing, by chance, in the background causing the logs to not appear.
e
Hi Tess. No success. Ive created a new virtual env and I still cant see any longs in the UI. Ive also tried running a flow directly in the terminal, and I do see some print statements, but no prefect logs INFO logs (Tried with this flow: https://docs.prefect.io/latest/tutorial/flows/#:~:text=Running%20this%20file%20interactively%20([…]ll%20result%20in%20some%20interesting%20output%3A) . Also, I’m not using prefect cloud, I’m using the self hosted server. Do you have any other ideas?
Is there any chance you / someone from the team could take a look a this with me via screen share? It’s making life pretty impossible trying to debug things without the logs or print statements. 😞
Ive found that if I install prefect==2.8.0 that I can see the logs:
Copy code
(prefect) emma@Emmas-MacBook-Pro ml-clause-labelling % python repo_info.py       
11:23:36.151 | INFO    | httpx - HTTP Request: GET <http://127.0.0.1:4200/api/health> "HTTP/1.1 200 OK"
11:23:36.158 | INFO    | httpx - HTTP Request: POST <http://127.0.0.1:4200/api/flows/> "HTTP/1.1 200 OK"
11:23:36.171 | INFO    | httpx - HTTP Request: POST <http://127.0.0.1:4200/api/flow_runs/> "HTTP/1.1 201 Created"
11:23:36.172 | INFO    | prefect.engine - Created flow run 'quantum-marmot' for flow 'get-repo-info'
11:23:36.177 | INFO    | httpx - HTTP Request: GET <http://127.0.0.1:4200/api/block_types/slug/local-file-system> "HTTP/1.1 200 OK"
11:23:36.181 | INFO    | httpx - HTTP Request: PATCH <http://127.0.0.1:4200/api/block_types/36c8a439-8621-4ae0-bc4b-1f11338d4048> "HTTP/1.1 204 No Content"
11:23:36.191 | INFO    | httpx - HTTP Request: GET <http://127.0.0.1:4200/api/block_schemas/checksum/sha256:6db1ab242e7b2b88a52dc137a7da3a373af63e0a103b9a91e060ed54a26f395a?version=2.8.0> "HTTP/1.1 404 Not Found"
11:23:36.201 | INFO    | httpx - HTTP Request: POST <http://127.0.0.1:4200/api/block_schemas/> "HTTP/1.1 201 Created"
11:23:36.220 | INFO    | httpx - HTTP Request: POST <http://127.0.0.1:4200/api/block_documents/> "HTTP/1.1 201 Created"
11:23:36.231 | INFO    | httpx - HTTP Request: POST <http://127.0.0.1:4200/api/flow_runs/5c03f069-06ce-4ab1-9652-1624236e08d4/set_state> "HTTP/1.1 201 Created"
11:23:36.237 | INFO    | httpx - HTTP Request: GET <http://127.0.0.1:4200/api/flow_runs/5c03f069-06ce-4ab1-9652-1624236e08d4> "HTTP/1.1 200 OK"
11:23:36.546 | INFO    | httpx - HTTP Request: GET <https://api.github.com/repos/PrefectHQ/prefect> "HTTP/1.1 200 OK"
PrefectHQ/prefect repository statistics πŸ€“:
Stars 🌠 : 13342
Forks 🍴 : 1374
11:23:36.584 | INFO    | httpx - HTTP Request: POST <http://127.0.0.1:4200/api/flow_runs/5c03f069-06ce-4ab1-9652-1624236e08d4/set_state> "HTTP/1.1 201 Created"
11:23:36.585 | INFO    | Flow run 'quantum-marmot' - Finished in state Completed()
11:23:36.605 | INFO    | httpx - HTTP Request: POST <http://127.0.0.1:4200/api/logs/> "HTTP/1.1 201 Created"
but as soon as I move to prefect 2.9.0 or later, I can only see the print statements:
Copy code
(prefect) emma@Emmas-MacBook-Pro ml-clause-labelling % python repo_info.py       
Overriding existing alarm handler <function _alarm_based_timeout.<locals>.sigalarm_to_error at 0x10aac9160>
PrefectHQ/prefect repository statistics πŸ€“:
Stars 🌠 : 13342
Forks 🍴 : 1374
Hey Tess, Ive resolved this. I had a
.prefect
directory locally which contained a logging.yml file, removing this revealed the logs.
t
Ah I’m glad it was resolved. Sorry you were dealing with that frustration. Had it persisted, we definitely could have figured something out!
πŸ™Œ 1