Skip to content

Show source code lines in task log tracebacks - #75100

Merged
bbovenzi merged 1 commit into
apache:mainfrom
souradeep07:fix-exception-source-lines
Oct 21, 2026
Merged

bbovenzi merged 1 commit into
apache:mainfrom
souradeep07:fix-exception-source-lines

Conversation

@souradeep07

Copy link
Copy Markdown
Contributor

Tracebacks in task logs show each frame's file, line number and function, but not the line of code that was running, unlike Airflow 2 or a plain Python traceback.

Task logs are always written as JSON, and structlog's ExceptionDictTransformer doesn't record source code for frames. This adds each frame's source line (via linecache, as the stdlib traceback module does) and shows it under the frame in the UI log view and in downloaded/copied logs.

closes: #55910

Before

before

After

after

Performance

JSON logging, median of 7 runs:

Before After
Plain log line (unaffected) 6.97 µs 7.05 µs
Exception with a 14-frame traceback 80 µs 111 µs

The extra cost is only paid when an exception is logged.

@boring-cyborg

boring-cyborg Bot commented Oct 19, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

structlog's ExceptionDictTransformer only records each frame's filename,
line number and function name, so tracebacks in task logs (which are always
written as JSON) no longer showed the line of code that was running. Add it
via linecache, as the stdlib traceback module does, and show it under each
frame in the UI log view.

closes: apache#55910
@souradeep07
souradeep07 force-pushed the fix-exception-source-lines branch from 9abff04 to ef7556c Compare October 19, 2026 14:21
@bbovenzi bbovenzi added the backport-to-v3-4-test Backport to v3-4-test label Oct 21, 2026
@bbovenzi bbovenzi added this to the Airflow 3.4.0 milestone Oct 21, 2026
@bbovenzi
bbovenzi merged commit 79d3afc into apache:main Oct 21, 2026
86 checks passed
@boring-cyborg

boring-cyborg Bot commented Oct 21, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-4-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
✅ v3-4-test PR Link

bbovenzi pushed a commit that referenced this pull request Oct 22, 2026
…75355)

structlog's ExceptionDictTransformer only records each frame's filename,
line number and function name, so tracebacks in task logs (which are always
written as JSON) no longer showed the line of code that was running. Add it
via linecache, as the stdlib traceback module does, and show it under each
frame in the UI log view.
(cherry picked from commit 79d3afc)


closes: #55910

Co-authored-by: Souradeep Biswas <30365437+souradeep07@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:logging area:UI Related to UI/UX. For Frontend Developers. backport-to-v3-4-test Backport to v3-4-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exceptions in task logs no longer contain source code

2 participants