Skip to content

Go SDK: stop log attributes from displacing standard log fields - #73820

Merged
jason810496 merged 2 commits into
apache:mainfrom
henry3260:fix-go-sdk-log-standard-fields
Oct 24, 2026
Merged

jason810496 merged 2 commits into
apache:mainfrom
henry3260:fix-go-sdk-log-standard-fields

Conversation

@henry3260

@henry3260 henry3260 commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Why

SocketLogHandler.Handle builds one map per log line and writes the four
standard fields into it. event and timestamp went in before the user
attributes, so a user attribute of the same name overwrote them. level and
logger went in after the attributes and were unaffected.

event carries the message. The supervisor reads a task's log line out of that
key (msg = event.pop("event", None)), so a Dag logging an attribute called
event lost its message entirely, with nothing left in the emitted line to
show that a message had ever existed:

before   {"event":"row_batch_done","level":"info","timestamp":"2026-09-28T00:55:22..."}
after    {"event":"loaded 42 rows","level":"info","timestamp":"2026-09-28T13:02:15..."}

A displaced timestamp no longer breaks the supervisor — #74783 moves an
unparseable value to invalid_timestamp — but the line still loses the time it
was emitted at, and is stamped with the time the supervisor received it instead.

Letting the standard field simply win the slot would still discard a value the
caller asked to log. So on a clash the attribute is moved rather than dropped,
the way logrus resolves the same collision.

Rejecting the attribute outright, as structlog's TypeError does, is not
available here: slog discards a handler's error
(_ = l.Handler().Handle(ctx, r)), so returning one would drop the whole line,
and a panic would surface in production rather than fail fast at the call
site.

What

  • go-sdk/pkg/execution/logger.go — moveClashingAttrs re-keys an attribute
    occupying a standard field's slot to fields.<key> before the standard
    fields are written, so both values survive. The reserved keys are event,
    timestamp, level and logger. Only the exact top-level key is reserved,
    so a group's grp.event is left alone.
  • go-sdk/pkg/execution/logger_test.go —
    TestSocketLogHandlerMovesAttrsClashingWithStandardFields covers all four
    reserved keys, asserting the standard field's value, the attribute's value
    under fields.<key>, and that the reserved slot no longer holds the
    attribute. TestSocketLogHandlerStandardFieldsOverrideAttrs additionally
    pins where the displaced level and logger values go.

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5)

@fat-catTW

Copy link
Copy Markdown
Contributor

Nice work!

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SocketLogHandler.Handle builds one map per log line and writes the four standard
fields into it. event and timestamp went in before the user attributes, so a
user attribute of the same name overwrote them. level and logger went in
after the attributes and were unaffected.

Would it make more sense to keep the current behavior that if user explicitly set the "event" field themself, we should just keep it instead of overriding with the timestamp.

@henry3260

Copy link
Copy Markdown
Member Author

SocketLogHandler.Handle builds one map per log line and writes the four standard
fields into it. event and timestamp went in before the user attributes, so a
user attribute of the same name overwrote them. level and logger went in
after the attributes and were unaffected.

Would it make more sense to keep the current behavior that if user explicitly set the "event" field themself, we should just keep it instead of overriding with the timestamp.

For event , I don't think we can, because slog only has one place to put the message: it's the positional argument to logger.Info(...), and it goes out in the event key. The supervisor reads it back from there. So keeping the user's event doesn't just reorder a field, it drops the message the user wrote, with nothing left in the line
to show it existed. Python doesn't even allow this collision , structlog raises TypeError for logger.info("msg", event="x").

For timestamp, the supervisor decodes it with msgspec and that line sits outside the try/except that
guards malformed log lines, so a non-RFC3339 value raises there rather than just spoiling one line.

That said, you have a point that a value is dropped either way. Preserving both would mean renaming the colliding attribute instead of overwriting it, maybe we can follow the same way (logrus prefixes such keys with fields.), so a user attribute called event would surface as fields.event. Happy to do that in a follow-up.

A user attribute whose key collides with a standard field replaced that
field instead of losing to it. "event" is the one that hurts: the
supervisor takes a task's log line out of that key, so a Dag logging an
attribute called "event" lost its message entirely, with nothing left in
the line to show the message had ever existed. "timestamp" was displaced
the same way, leaving the supervisor a value it cannot decode as a
datetime.

"level" and "logger" were already immune, for no reason other than being
written after the attributes rather than before them.

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after adding the validation against the reserved fields, thanks for the fix!

Comment thread go-sdk/pkg/execution/logger_test.go Resolved
Letting the standard field win the slot still discarded a value the caller
asked to log. Reserving the slot and re-keying the attribute to
"fields.<key>" keeps both: the supervisor finds the message in "event" and
a parsable "timestamp", and the attribute survives under a name that
collides with nothing. logrus resolves the same clash the same way.

Rejecting the attribute outright, as structlog's TypeError does, is not
available here. slog discards a handler's error, so returning one would
drop the whole line, and a panic would surface in production rather than
fail fast at the call site.
@jason810496 jason810496 added the backport-to-v3-4-test Backport to v3-4-test label Oct 24, 2026
@jason810496 jason810496 added this to the Airflow 3.4.0 milestone Oct 24, 2026
@jason810496
jason810496 enabled auto-merge (squash) October 24, 2026 15:35
@jason810496

Copy link
Copy Markdown
Member

Just tried out the auto-merge feature, hope it works well :)

@jason810496
jason810496 merged commit 9761167 into apache:main Oct 24, 2026
81 checks passed
@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

henry3260 added a commit that referenced this pull request Oct 24, 2026
…fields (#73820) (#75564)

* Go SDK: stop log attributes from displacing standard log fields

A user attribute whose key collides with a standard field replaced that
field instead of losing to it. "event" is the one that hurts: the
supervisor takes a task's log line out of that key, so a Dag logging an
attribute called "event" lost its message entirely, with nothing left in
the line to show the message had ever existed. "timestamp" was displaced
the same way, leaving the supervisor a value it cannot decode as a
datetime.

"level" and "logger" were already immune, for no reason other than being
written after the attributes rather than before them.

* Move a clashing log attribute aside instead of overwriting it

Letting the standard field win the slot still discarded a value the caller
asked to log. Reserving the slot and re-keying the attribute to
"fields.<key>" keeps both: the supervisor finds the message in "event" and
a parsable "timestamp", and the attribute survives under a name that
collides with nothing. logrus resolves the same clash the same way.

Rejecting the attribute outright, as structlog's TypeError does, is not
available here. slog discards a handler's error, so returning one would
drop the whole line, and a panic would surface in production rather than
fail fast at the call site.
(cherry picked from commit 9761167)

Co-authored-by: Henry Chen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants