Skip to content

Exceptions in task logs no longer contain source code #55910

Closed

Description

@NilsJPWerner

Apache Airflow version

3.0.6

If "Other Airflow 2 version" selected, which one?

No response

What happened?

Updated with better example

Airflow 3 no longer captures all the lines from an Exception. It seems like it displays part of the traceback but not the actual lines of code. This makes debugging difficult.

Image Image

What you think should happen instead?

No response

How to reproduce

from datetime import datetime

from airflow import DAG
from airflow.operators.python import PythonOperator

default_args = {
    "owner": "airflow",
    "depends_on_past": False,
    "start_date": datetime(2021, 6, 18),
    "retries": 0,
}

def failing_python_function():
    print("Things are going well!")
    raise Exception("Down bad rn")

def nested_function():
    failing_python_function()

def nested_function_2():
    nested_function()

with DAG(
    "test_error",
    default_args=default_args,
    schedule=None,
    catchup=False,
) as dag:
    PythonOperator(
        task_id="run_entrypoint",
        python_callable=nested_function_2,
    )

Operating System

Debian

Versions of Apache Airflow Providers

No response

Deployment

Astronomer

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. jroachgolf84 commented on Sep 21, 2025

    @jroachgolf84
    Collaborator

    Hmmm, those two screenshots that you included have different exceptions. The first (Airflow 2.X) looks like it is failing to fetch a Git repository. I was NOT able to reproduce this exception, and have not seen anything similar before. I'll leave this open in case someone else is able to reproduce.

  2. NilsJPWerner commented on Sep 22, 2025

    @NilsJPWerner
    ContributorAuthor

    I will try to create another replication.

  3. NilsJPWerner commented on Sep 22, 2025

    @NilsJPWerner
    ContributorAuthor

    Updated with better comparison.

    It seems like airflow 3 does not show the indented part of the exception frame that shows the contents of the line of code.

  4. changed the title [-]Exceptions are not logged properly[/-] [+]Exceptions in task logs no longer contain source code[/+] on Jan 15, 2026
  5. Venture200 commented on Jul 15, 2026

    @Venture200

    is there any update on it ? I am also experiencing same problem. No verbose content about Exception it shows -> ERROR - Task failed with exception. Version 3.1.8

  6. koleharv commented on Aug 17, 2026

    @koleharv
    Contributor

    This reproduces, and the cause looks structural rather than a formatting slip — it only affects deployments using JSON log output, which may be why it hasn't reproduced for everyone in this thread.

    Where the source lines go missing

    shared/logging/src/airflow_shared/logging/structlog.py builds the JSON branch's exception renderer from structlog's ExceptionDictTransformer:

    dict_exc_formatter = structlog.tracebacks.ExceptionDictTransformer(
        use_rich=False, show_locals=False, suppress=suppress
    )
    dict_tracebacks = structlog.processors.ExceptionRenderer(dict_exc_formatter)

    That transformer emits one dict per frame containing filename, lineno and name — and nothing else. There is no field carrying the source text of the line, so the rendered traceback can only ever show the frame headers, never the indented code line beneath them. Checked against structlog 26.1.0:

    use_rich=False -> frame keys = ['filename', 'lineno', 'name']
    use_rich=True  -> frame keys = ['filename', 'lineno', 'name']
    

    use_rich makes no difference here; both paths produce the same three keys.

    Why it's specific to JSON output

    The non-JSON branch of the same function uses structlog.dev.plain_traceback (or RichTracebackFormatter when DEV is set), and those go through traceback.print_exception, which pulls the source line via linecache. Both retain the code line. So the same failing task shows full tracebacks in text output and header-only tracebacks in JSON output.

    That matches the Airflow 2 → 3 change: the standard-library formatting that carried the source line is no longer on the path for structured logs.

    Question before anyone writes a patch

    Restoring the code line would mean carrying it per frame — for example a transformer that adds linecache.getline(filename, lineno) alongside the existing keys, with the UI rendering it under each frame. That does make every logged traceback bigger, and show_locals=False / use_rich=False suggest the current settings were chosen deliberately to keep structured logs compact.

    Is restoring parity with the text output something the project wants, and if so is a per-frame source field the right shape — or would you rather this stayed as is and the docs noted the difference? Happy to put up a PR once there's a direction.


    Drafted-by: Claude Code (Opus 5); reviewed by @Arose26 before posting

  7. souradeep07 commented on Oct 19, 2026

    @souradeep07
    Contributor

    I've opened #75100 for this, following the approach suggested above: each frame in the JSON traceback gets a line field (read via linecache, as the stdlib traceback module does), and the UI shows it under the frame.

    On the open questions:

    • Scope: this isn't limited to deployments that opt into JSON output. The task process always logs JSON to the supervisor, so every task log viewed in the UI is affected.
    • Size: it adds one stripped source line per frame, only when an exception is logged. Frames without available source are unchanged, and plain log lines are unaffected (the PR has a small benchmark).

    Happy to change the shape if maintainers would prefer something else.

  8. added a commit that references this issue on Oct 19, 2026
    ef7556c
  9. added a commit that references this issue on Oct 21, 2026
    79d3afc
  10. added a commit that references this issue on Oct 22, 2026
    37fcddf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions