diff --git a/airflow-core/src/airflow/jobs/scheduler_job_runner.py b/airflow-core/src/airflow/jobs/scheduler_job_runner.py index f093a3e360776..981117c073339 100644 --- a/airflow-core/src/airflow/jobs/scheduler_job_runner.py +++ b/airflow-core/src/airflow/jobs/scheduler_job_runner.py @@ -283,7 +283,8 @@ def register_signals(self) -> ExitStack: def _exit_gracefully(self, signum: int, frame: FrameType | None) -> None: """Clean up processor_agent to avoid leaving orphan processes.""" - self._end_active_spans() + if self._is_tracing_enabled(): + self._end_active_spans() if not _is_parent_process(): # Only the parent process should perform the cleanup. @@ -1931,7 +1932,8 @@ def _schedule_dag_run( return callback if ( - dag_run.scheduled_by_job_id is not None + self._is_tracing_enabled() + and dag_run.scheduled_by_job_id is not None and dag_run.scheduled_by_job_id != self.job.id and self.active_spans.get(dag_run.run_id) is None ):