Sort event metadata in notifications - #1369
Open
artur-chopikian wants to merge 1 commit into
Open
Conversation
artur-chopikian
marked this pull request as ready for review
August 11, 2026 07:30
Notification fields are built by ranging over event.Metadata. Go randomises map iteration, so the same event produces a different field order on every send and the value being looked for moves between messages. Iterating slices.Sorted(maps.Keys(...)) makes the order stable and alphabetical. slices is already used in this package and the module is on Go 1.26, so no helper is needed. teams.go already does this for its Adaptive Card payload, sorting the built facts with slices.SortFunc. The guarantee existed but was not applied elsewhere, including to the deprecated connector payload in the same file. Applied to the notifiers whose output is read in order: slack, discord, rocket, teams, google_chat, zoom, webex, grafana, lark, matrix, telegram. The iterate-sorted-keys form is used throughout because five of them concatenate strings and cannot be sorted after the fact. Not applied to incidentio and sentry, where metadata goes into a map and order cannot be observed, nor to datadog and otel, where tags and attributes are sets. Signed-off-by: Artur Chopikian <arturchopikian@gmail.com> Assisted-by: claude-code/claude-opus-5
artur-chopikian
force-pushed
the
fix/sort-event-metadata-fields
branch
from
August 11, 2026 07:33
d45c315 to
376eefe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Notification fields are built by ranging over
event.Metadata. Go randomises map iteration, so the same event produces a different field order on every send:Same four keys, two orders, seconds apart. The value being looked for moves between messages.
teams.goalready sorts its Adaptive Card facts withslices.SortFunc, so the guarantee exists — it was not applied elsewhere, including to the deprecated connector payload in the same file.Applied to the notifiers whose output is read in order: slack, discord, rocket, teams, google_chat, zoom, webex, grafana, lark, matrix, telegram. The iterate-sorted-keys form is used throughout because five of them concatenate strings and cannot be sorted afterwards.
Not applied to incidentio and sentry, where metadata goes into a map, nor to datadog and otel, where tags and attributes are sets.
TestSlack_PostFieldsAreSortedposts one event ten times and asserts the order each time. It fails on main.make tidy fmt vetandmake testpass, working tree clean.