Skip to content

Add PREFECT_CLIENT_EMIT_EVENTS setting to disable client-side event emission#21032

Open
zionts wants to merge 1 commit intoPrefectHQ:mainfrom
zionts:fix/emit-events-setting
Open

Add PREFECT_CLIENT_EMIT_EVENTS setting to disable client-side event emission#21032
zionts wants to merge 1 commit intoPrefectHQ:mainfrom
zionts:fix/emit-events-setting

Conversation

@zionts
Copy link

@zionts zionts commented Mar 9, 2026

Closes #21030

Summary

Adds a PREFECT_CLIENT_EMIT_EVENTS boolean setting that controls whether the client emits events to the Prefect server. Defaults to True (no behavior change).

Currently, should_emit_events() is hardcoded to return True whenever PREFECT_API_URL is set — there's no way to disable client-side event emission via configuration. This PR adds a clean opt-out for deployments that don't use event-driven features (automations, triggers).

Changes

  • src/prefect/settings/models/client.py — new emit_events field on ClientSettings with env var PREFECT_CLIENT_EMIT_EVENTS
  • src/prefect/events/worker.pyshould_emit_events() checks the setting first, short-circuiting before API URL/key checks
  • tests/events/client/test_emit_events_setting.py — 5 tests covering default behavior, override, and interaction with cloud config
  • tests/test_settings.py — added to parametrized settings validation

Usage

export PREFECT_CLIENT_EMIT_EVENTS=false

Or in Python:

from prefect.settings import temporary_settings, PREFECT_CLIENT_EMIT_EVENTS

with temporary_settings(updates={PREFECT_CLIENT_EMIT_EVENTS: False}):
    # Events are not emitted in this context
    ...

Checklist

…mission

Adds a new `client.emit_events` boolean setting (env var
`PREFECT_CLIENT_EMIT_EVENTS`) that controls whether the client emits
events to the Prefect server. Defaults to `True` (no behavior change).

When set to `False`, `should_emit_events()` short-circuits and returns
`False` before checking API URL/key configuration, preventing any events
from being created or queued.

This is useful for long-running flows that don't rely on event-driven
features (automations, triggers) and want to reduce memory usage from
the EventsWorker queue.

Closes PrefectHQ#21030
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 9, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing zionts:fix/emit-events-setting (2e5c260) with main (4fc6103)

Open in CodSpeed

Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a PR that we likely won't accept because large portions of Prefect rely on events being emitted client-side. In particular, task state changes are reported via events, so there would be no task observability with events turned off.

It seems this PR is motivated by other issues you were having with event emission, so let's see if we can find a different way to address them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PREFECT_EMIT_EVENTS setting to disable client-side event emission

2 participants