Skip to main content

dag

Telemetry for background DAG wave and sweep outcomes.

Module​

Functions​

report_abandoned_thread​

def report_abandoned_thread(    *,    reason: str,    step_name: str | None,    thread_name: str | None,    elapsed_seconds: float | None,    task_hash: str | None,    project_id: str | None,    level: int = 30,) ‑> None:

Send an AbandonedThreadEvent at level. Never raises.

Arguments

  • reason: Why the run stopped waiting on the thread, e.g. "wave_timeout".
  • step_name: The step the thread runs, when known.
  • thread_name: The thread's name.
  • elapsed_seconds: How long the thread has been running.
  • task_hash: The run's task hash.
  • project_id: The run's project.
  • level: Severity, matching the log line the report accompanies. ERROR is a thread the run gave up on and ended without, which leaves it running on the machine: the run released its locks, so the site keeps working but this unit of work will not.

report_background_run_deferred​

def report_background_run_deferred(    *, task_hash: str, project_id: str, datasource_name: str, trigger: str,) ‑> None:

Send a BackgroundRunDeferredEvent for an unreachable root, at WARNING.

Never raises.

Arguments

  • task_hash: The (pod, datasource) task hash of the run.
  • project_id: The project the run belongs to.
  • datasource_name: The datasource the run would have processed.
  • trigger: Why the run was being started.

report_concurrency_slots_unleased​

def report_concurrency_slots_unleased(    limit_name: str, *, active_slots: int, leased_slots: int,) ‑> None:

Send a PrefectSlotsUnleasedEvent at WARNING. Never raises.

Arguments

  • limit_name: The concurrency limit whose slots were released.
  • active_slots: The slots it read as taken.
  • leased_slots: The slots the server's leases account for.

report_dag_run_progress​

def report_dag_run_progress(    *,    sequence: int,    elapsed_seconds: float,    loop_lag_seconds: float | None,    loop_lag_timed_out: bool,    emit_drift_seconds: float,    threads_alive: int | None,    task_hash: str | None = None,    project_id: str | None = None,    datasource_name: str | None = None,    trigger: str | None = None,    rss_bytes: int | None = None,    system_available_bytes: int | None = None,) ‑> None:

Send a DAGRunProgressEvent; WARNING when the loop probe timed out.

Never raises.

Arguments

  • sequence: This heartbeat's number within the run.
  • elapsed_seconds: Seconds since the heartbeat started.
  • loop_lag_seconds: How long the loop probe took to run.
  • loop_lag_timed_out: Whether the probe gave up waiting.
  • emit_drift_seconds: How late this heartbeat was against its schedule.
  • threads_alive: Threads alive in the process.
  • task_hash: The run's task hash.
  • project_id: The run's project.
  • datasource_name: The run's datasource.
  • trigger: Why the run was started.
  • rss_bytes: Process RSS when the heartbeat was sent.
  • system_available_bytes: System-available memory when it was sent.

report_dag_step​

def report_dag_step(    *,    phase: str,    step_name: str,    wave_index: int | None = None,    wave_attempt: int | None = None,    trigger: str | None = None,    task_hash: str | None = None,    duration_seconds: float | None = None,    exc: BaseException | None = None,    lock_wait_seconds: float = 0.0,    lock_name: str | None = None,    parallel: bool | None = None,    memory: StepMemorySummary | None = None,) ‑> None:

Send a DAGStepEvent for a step starting or ending. Never raises.

An "end" that a step raised to is sent at WARNING; everything else at INFO.

Arguments

  • phase: "start" or "end".
  • step_name: The step, as named in the DAG.
  • wave_index: The wave the step is running for, if the run is waved.
  • wave_attempt: The wave's attempt number, if the run is waved.
  • trigger: Why the run was started.
  • task_hash: The run-level task hash.
  • duration_seconds: How long the step ran, on "end".
  • exc: What the step raised, on an "end" that it raised to.
  • lock_wait_seconds: How long the step waited for its resource lock.
  • lock_name: The resource lock the step held, if any.
  • parallel: Whether the step is marked to run concurrently with others.
  • memory: The step's memory over its run, on "end".

report_dag_sweep​

def report_dag_sweep(    *,    dag_name: str,    waves_planned: int,    waves_banked: int,    waves_failed: int,    waves_unstarted: int,    duration_seconds: float,    stop_reason: str | None,) ‑> None:

Send a DAGSweepSummaryEvent; ERROR when every wave failed. Never raises.

Arguments

  • dag_name: The DAG that was run.
  • waves_planned: Waves the run planned.
  • waves_banked: Waves that completed.
  • waves_failed: Waves abandoned.
  • waves_unstarted: Waves left for a later run.
  • duration_seconds: How long the sweep took.
  • stop_reason: Why the loop stopped early, if it did.

report_dag_wave​

def report_dag_wave(    *,    dag_name: str,    outcome: str,    wave_index: int,    attempt: int,    attempts: int,    waves_planned: int,    files: int,    patient_count: int,    wave_kind: str,    duration_seconds: float,    prefect_subflow: bool,    exc: BaseException | None = None,) ‑> None:

