Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions airflow/jobs/scheduler_job_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,35 +804,7 @@ def process_executor_events(
)

with Trace.start_span_from_taskinstance(ti=ti) as span:
span.set_attribute("category", "scheduler")
span.set_attribute("task_id", ti.task_id)
span.set_attribute("dag_id", ti.dag_id)
span.set_attribute("state", ti.state)
if ti.state == TaskInstanceState.FAILED:
span.set_attribute("error", True)
span.set_attribute("start_date", str(ti.start_date))
span.set_attribute("end_date", str(ti.end_date))
span.set_attribute("duration", ti.duration)
span.set_attribute("executor_config", str(ti.executor_config))
span.set_attribute("execution_date", str(ti.execution_date))
span.set_attribute("hostname", ti.hostname)
span.set_attribute("log_url", ti.log_url)
span.set_attribute("operator", str(ti.operator))
span.set_attribute("try_number", ti.try_number)
span.set_attribute("executor_state", state)
span.set_attribute("pool", ti.pool)
span.set_attribute("queue", ti.queue)
span.set_attribute("priority_weight", ti.priority_weight)
span.set_attribute("queued_dttm", str(ti.queued_dttm))
span.set_attribute("queued_by_job_id", ti.queued_by_job_id)
span.set_attribute("pid", ti.pid)
if span.is_recording():
if ti.queued_dttm:
span.add_event(name="queued", timestamp=datetime_to_nano(ti.queued_dttm))
if ti.start_date:
span.add_event(name="started", timestamp=datetime_to_nano(ti.start_date))
if ti.end_date:
span.add_event(name="ended", timestamp=datetime_to_nano(ti.end_date))
cls._set_span_attrs__process_executor_events(span, state, ti)
if conf.has_option("traces", "otel_task_log_event") and conf.getboolean(
"traces", "otel_task_log_event"
):
Expand Down Expand Up @@ -916,6 +888,35 @@ def process_executor_events(

return len(event_buffer)

@classmethod
def _set_span_attrs__process_executor_events(cls, span, state, ti):
span.set_attribute("category", "scheduler")
span.set_attribute("task_id", ti.task_id)
span.set_attribute("dag_id", ti.dag_id)
span.set_attribute("state", ti.state)
if ti.state == TaskInstanceState.FAILED:
span.set_attribute("error", True)
span.set_attribute("start_date", str(ti.start_date))
span.set_attribute("end_date", str(ti.end_date))
span.set_attribute("duration", ti.duration)
span.set_attribute("executor_config", str(ti.executor_config))
span.set_attribute("execution_date", str(ti.execution_date))
span.set_attribute("hostname", ti.hostname)
span.set_attribute("log_url", ti.log_url)
span.set_attribute("operator", str(ti.operator))
span.set_attribute("try_number", ti.try_number)
span.set_attribute("executor_state", state)
span.set_attribute("pool", ti.pool)
span.set_attribute("queue", ti.queue)
span.set_attribute("priority_weight", ti.priority_weight)
span.set_attribute("queued_dttm", str(ti.queued_dttm))
span.set_attribute("queued_by_job_id", ti.queued_by_job_id)
span.set_attribute("pid", ti.pid)
if span.is_recording():
span.add_event(name="queued", timestamp=datetime_to_nano(ti.queued_dttm))
span.add_event(name="started", timestamp=datetime_to_nano(ti.start_date))
span.add_event(name="ended", timestamp=datetime_to_nano(ti.end_date))

def _execute(self) -> int | None:
from airflow.dag_processing.manager import DagFileProcessorAgent

Expand Down
6 changes: 4 additions & 2 deletions airflow/utils/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
}


def datetime_to_nano(datetime) -> int:
def datetime_to_nano(datetime) -> int | None:
"""Convert datetime to nanoseconds."""
return int(datetime.timestamp() * 1000000000)
if datetime:
return int(datetime.timestamp() * 1000000000)
return None