Skip to content

fix(integrations): stop using mrkdwn formatting inside Slack link labels - #124244

Open
parh0m2007 wants to merge 1 commit into
getsentry:masterfrom
parh0m2007:fix/slack-link-formatting
Open

fix(integrations): stop using mrkdwn formatting inside Slack link labels#124244
parh0m2007 wants to merge 1 commit into
getsentry:masterfrom
parh0m2007:fix/slack-link-formatting

Conversation

@parh0m2007

Copy link
Copy Markdown

Problem

Two related bugs, both rooted in the <url|*bold label*> pattern used by Sentry's Slack message builders:

  1. Bold inside link labels breaks Slack mobile (Slack alert notifications render as plain text on mobile (Android) due to bold formatting inside links #109694) — On Slack for Android, alert titles render as plain text instead of clickable links. Slack support confirmed this is a known mobile bug triggered by mrkdwn formatting (e.g. *...*) inside a link label; their recommended workaround is to use <url|text> without inline formatting.

  2. Newlines in labels break the link syntax everywhere (Slack notifications: feedback issue titles containing newlines render as raw mrkdwn instead of a link #121520) — User feedback messages can contain line breaks, and the feedback issue title ("User Feedback: ") becomes the notification link label. Slack only parses the <url|label> syntax when the label is on a single line, so the whole message renders as literal mrkdwn text and nothing is clickable. Affects issue alerts, metric alerts, incident alerts, and notification digests.

Closes #109694
Closes #121520

Solution

Add escape_slack_link_label() in src/sentry/integrations/slack/utils/escape.py: applies escape_slack_text and collapses newline runs into single spaces (per the fix suggested in #121520).

Use it for plain (unformatted) labels everywhere a <url|label> link is built:

  • message_builder/issues.py — issue alert titles (also fixes the newline case)
  • message_builder/notifications/base.py — generic notifications (metric alerts, digests, activity notifications)
  • message_builder/incidents.py — incident alert fallback text
  • notifications/platform/slack/renderers/metric_alert.py — new-platform metric alert fallback text

Emojis and standalone bold text outside links are unchanged; only formatting inside link labels is dropped.

Recipes

  • Issue alert with a single-line title → <url|title> renders as a clickable link (bold visual change is acceptable per Slack's own recommendation)
  • Issue alert with a multiline feedback title → label collapses to one line, link parses, message is clickable (previously nothing was clickable)
  • Metric/incident alerts and digests now use plain labels too

Evidence

  • Updated all affected assertions in tests/sentry/integrations/slack/** and tests/sentry/notifications/platform/slack/**
  • ruff check and ruff format --check pass on all touched files
  • Note: I could not run the Python test suite locally (the pinned orjson wheel in Sentry's devpi index targets macOS 15+; this machine is macOS 14). CI should confirm — happy to address any failures.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Slack only parses the <url|label> link syntax when the label sits on a
single line, and inline mrkdwn formatting (e.g. *bold*) inside the label
is not rendered by some clients — notably Slack mobile, where alert
titles render as plain text instead of links. Titles may also contain
newlines (e.g. multiline user feedback becomes an issue title), which
renders the whole message as literal mrkdwn text.

Add escape_slack_link_label() which escapes text and collapses newlines,
and use plain labels everywhere a <url|label> link is built: issue
alerts, generic notifications, and incident/metric alerts.

Fixes getsentry#109694
Fixes getsentry#121520
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

1 participant