Send a DAGWaveEvent for one ended wave attempt. Never raises.

Arguments

  • dag_name: The DAG being run.
  • outcome: "banked", "attempt_failed", "abandoned", or "stood_down" when the run stopped at the wave because its EHR step could not reach the EHR.
  • wave_index: The wave's position in its sweep.
  • attempt: This attempt's number.
  • attempts: Attempts the wave is allowed.
  • waves_planned: Waves the sweep planned.
  • files: Files in the wave.
  • patient_count: Distinct patients the wave's files belong to.
  • wave_kind: "first_carry", "refresh" or "orphan".
  • duration_seconds: How long the attempt took.
  • prefect_subflow: Whether the wave ran as its own Prefect subflow run.
  • exc: The failure, for a failed attempt.

report_lease_storage_in_memory​

def report_lease_storage_in_memory(lease_storage: str) ‑> None:

Send a PrefectLeaseStorageInMemoryEvent at ERROR. Never raises.

Arguments

  • lease_storage: The server's lease storage setting.

report_lock_lease_lost​

def report_lock_lease_lost(    *,    lock_name: str,    holder_run_id: str | None,    lease_duration_seconds: float | None,    held_seconds: float | None,) ‑> None:

Send a LockLeaseLostEvent at WARNING. Never raises.

Arguments

  • lock_name: The concurrency limit whose lease was lost.
  • holder_run_id: The flow run holding the slot, when known.
  • lease_duration_seconds: The lease duration the slot was taken with.
  • held_seconds: How long the slot had been held.

report_periodic_rerun_tick​

def report_periodic_rerun_tick(    *,    total_seconds: float,    phase_seconds: dict[str, float],    lineages: int,    submitted: int = 0,    machine_deferred: int = 0,    executing: int | None = None,    machine_limit: int = 0,    slow: bool = False,) ‑> None:

Send a PeriodicRerunTickEvent, at WARNING for a slow tick. Never raises.

Sent every tick: the machine counts it carries are what make a pod starved by its own work visible on a graph.

Arguments

  • total_seconds: How long the tick took.
  • phase_seconds: Time spent in each off-loop phase, by phase name.
  • lineages: Lineages the tick read from the cache.
  • submitted: Runs the tick admitted and scheduled.
  • machine_deferred: Submissions the machine held back.
  • executing: Background runs found executing, or None if uncounted.
  • machine_limit: background_dag_max_concurrent_runs, the limit the two counts were weighed against.
  • slow: Whether the tick outran its budget, so the event is raised to WARNING.

report_pod_resources​

def report_pod_resources(    *,    resources: ProcessResources,    cache_db_bytes: int | None = None,    cache_wal_bytes: int | None = None,    uptime_seconds: float | None = None,    dag_in_flight: bool | None = None,) ‑> None:

Send a PodResourcesEvent at INFO. Never raises.

Sent on the periodic tick rather than from a poller of its own, so a pod reports its size on the schedule it already runs on.

Arguments

  • resources: The pod process's memory, threads and open files.
  • cache_db_bytes: Size of the background cache's database file.
  • cache_wal_bytes: Size of that database's write-ahead log.
  • uptime_seconds: How long the pod's process has been running.
  • dag_in_flight: Whether a background DAG run is executing; None if that could not be counted.

report_prefect_migration​

def report_prefect_migration(    *,    deployments_cleared: list[str],    backlog_cancelled: int,    orphan_limits_deleted: list[str],    rerun_limit_deleted: bool,    limits_ensured: dict[str, int],    failed_steps: list[str],) ‑> None:

Send a PrefectMigrationEvent, at WARNING if a step failed. Never raises.

Arguments

  • deployments_cleared: Background deployments whose limit was removed.
  • backlog_cancelled: Superseded queued runs cancelled first.
  • orphan_limits_deleted: Orphaned deployment:<id> limits deleted.
  • rerun_limit_deleted: Whether background_dag_rerun was deleted.
  • limits_ensured: The pod-wide limits upserted, with their sizes.
  • failed_steps: Migration steps that raised.

report_rerun_gate​

def report_rerun_gate(    *,    gate: str,    project_id: str,    datasource_name: str,    occurrence: str,    level: int = 20,    detail: str | None = None,) ‑> None:

Send a BackgroundRerunGateEvent at level. Never raises.

Arguments

  • gate: Short name of the gate that held the lineage.
  • project_id: The lineage's project.
  • datasource_name: The lineage's datasource.
  • occurrence: The cron occurrence being acted on, ISO 8601.
  • level: Severity, matching the log line the gate writes.
  • detail: What the gate judged on, when its name does not say.

report_scan_sweep_gate_unreadable​

def report_scan_sweep_gate_unreadable(*, task_hash: str, exc: BaseException) ‑> None:

Send a ScanSweepGateUnreadableEvent at WARNING. Never raises.

Arguments

  • task_hash: The (pod, datasource) task hash.
  • exc: What the cache read raised.

report_task_definition_refresh​

