Skip to content

Commit

Permalink
Conditionally add OTEL events when processing executor events (#43558) (
Browse files Browse the repository at this point in the history
#43567)

It's possible that the start/end date are null when processing an
executor event, and there is no point in adding an OTEL event in that
case.

Before this, we'd try and convert `None` to nanoseconds and blow up the
scheduler.

Note: I don't think `queued_dttm` can be empty, but figured it didn't hurt to
guard against it just in case I've overlooked a way it can be possible.

(cherry picked from commit fe41e15)
  • Loading branch information
jedcunningham authored Oct 31, 2024
1 parent 842c60a commit c83e524
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions airflow/jobs/scheduler_job_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,9 +847,12 @@ def _process_executor_events(self, executor: BaseExecutor, session: Session) ->
span.set_attribute("ququed_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))
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))
if conf.has_option("traces", "otel_task_log_event") and conf.getboolean(
"traces", "otel_task_log_event"
):
Expand Down

0 comments on commit c83e524

Please sign in to comment.