Skip to content

fix(Discord): Move message content to embed description field#529

Open
chernistry wants to merge 2 commits intografana:mainfrom
chernistry:fix/discord-embed-field-order
Open

fix(Discord): Move message content to embed description field#529
chernistry wants to merge 2 commits intografana:mainfrom
chernistry:fix/discord-embed-field-order

Conversation

@chernistry
Copy link
Copy Markdown

@chernistry chernistry commented Apr 6, 2026

What this PR does

Fixes the Discord notification formatting where the alert message text appears above the embed title instead of below it.

The root cause is that the v1 Discord notifier places the message in the webhook's top-level content field, which Discord renders above all embeds. The fix moves the message to the embed's description field, which renders below the title within the embed -- matching the behavior of Slack and other notification channels.

Changes

  • Added Description field to discordLinkEmbed struct
  • Message content is now placed in linkEmbed.Description instead of msg.Content
  • Truncation limit updated from 2000 (content field limit) to 4096 (embed description limit per Discord docs)
  • Tests updated to reflect the new payload structure

Before

[Message content appears here, above the embed]
┌─────────────────────────┐
│ Title                   │
│ Footer                  │
└─────────────────────────┘

After

┌─────────────────────────┐
│ Title                   │
│ Message content here    │
│ Footer                  │
└─────────────────────────┘

Note: The v0mimir1 Discord notifier already uses Description correctly. This fix aligns v1 with the same pattern.

Which issue(s) this PR fixes

Fixes grafana/grafana#86565

Checklist

  • Tests updated and passing
  • Follows existing code patterns (matches v0mimir1 behavior)

Note

Medium Risk
Moderate risk because it changes the Discord webhook payload structure and truncation limits, which can affect message rendering and any consumers expecting content to be populated.

Overview
Discord v1 notifications now render the alert message inside the embed by adding an embed description field and populating it with the templated message, leaving top-level content empty so text no longer appears above the title.

Message truncation is updated to Discord’s embed description limit (4096 runes), and tests are adjusted (including image/embedded quota cases) to assert the new payload shape and truncation behavior.

Reviewed by Cursor Bugbot for commit 41901d4. Bugbot is set up for automated code reviews on this repo. Configure here.

The Discord notifier was placing the alert message in the webhook's
top-level content field, which renders above the embed. This caused
the message text to appear above the title instead of below it.

Move the message to the embed's description field so it renders
below the title within the embed, matching the behavior of other
notification channels like Slack.

Also increases the truncation limit from 2000 (content limit) to
4096 (embed description limit) per Discord API documentation.

Fixes grafana/grafana#86565
@chernistry chernistry requested a review from a team as a code owner April 6, 2026 18:15
@github-project-automation github-project-automation bot moved this to In review in Alerting Apr 6, 2026
@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Apr 6, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit c50833f. Configure here.

tmplErr = nil
}
truncatedMsg, truncated := receivers.TruncateInRunes(msg.Content, discordMaxMessageLen)
messageText, truncated := receivers.TruncateInRunes(messageText, discordMaxDescriptionLen)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Embed total may exceed Discord's 6000 character limit

Medium Severity

Moving the message from the top-level content field (which doesn't count toward embed limits) into the embed Description field (which does) means the message text now contributes to Discord's 6000-character total across all embeds. With discordMaxDescriptionLen at 4096, plus discordMaxTitleLen at 256, footer text, and up to 9 image embed titles (each up to 256 chars), the theoretical maximum is ~6681 characters — exceeding 6000. Discord will reject such messages. Previously, the content field was outside embeds so this limit couldn't be hit.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c50833f. Configure here.

- Remove dead constant discordMaxMessageLen (no longer referenced
  after truncation switched to discordMaxDescriptionLen)
- Add comment explaining why the 6000-char total embed limit is safe:
  title (256) + description (4096) + footer (~30) < 6000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Alerting: Discord alert message is above the title

1 participant