Skip to content

Commit c12e628

Browse files
jedcunninghamutkarsharma2
authored andcommitted
Conditionally add OTEL events when processing executor events (#43558) (#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) (cherry picked from commit c83e524)
1 parent 898f332 commit c12e628

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

airflow/jobs/scheduler_job_runner.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,12 @@ def _process_executor_events(self, executor: BaseExecutor, session: Session) ->
847847
span.set_attribute("ququed_by_job_id", ti.queued_by_job_id)
848848
span.set_attribute("pid", ti.pid)
849849
if span.is_recording():
850-
span.add_event(name="queued", timestamp=datetime_to_nano(ti.queued_dttm))
851-
span.add_event(name="started", timestamp=datetime_to_nano(ti.start_date))
852-
span.add_event(name="ended", timestamp=datetime_to_nano(ti.end_date))
850+
if ti.queued_dttm:
851+
span.add_event(name="queued", timestamp=datetime_to_nano(ti.queued_dttm))
852+
if ti.start_date:
853+
span.add_event(name="started", timestamp=datetime_to_nano(ti.start_date))
854+
if ti.end_date:
855+
span.add_event(name="ended", timestamp=datetime_to_nano(ti.end_date))
853856
if conf.has_option("traces", "otel_task_log_event") and conf.getboolean(
854857
"traces", "otel_task_log_event"
855858
):

0 commit comments

Comments
 (0)