Hello! I'm prototyping Prefect with ControlFlow fo...
# prefect-getting-started
m
Hello! I'm prototyping Prefect with ControlFlow for potentially full adoption on my team. I have a local server running for testing and some flows written that I'm messing around with deploying. I'm starting to get the hang of it, but am struggling with logging... I went through these docs and tried both
print
with
@flow(log_prints=True)
and using the
get_run_logger()
object and using that, but no matter what I never see anything in the logs in the UI. I can see the prints coming through in the worker stdout but just can't manage to get anything to show in the UI besides the "Opening process" and "Submission completed" (screenshot attached). My task and flow definition is below (leaving out the agent definitions)... wondering if anyone has tips on how to get some of these to show up in the UI logs.
Untitled.py
(also tried with
@flow(log_prints=True)
)
Also if this is not the right channel for this question please let me know 🙂
Bumping this to see if anyone has any tips about logging/seeing logs in the Prefect ui 🙂
n
hi @MikeT !
hrm what does
prefect config view
show for you?
m
Hi Nate!
This is what it's showing for me:
Copy code
❯ prefect config view
PREFECT_PROFILE='ephemeral'
PREFECT_API_URL='<http://0.0.0.0:4200/api>' (from profile)
PREFECT_SERVER_ALLOW_EPHEMERAL_MODE='True' (from profile)
I'm running my server with docker-compose, this is the yaml I made for that:
Copy code
services:
  db:
    image:  postgres:latest
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: yourTopSecretPassword
      POSTGRES_DB: prefect
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"

  prefect:
    image:  prefecthq/prefect:3.0.0rc20-python3.11-conda
    depends_on:
      - db
    environment:
      PREFECT_API_DATABASE_CONNECTION_URL: "<postgresql+asyncpg://postgres:yourTopSecretPassword@db:5432/prefect>"
      PREFECT_API_URL: "<http://localhost:4200/api>"
      PREFECT_SERVER_API_HOST: "0.0.0.0"
    ports:
      - "4200:4200"
    command: prefect server start

volumes:
  postgres_data:
n
if you were to run a simple flow like this from the same place you try your cf flow
Copy code
from prefect import flow

@flow(log_prints=True)
def f(): print('hi')

f()
does that log show up in the UI for you?
m
Giving that a shot now. My environment got into a little bit of a wonky state so getting it working again.
n
👍 yeah im thinking if you cant see that simple log its probably a config thing and if you can it might be an issue with controlflow's logging interaction with prefect
aha so you'll want set
PREFECT_LOGGING_LEVEL=INFO
where you're running controlflow https://github.com/PrefectHQ/ControlFlow/blob/main/src/controlflow/settings.py#L98-L102
here's a working example w docker-compose and
controlflow
running in a simple api
Copy code
docker compose up -d --build

» curl -X POST "<http://localhost:8000/chat?message=Your%20message%20here>"
Copy code
# api.py

@flow(log_prints=True)
async def handle_message(message: str):
    result = await cf.run_async(
        message, result_type=Annotated[str, Field(description="sPoNgEbOb MoCkInG tExT")]
    )
    print(result)


@app.post("/chat")
async def chat(message: str):
    asyncio.create_task(handle_message(message))
    return {"message": "Message received"}
m
I was able to get the sample prefect flow to show some prints, but not in controlflow. The
flow
you import from controlflow does not accept
log_prints=True
. I'm wondering what the difference is between these classes and how to log with them. My environment ended up getting wonky in the process of testing though and I need to clean wipe it and rebuild, which will also let me grab all the newest 3.0 stuff (i was using 3.0rcX builds - if that matters)
n
it shouldn’t matter too much on the rc versions vs the standard 3.0.0 but yeah log_prints=True is a prefect flow thing
👍 1
they’re similar in nature, in that they’re both intended to compose more atomic pieces of work, but the prefect flow is more general, you can stick normal python / prefect stuff / controlflow stuff inside whereas controlflow flows are specifically for encapsulating / configuring controlflow stuff in that scope
m
That's what I figured. I wasn't sure exactly, but I think some of my controlflow stuff wasn't running when I used a prefect flow? I could be wrong though, the lack of logging was making it difficult to know
Like I said, I'll rebuild my environment and build up my example a little more piece-meal and see how it goes
👍 1
I appreciate all your support!
catjam 1