Skip to content

Emit OpenLineage events for asset watcher asset events - #76773

Draft
kacpermuda wants to merge 8 commits into
apache:mainfrom
kacpermuda:ol-asset-watcher-events
Draft

kacpermuda wants to merge 8 commits into
apache:mainfrom
kacpermuda:ol-asset-watcher-events

Conversation

@kacpermuda

@kacpermuda kacpermuda commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Asset events created by asset watchers in the triggerer (Airflow 3.2+) were invisible to OpenLineage. Asset events produced by a task are already reported as outputs of that task's own run, but a watcher-produced event has no task run to attach to.

This implements the on_asset_event_emitted listener hook in the OpenLineage provider:

  • An event is treated as a watcher event when Airflow names its source watcher. On Airflow versions that don't, the provider falls back to: no source task, from_trigger in extra, and not created through the REST API.

  • Each watcher event emits a START and COMPLETE pair for the job asset_watcher.<asset name> (job type ASSET_WATCHER), with the asset translated to an OpenLineage dataset as the output. All watchers of an asset share one job, so the job name is the same on every Airflow version. Each of the two events gets its own job, run, facet and dataset objects.

  • An asset that can't be translated to an OpenLineage dataset is still reported, without outputs; its URI is in the facet.

  • A new airflowAssetEvent run facet, with a schema listing every key:

    • the asset: name, uri, group and extra, and its id when Airflow passes it;
    • the event: extra (with the trigger payload) and source aliases, and its id, partition key and date when available;
    • the event's source: a type (ASSET_WATCHER here, matching the job type), plus the watcher name and trigger classpath when Airflow passes them.

    The facet, run id and adapter method aren't specific to watchers, so events created through the REST API can later reuse them with a new source type.

  • When Airflow passes the asset event id and timestamp (Expose asset event id and source watcher to asset listeners #76750), the run id is the same for every send of an event, and the event time is the stored event time. Older versions get a uuid7 run id and the current time.

  • Emission policy: only global rules apply, since these events have no Dag, task, operator or hook.

    • The new emit_asset_watcher_events control turns them off. Like emit_task_events and emit_dag_events, it beats emit within a rule.
    • emit: false suppresses them.
    • exclude_datasets is matched against the asset. When it matches, the events are skipped altogether, because their facet names the asset.
    • The legacy selective_enable suppresses them too.

Manual state changes. The policy so far could turn events off on the scheduler and workers, but not those the API server sends when a user sets a task or Dag run state.

  • The new emit_manual_state_change_events control turns them off, globally or per Dag or task. An event is sent only if both this control and the usual emit resolution allow it, and per-Dag or per-task settings in Dag code can't turn them back on.
  • Behaviour change: task states changed by hand used to skip the emission policy on the API server, which has no task objects, so their events were always sent. They are now resolved with the global, dag_id and dag_id + task_id rules; operator rules, per-Dag or per-task settings in Dag code, and legacy options need the task, so they are skipped.
  • A task failure counts as manual only when it carries the error the API server passes ("TaskInstance's state was manually set to …", on every Airflow 3 version), since the scheduler also fails task instances without their task, e.g. when it can't load the serialized Dag.
  • Dag run states set by hand are only recognized on Airflow 3.3.1+. Older API servers report them with the same empty message the scheduler uses for a Dag run that timed out. The docs say so.

Triggerer safety. The hook runs on the triggerer's main loop, inside the transaction that records the asset change, so a dropped event is preferred to any impact on the triggerer:

  • Whether these events are on is decided once per process: when the policy turns them off, or the queue size is 0, negative or invalid, the hook logs that once and returns for every later event, creating no queue, thread or client.
  • Otherwise it only does cheap checks, then a non-blocking put_nowait onto a bounded queue. The new [openlineage] asset_watcher_event_queue_size sets its size (default 100). There is no unbounded mode, as each waiting event holds its trigger payload.
  • A single daemon thread, started with the queue, resolves the dataset exclusions, builds the events and sends them with its own adapter. While no events arrive it sleeps without waking up. A slow or broken transport can only fill the queue; after that, events are dropped. The main loop only counts drops and never logs per event; the thread logs the total a minute after the first drop. A forked process builds its own queue and thread.
  • If the thread can't start, these events are turned off for the process with one warning. Nothing the emission raises can end the thread. Events still waiting when the triggerer stops are counted in a log line.
  • An asset whose URI can't be normalized in the triggerer, e.g. when it has other providers than the Dag processor, is reported without outputs rather than dropped.
  • The thread never delays shutdown, and the hook can't raise.

Tests.

  • Unit tests cover the hook, the emitter thread, the adapter, the helpers (with and without the fields from Expose asset event id and source watcher to asset listeners #76750) and the emission policy.
  • New OpenLineage e2e Dags:
    • Two watchers on one asset, told apart by the trigger payload on every Airflow version.
    • A trigger shared by two assets.
    • An asset OpenLineage can't translate (https://).
    • An asset excluded by the deployment's global exclude_datasets rule.
    • A task outlet and a REST-created asset event (with from_trigger in extra), neither of which may produce watcher events.
    • A partitioned watcher event that starts a partitioned run of another Dag, on Airflow 3.5+.
  • A new e2e Dag changes task and Dag run states through the REST API under emit_manual_state_change_events and emit_task_events rules.
  • The run id integrity check of the system tests now also covers ASSET_WATCHER runs. A new unfinished_start_keys option lets it accept a START whose COMPLETE the policy suppresses.
  • The e2e assets use no URI scheme of a provider the e2e deployment may not have.
  • The compat e2e image now reinstalls the provider wheels under test even when the base image has a provider of the same version. Before, the 3.4.0 run kept the released OpenLineage provider.
  • The Spark utils tests no longer depend on the local timezone.

Depends on #76750 (passes the event id, timestamp and source watcher to listeners) and #76982 (fixes wrong watcher names for assets sharing a trigger, which these e2e tests found). Both are expected to merge first: the 3.5+ expected events require the watcher fields. The OpenLineage e2e suite passed locally on main with both applied, and on Airflow 3.0.6, 3.1.8, 3.2.2, 3.3.2 and 3.4.0.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5.5)

Generated-by: Claude Code (Opus 5.5) following the guidelines

🤖 Generated with Claude Code

kacpermuda and others added 8 commits November 18, 2026 17:52
Asset events created by asset watchers in the triggerer were invisible to
OpenLineage: task-produced asset events are reported as outputs of the
task's own run, but watcher-produced ones have no task run to attach to.
Reporting them as a START/COMPLETE run pair of a dedicated asset watcher
job makes external asset changes visible in lineage.

Emission happens off the triggerer's main loop on a bounded, best-effort
queue, so a slow or failing transport can only drop events and never
block or break the triggerer.

Co-Authored-By: Claude <noreply@anthropic.com>
Asset watcher events ignored the admin emission policy, so a global
emit: false or exclude_datasets rule did not stop them. They also lacked
end-to-end coverage for the cases that matter in a deployment: several
watchers on one asset, a trigger shared by two assets, events from tasks
or the REST API that must not be reported, partitions, and excluded
assets.

When Airflow passes the asset event id and timestamp, the run id is now
stable across sends and the event time matches the stored event; older
versions keep the previous fallback.

Co-Authored-By: Claude <noreply@anthropic.com>
Deployment managers could turn off OpenLineage events on the scheduler
and workers, but not those sent from the triggerer for asset watchers or
from the API server when a user changes a state. The API server also
ignored the emission policy for task states changed by hand, so even
`emit: false` for a Dag did not stop those events.

Co-Authored-By: Claude <noreply@anthropic.com>
Deployments that turn asset watcher events off should not keep any
OpenLineage machinery in the triggerer, and the size of the queue of
waiting events must be up to them. The two events of an asset event
shared their objects, which earlier caused facets to leak between
events, and assets that can't be translated to a dataset were not
covered end to end.

Older Airflow versions report Dag run states set by hand with the same
empty message as a Dag run that timed out, so those are only recognized
from Airflow 3.3.1. The OpenLineage compat e2e image kept the released
provider when it had the same version as the one under test, so those
runs did not test the provider's code.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
The watcher name and trigger classpath move into a nested `source` object
with a `type`, which matches the job type, so asset events created through
the REST API can later reuse the same facet, run id and adapter method with a
new source type instead of a parallel set.

Co-Authored-By: Claude <noreply@anthropic.com>
@kacpermuda
kacpermuda force-pushed the ol-asset-watcher-events branch from 34c4be6 to e286cec Compare November 18, 2026 16:53

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant