-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Description
There is currently no way to disable client-side event emission via configuration. The should_emit_events() function in src/prefect/events/worker.py hardcodes its logic based on PREFECT_API_URL and PREFECT_API_KEY:
def should_emit_events() -> bool:
return (
emit_events_to_cloud()
or should_emit_events_to_running_server()
or should_emit_events_to_ephemeral_server()
)When PREFECT_API_URL is set (which it always is for self-hosted Prefect), should_emit_events_to_running_server() returns True unconditionally. There is no env var or setting to override this.
Use Case
We run long-running ingest jobs (10+ hours) on a self-hosted Prefect server. We don't use Prefect's event-driven features (automations, triggers) — we only use flows, tasks, and concurrency limits. During transient server outages, the EventsWorker queue accumulates events without bound (see related: the queue is queue.Queue() with no maxsize), contributing to memory pressure in our worker pods.
Our current workaround is monkey-patching:
import prefect.events.utilities
prefect.events.utilities.should_emit_events = lambda: FalseThis works but relies on internal module structure and could break on any upgrade.
Proposed Solution
Add a PREFECT_EMIT_EVENTS (or PREFECT_CLIENT_EMIT_EVENTS) boolean setting that should_emit_events() checks first:
def should_emit_events() -> bool:
if not PREFECT_EMIT_EVENTS.value():
return False
return (
emit_events_to_cloud()
or should_emit_events_to_running_server()
or should_emit_events_to_ephemeral_server()
)Default: True (no behavior change). Setting PREFECT_EMIT_EVENTS=false would cleanly disable all client-side event emission.
Additional Context
The existing PREFECT_EVENTS_* settings (PREFECT_EVENTS_MAXIMUM_SIZE_BYTES, PREFECT_EVENTS_RETENTION_PERIOD, etc.) are all server-side settings. There are no client-side event settings today.
Happy to submit a PR for this.