Kiran
08/20/2025, 12:12 PMMarvin
08/20/2025, 12:12 PMMarvin
08/20/2025, 12:14 PM@task
and executed within a @flow
- The flow run is connected to a Prefect API (Cloud or a running Server), so the run is tracked
If a task returns nothing, it will still appear with state, logs, and timing. You just won’t see a “result” value unless you return one and (optionally) persist results.
Tip:
- Use get_run_logger()
inside tasks to surface useful info in the UI logs.
- If you want something richer than logs, create artifacts (e.g., markdown) during the task.
Example:
from prefect import flow, task, get_run_logger
from prefect.artifacts import create_markdown_artifact
@task
def do_side_effects():
logger = get_run_logger()
<http://logger.info|logger.info>("I did a thing.")
create_markdown_artifact("# Task report\nAll done ✅", description="Run notes")
# no return
@flow
def my_flow():
do_side_effects()
if __name__ == "__main__":
my_flow()
If you want task return values visible across runs, configure result persistence (e.g., set result storage and/or PREFECT_RESULTS_PERSIST_BY_DEFAULT
):
https://docs-3.prefect.io/v3/advanced/results
If you’re not seeing your task in the UI, are you running it inside a flow and against a Prefect API?Kiran
08/25/2025, 12:10 PMMarvin
08/25/2025, 12:10 PMMarvin
08/25/2025, 12:12 PMservices:
postgres:
image: postgres:16
environment:
POSTGRES_DB: prefect
POSTGRES_USER: prefect
POSTGRES_PASSWORD: yourpassword
ports: ["5432:5432"]
postgres-exporter:
image: <http://quay.io/prometheuscommunity/postgres-exporter:v0.15.0|quay.io/prometheuscommunity/postgres-exporter:v0.15.0>
environment:
DATA_SOURCE_NAME: "<postgresql://prefect:yourpassword@postgres:5432/prefect?sslmode=disable>"
ports: ["9187:9187"]
depends_on: [postgres]
Prometheus scrape config
scrape_configs:
- job_name: 'postgres'
static_configs:
- targets: ['postgres-exporter:9187']
Kubernetes (Helm) option
- If you use Bitnami’s PostgreSQL chart, enable metrics:
--set metrics.enabled=true \
--set metrics.serviceMonitor.enabled=true
- Or deploy prometheus-postgres-exporter Helm chart and provide a connection secret.
If your goal is “Prefect metrics in Prometheus”
- There’s no built-in /metrics from Prefect 3 components today.
- Two common patterns:
- Instrument your flow code with the Prometheus Python client and either expose an HTTP endpoint from your runtime or push to a Pushgateway.
- prometheus_client and Pushgateway
- Rely on infrastructure metrics (K8s/Docker/EC2) in Prometheus and use Prefect’s event/alerting system for run-level status.
If you can share:
- Cloud vs self-hosted
- Where your Postgres lives (container, managed service, K8s)
- What specific metrics you want (DB health vs flow-run success rates)
…I can give a targeted config for your setup.