def report_task_definition_refresh(    *,    outcome: "Literal['replaced', 'refused', 'failed']",    source: "Literal['fetch', 'message']",    project_id: str,    datasource_name: str,    task_hash: str,    hub_spec_hash: str,    stored_spec_hash: str | None,    dag_name_before: str | None,    dag_name_after: str | None = None,    error: BaseException | None = None,) ‑> None:

Send a TaskDefinitionRefreshEvent, at INFO if replaced, else ERROR.

Never raises.

Arguments

  • outcome: Whether the stored definition was replaced, the Hub's was refused, or applying it failed.
  • source: Whether the pod learned of the definition by message or fetch.
  • project_id: The project the lineage belongs to.
  • datasource_name: The datasource the lineage runs on.
  • task_hash: The (pod, datasource) task hash of the lineage.
  • hub_spec_hash: Hash of the definition the Hub served.
  • stored_spec_hash: Hash of the definition the pod held, if any.
  • dag_name_before: The DAG name of the stored definition, if any.
  • dag_name_after: The DAG name of the new definition, once applied.
  • error: The refusal or failure, if there was one.

report_update_hold​

def report_update_hold(    *,    phase: str,    flow_run_id: str | None,    reason: UpdateHoldReason | None = None,    waited_seconds: float | None = None,    held_seconds: float | None = None,    slots_held: int | None = None,    runs_refused: int | None = None,    metadata_runs_running: int | None = None,) ‑> None:

Send an UpdateHoldEvent; WARNING for a timed-out hold. Never raises.

Arguments

  • phase: ready or released.
  • flow_run_id: The hold's flow run.
  • reason: Why a released hold ended; None when ready.
  • waited_seconds: How long the hold waited for the machine.
  • held_seconds: How long a released hold held the machine once ready.
  • slots_held: How many machine slots the hold held.
  • runs_refused: Background runs the hold turned away before setup.
  • metadata_runs_running: Metadata runs running when the hold was ready.

report_wave_decoded_cache​

def report_wave_decoded_cache(    *,    outcome: str,    reason: str | None = None,    records_stored: int | None = None,    bytes_stored: int | None = None,    hits: int | None = None,    misses: int | None = None,    admission_stopped: str | None = None,    budget_bytes: int | None = None,    free_bytes_at_open: int | None = None,    lifetime_seconds: float | None = None,    cleanup_seconds: float | None = None,    orphans_deleted: int | None = None,    orphan_bytes_reclaimed: int | None = None,    orphans_failed: int | None = None,    location: str | None = None,) ‑> None:

Send a WaveDecodedCacheEvent for a wave's decoded-record cache.

Never raises. Logged at INFO for "closed" and at WARNING for "delete_failed". "unavailable" is a WARNING the first time this process reports a given reason and INFO after that, so a cache that can never open does not warn on every wave. No path or filename is carried.

Arguments

  • outcome: "closed", "delete_failed" or "unavailable".
  • reason: Why the cache was unavailable or its removal failed.
  • records_stored: Records written over the cache's lifetime.
  • bytes_stored: Bytes written over the cache's lifetime.
  • hits: Lookups served from the cache.
  • misses: Lookups the cache could not serve.
  • admission_stopped: Why the cache stopped admitting records, if it did.
  • budget_bytes: The disk budget the cache was given.
  • free_bytes_at_open: Free disk space when the cache was opened.
  • lifetime_seconds: How long the cache existed.
  • cleanup_seconds: How long removing the cache took.
  • orphans_deleted: Leftover caches deleted.
  • orphan_bytes_reclaimed: Bytes reclaimed by deleting them.
  • orphans_failed: Leftover caches that could not be deleted.
  • location: A coarse label for where the cache lived.

report_wave_plan_candidates_exhausted​

def report_wave_plan_candidates_exhausted(    *, dag_name: str, task_hash: str, project_id: str | None, files_exhausted: int,) ‑> None:

Send a WavePlanCandidatesExhaustedEvent at ERROR. Never raises.

Arguments

  • dag_name: The DAG that stood down.
  • task_hash: The (pod, datasource) task hash.
  • project_id: The lineage's project.
  • files_exhausted: Files left out for having reached the limit.

report_wave_plan_failed​

def report_wave_plan_failed(    *, dag_name: str, task_hash: str, project_id: str | None, exc: BaseException,) ‑> None:

Send a WavePlanFailedEvent at ERROR. Never raises.

Arguments

  • dag_name: The DAG whose run failed.
  • task_hash: The (pod, datasource) task hash.
  • project_id: The lineage's project.
  • exc: What planning raised.

report_wave_plan_no_scan_coverage​

def report_wave_plan_no_scan_coverage(    *, dag_name: str, task_hash: str, project_id: str | None, files_selected: int,) ‑> None:

Send a WavePlanNoScanCoverageEvent at ERROR. Never raises.

Arguments

  • dag_name: The DAG that stood down.
  • task_hash: The (pod, datasource) task hash.
  • project_id: The lineage's project.
  • files_selected: Files in the run's selection.