:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(alerts): link alert messages to the alert and name the source (#114179)
Jimmy Zhud85ee8116cc8
diff --git a/products/alerts_platform/backend/delivery/discord.py b/products/alerts_platform/backend/delivery/discord.pyindex f26a46591788..71ee7c1503cc 100644--- a/products/alerts_platform/backend/delivery/discord.py+++ b/products/alerts_platform/backend/delivery/discord.py@@ -32,16 +32,21 @@ def escape_markdown(text: str) -> str:def content_for(message: AlertMessage) -> str:+ link = f"\n\n[View alert](<{message.alert_url}>)"+ return _body(message, MAX_CONTENT_CHARS - len(link)) + link+++def _body(message: AlertMessage, limit: int) -> str:headline = f"**{escape_markdown(message.headline)}**"lines = [f"**{detail.label}:** {escape_markdown(detail.value)}" for detail in message.details]if not lines:return headline- content = f"{headline}\n\n" + "\n".join(lines)- if len(content) <= MAX_CONTENT_CHARS:- return content+ body = f"{headline}\n\n" + "\n".join(lines)+ if len(body) <= limit:+ return body# An error message can carry a whole query, so it is a detail that overflows. Each detail gets# an equal share, so clipping the error cannot drop the failure count after it.- share = (MAX_CONTENT_CHARS - len(headline) - 2 - (len(lines) - 1)) // len(lines)+ share = (limit - len(headline) - 2 - (len(lines) - 1)) // len(lines)return f"{headline}\n\n" + "\n".join(clip_text(line, share) for line in lines)diff --git a/products/alerts_platform/backend/delivery/dispatch.py b/products/alerts_platform/backend/delivery/dispatch.pyindex 2a6ea610c1b7..498a41e15d2e 100644--- a/products/alerts_platform/backend/delivery/dispatch.py+++ b/products/alerts_platform/backend/delivery/dispatch.py@@ -44,7 +44,7 @@ def deliver(team_id=team_id,configuration_id=configuration_id,target=target,- message=build_message(announcement, transition, incident_action=incident_action),+ message=build_message(announcement, transition, team_id=team_id, incident_action=incident_action),in_reply_to=None,)continue@@ -66,7 +66,7 @@ def deliver(team_id=team_id,configuration_id=configuration_id,target=target,- message=build_message(announcement, transition, incident_action=incident_action),+ message=build_message(announcement, transition, team_id=team_id, incident_action=incident_action),in_reply_to=claim.handle,)except Exception:diff --git a/products/alerts_platform/backend/delivery/evaluation.py b/products/alerts_platform/backend/delivery/evaluation.pyindex 5f9ed6320bb1..a62d76dfedd6 100644--- a/products/alerts_platform/backend/delivery/evaluation.py+++ b/products/alerts_platform/backend/delivery/evaluation.py@@ -103,6 +103,7 @@ def deliver_evaluation(request: AlertDeliveryRequest) -> DeliveryOutcome:request.team_id,request.configuration_id,request.evaluation_key,+ source=request.source,incident_grouping_keys=request.incident_actions.keys(),)if announced is None:diff --git a/products/alerts_platform/backend/delivery/message.py b/products/alerts_platform/backend/delivery/message.pyindex 92ce1c420ee0..1d3812d01e9c 100644--- a/products/alerts_platform/backend/delivery/message.py+++ b/products/alerts_platform/backend/delivery/message.py@@ -8,20 +8,26 @@ check it is rendered. A provider turns this into its own body shape.from typing import Any, Finalfrom posthog.dataclasses import frozen-from posthog.utils import pluralize+from posthog.utils import absolute_uri, pluralizefrom products.alerts_platform.backend.facade.contracts import (AlertEventKind,AnnouncedTransition,EvaluationAnnouncement,IncidentAction,+ SourceKind,)_HEADLINES: Final[dict[AlertEventKind, str]] = {- AlertEventKind.FIRING: "{name} is firing",- AlertEventKind.RESOLVED: "{name} is resolved",- AlertEventKind.ERRORED: "{name} could not be checked",- AlertEventKind.BROKEN: "{name} is turned off",+ AlertEventKind.FIRING: "{kind} alert '{name}' is firing",+ AlertEventKind.RESOLVED: "{kind} alert '{name}' is resolved",+ AlertEventKind.ERRORED: "{kind} alert '{name}' could not be checked",+ AlertEventKind.BROKEN: "{kind} alert '{name}' is turned off",+}++_SOURCE_LABELS: Final[dict[SourceKind, str]] = {+ SourceKind.LOGS: "Log",+ SourceKind.INSIGHT: "Insight",}# What a held row says, when cooldown or mute kept its announcement and only its incident moved.@@ -53,10 +59,17 @@ class AlertMessage:details: tuple[MessageDetail, ...]configuration_id: stralert_name: str+ source: SourceKind+ alert_url: strtransition: AnnouncedTransitionincident_action: IncidentAction | None = None+def alert_url(project_id: int, configuration_id: str) -> str:+ # pinned: the platform alert page route in products/alerts_platform/manifest.tsx.+ return absolute_uri(f"/project/{project_id}/platform-alerts/{configuration_id}")++def _number(value: float) -> str:"""A count reads as 300 rather than 300.0, and a rate keeps the digits it needs."""return f"{value:g}"@@ -96,6 +109,7 @@ def build_message(announcement: EvaluationAnnouncement,transition: AnnouncedTransition,*,+ team_id: int,incident_action: IncidentAction | None = None,) -> AlertMessage:"""The message for one transition.@@ -120,10 +134,13 @@ def build_message(else _breach_details(transition))return AlertMessage(- headline=headline.format(name=announcement.alert_name),+ headline=headline.format(kind=_SOURCE_LABELS[announcement.source], name=announcement.alert_name),details=tuple(details),configuration_id=announcement.configuration_id,alert_name=announcement.alert_name,+ source=announcement.source,+ # Platform rows live on the project's root team, so its id is the project id.+ alert_url=alert_url(team_id, announcement.configuration_id),transition=transition,incident_action=incident_action,)diff --git a/products/alerts_platform/backend/delivery/pagerduty.py b/products/alerts_platform/backend/delivery/pagerduty.pyindex 52af31b18e9b..3fa4069a00f7 100644--- a/products/alerts_platform/backend/delivery/pagerduty.py+++ b/products/alerts_platform/backend/delivery/pagerduty.py@@ -72,6 +72,7 @@ def pagerduty_body(message: AlertMessage, *, routing_key: str, severity: PagerDureturn bodytransition = message.transitionbody["client"] = "PostHog"+ body["client_url"] = message.alert_urlbody["payload"] = {"summary": message.headline[:_MAX_SUMMARY_LENGTH],"source": SOURCE,diff --git a/products/alerts_platform/backend/delivery/slack.py b/products/alerts_platform/backend/delivery/slack.pyindex bb986529653a..7b3899b430bf 100644--- a/products/alerts_platform/backend/delivery/slack.py+++ b/products/alerts_platform/backend/delivery/slack.py@@ -10,7 +10,15 @@ from typing import Any, Finalfrom slack_sdk.errors import SlackApiErrorfrom posthog.models.integration import SLACK_INTEGRATION_KINDS, Integration, SlackIntegration-from posthog.slack.channels import MAX_SECTION_CHARS, clip_text, header_block, post_message, section_block+from posthog.slack.channels import (+ MAX_SECTION_CHARS,+ SlackButton,+ actions_block,+ clip_text,+ header_block,+ post_message,+ section_block,+)from posthog.slack.formatting import escape_slack_mrkdwnfrom products.alerts_platform.backend.delivery.message import AlertMessage, MessageDetail@@ -44,6 +52,7 @@ def blocks_for(message: AlertMessage) -> list[dict[str, Any]]:blocks: list[dict[str, Any]] = [header_block(message.headline)]if message.details:blocks.append(section_block(_body(message.details)))+ blocks.append(actions_block([SlackButton(text="View alert", url=message.alert_url)]))return blocksdiff --git a/products/alerts_platform/backend/delivery/teams.py b/products/alerts_platform/backend/delivery/teams.pyindex 24b37c940014..8cc15d3b8ea1 100644--- a/products/alerts_platform/backend/delivery/teams.py+++ b/products/alerts_platform/backend/delivery/teams.py@@ -76,6 +76,7 @@ def card_for(message: AlertMessage) -> dict[str, Any]:"type": "AdaptiveCard","version": "1.2","body": body,+ "actions": [{"type": "Action.OpenUrl", "title": "View alert", "url": message.alert_url}],},}],diff --git a/products/alerts_platform/backend/delivery/webhook.py b/products/alerts_platform/backend/delivery/webhook.pyindex 97b2c81a0172..15c4d0183dd4 100644--- a/products/alerts_platform/backend/delivery/webhook.py+++ b/products/alerts_platform/backend/delivery/webhook.py@@ -54,7 +54,11 @@ def alertmanager_body(message: AlertMessage) -> dict[str, Any]:# Alertmanager has only these two statuses. A failed or a turned-off check goes out as# firing, and `posthog_event_kind` is what tells it apart from a breach.status = "resolved" if transition.kind == AlertEventKind.RESOLVED else "firing"- group_labels = {"alertname": message.alert_name, "posthog_configuration_id": configuration_id}+ group_labels = {+ "alertname": message.alert_name,+ "posthog_configuration_id": configuration_id,+ "posthog_source_kind": message.source.value,+ }# The platform's own labels come last, so a source label with the same name cannot replace them.labels = {**transition.labels, **group_labels, "posthog_event_kind": transition.kind.value}annotations = _annotations(message)@@ -75,7 +79,7 @@ def alertmanager_body(message: AlertMessage) -> dict[str, Any]:"annotations": annotations,"startsAt": rfc3339(transition.episode_started_at or transition.occurred_at),"endsAt": rfc3339(transition.occurred_at) if status == "resolved" else _NOT_ENDED,- "generatorURL": "",+ "generatorURL": message.alert_url,"fingerprint": _fingerprint(configuration_id, transition),}],diff --git a/products/alerts_platform/backend/facade/contracts.py b/products/alerts_platform/backend/facade/contracts.pyindex 17c323f7d967..2e77dc3bfd04 100644--- a/products/alerts_platform/backend/facade/contracts.py+++ b/products/alerts_platform/backend/facade/contracts.py@@ -299,6 +299,7 @@ class EvaluationAnnouncement:"""configuration_id: str+ source: SourceKindalert_name: str# Evaluation-level, so it sits here rather than on a transition: a failed check fails the# whole evaluation, and every group in one announcement saw the same count.diff --git a/products/alerts_platform/backend/logic/platform_alert_events.py b/products/alerts_platform/backend/logic/platform_alert_events.pyindex d1bd460fd3bf..ab227a1b6207 100644--- a/products/alerts_platform/backend/logic/platform_alert_events.py+++ b/products/alerts_platform/backend/logic/platform_alert_events.py@@ -29,6 +29,7 @@ from products.alerts_platform.backend.facade.contracts import (AlertEventKind,AnnouncedTransition,EvaluationAnnouncement,+ SourceKind,)from products.alerts_platform.backend.models.platform_alert_events_sql import PLATFORM_ALERT_EVENTS_TABLE@@ -161,6 +162,7 @@ def announcement(configuration_id: str,evaluation_key: str,*,+ source: SourceKind,incident_grouping_keys: Collection[str] = (),) -> EvaluationAnnouncement | None:"""What one evaluation left for a destination to say, or None when it announced nothing.@@ -207,6 +209,7 @@ def announcement(*_, alert_name, consecutive_failures = rows[0]return EvaluationAnnouncement(configuration_id=configuration_id,+ source=source,alert_name=alert_name,consecutive_failures=consecutive_failures,transitions=transitions,diff --git a/products/alerts_platform/backend/tests/delivery_messages.py b/products/alerts_platform/backend/tests/delivery_messages.pyindex a7b23e7f3444..4bc7b2a7cc50 100644--- a/products/alerts_platform/backend/tests/delivery_messages.py+++ b/products/alerts_platform/backend/tests/delivery_messages.py@@ -11,10 +11,16 @@ from requests.adapters import BaseAdapterfrom requests.structures import CaseInsensitiveDictfrom products.alerts_platform.backend.delivery.message import AlertMessage, MessageDetail-from products.alerts_platform.backend.facade.contracts import AlertEventKind, AnnouncedTransition, IncidentAction+from products.alerts_platform.backend.facade.contracts import (+ AlertEventKind,+ AnnouncedTransition,+ IncidentAction,+ SourceKind,+)EPISODE_STARTED = datetime(2026, 9, 30, 9, tzinfo=UTC)OCCURRED = datetime(2026, 9, 30, 10, tzinfo=UTC)+ALERT_URL = "https://app.example.com/project/1/platform-alerts/cfg-1"def announced_transition(kind: AlertEventKind = AlertEventKind.FIRING, **overrides: Any) -> AnnouncedTransition:@@ -45,6 +51,8 @@ def alert_message(details=details,configuration_id="cfg-1",alert_name=alert_name,+ source=SourceKind.LOGS,+ alert_url=ALERT_URL,transition=transition or announced_transition(),incident_action=incident_action,)diff --git a/products/alerts_platform/backend/tests/test_delivery_discord.py b/products/alerts_platform/backend/tests/test_delivery_discord.pyindex 32b3be522946..f9353d5bc4b7 100644--- a/products/alerts_platform/backend/tests/test_delivery_discord.py+++ b/products/alerts_platform/backend/tests/test_delivery_discord.py@@ -10,7 +10,7 @@ from products.alerts_platform.backend.delivery.discord import MAX_CONTENT_CHARS,from products.alerts_platform.backend.delivery.message import MessageDetailfrom products.alerts_platform.backend.delivery.transport import DeliveryErrorfrom products.alerts_platform.backend.facade.contracts import AlertDestinationData-from products.alerts_platform.backend.tests.delivery_messages import alert_message, pinned_post+from products.alerts_platform.backend.tests.delivery_messages import ALERT_URL, alert_message, pinned_postclass TestDiscordMessage(SimpleTestCase):@@ -27,7 +27,8 @@ class TestDiscordMessage(SimpleTestCase):assert body == {"content": "**@everyone \\[Checkout\\](https://evil.example) is firing**\n\n"- "**Threshold:** \\> 300\n**Error:** bad query\n\\# not a heading",+ "**Threshold:** \\> 300\n**Error:** bad query\n\\# not a heading"+ f"\n\n[View alert](<{ALERT_URL}>)","allowed_mentions": {"parse": []},"flags": 4,}@@ -41,7 +42,7 @@ class TestDiscordMessage(SimpleTestCase):content = content_for(message)assert len(content) <= MAX_CONTENT_CHARS- assert content.endswith("**Failed checks:** 3")+ assert content.endswith(f"**Failed checks:** 3\n\n[View alert](<{ALERT_URL}>)")class TestDiscordTransport(SimpleTestCase):diff --git a/products/alerts_platform/backend/tests/test_delivery_dispatch.py b/products/alerts_platform/backend/tests/test_delivery_dispatch.pyindex 8bb3574910a0..09b8b3e75cb2 100644--- a/products/alerts_platform/backend/tests/test_delivery_dispatch.py+++ b/products/alerts_platform/backend/tests/test_delivery_dispatch.py@@ -17,6 +17,7 @@ from products.alerts_platform.backend.facade.contracts import (AlertEventKind,AnnouncedTransition,EvaluationAnnouncement,+ SourceKind,)TARGET = cast(AlertDestinationData, {"type": "slack", "slack_workspace_id": 1, "slack_channel_id": "C-ENG"})@@ -46,6 +47,7 @@ def _announcement(kind: AlertEventKind = AlertEventKind.FIRING, episode_started_at: datetime | None = FIRST_FIRING) -> EvaluationAnnouncement:return EvaluationAnnouncement(+ source=SourceKind.LOGS,configuration_id="cfg-1",alert_name="API errors",consecutive_failures=0,@@ -163,6 +165,7 @@ class TestDeliveryDispatch(SimpleTestCase):store = RecordingThreadStore()transport = FakeTransport()announcement = EvaluationAnnouncement(+ source=SourceKind.LOGS,configuration_id="cfg-1",alert_name="API errors",consecutive_failures=0,diff --git a/products/alerts_platform/backend/tests/test_delivery_evaluation.py b/products/alerts_platform/backend/tests/test_delivery_evaluation.pyindex adbff192cf6d..38929ef9e4a9 100644--- a/products/alerts_platform/backend/tests/test_delivery_evaluation.py+++ b/products/alerts_platform/backend/tests/test_delivery_evaluation.py@@ -108,7 +108,11 @@ def _transition(kind: AlertEventKind, grouping_key: str = "") -> AnnouncedTransidef _announcement(*transitions: AnnouncedTransition) -> EvaluationAnnouncement:return EvaluationAnnouncement(- configuration_id="cfg-1", alert_name="API errors", consecutive_failures=0, transitions=transitions+ source=SourceKind.LOGS,+ configuration_id="cfg-1",+ alert_name="API errors",+ consecutive_failures=0,+ transitions=transitions,)@@ -164,8 +168,8 @@ class TestDeliverEvaluation(APIBaseTest):self._run(announced, {FIRING_EVENT: [_group(fires_only)], RESOLVED_EVENT: [_group(resolves_only)]})assert sorted((channel, m.headline) for channel, m in RecordingTransport.sends) == [- ("C-fires", "API errors is firing"),- ("C-resolves", "API errors is resolved"),+ ("C-fires", "Log alert 'API errors' is firing"),+ ("C-resolves", "Log alert 'API errors' is resolved"),]def test_a_destination_subscribed_to_both_hears_about_both(self) -> None:@@ -177,8 +181,8 @@ class TestDeliverEvaluation(APIBaseTest):self._run(announced, {FIRING_EVENT: [_group(SLACK)], RESOLVED_EVENT: [_group(SLACK)]})assert sorted(m.headline for _, m in RecordingTransport.sends) == [- "API errors is firing",- "API errors is resolved",+ "Log alert 'API errors' is firing",+ "Log alert 'API errors' is resolved",]def test_a_delivery_that_exists_only_for_its_incident_sends_no_message(self) -> None:@@ -196,7 +200,13 @@ class TestDeliverEvaluation(APIBaseTest):[# Cooldown held the resolve, so chat hears nothing and the incident still closes.("a_held_resolve", AlertEventKind.CHECK, False, IncidentAction.RESOLVE, []),- ("an_announced_fire", AlertEventKind.FIRING, True, IncidentAction.TRIGGER, ["API errors is firing"]),+ (+ "an_announced_fire",+ AlertEventKind.FIRING,+ True,+ IncidentAction.TRIGGER,+ ["Log alert 'API errors' is firing"],+ ),])def test_an_incident_action_reaches_only_the_incident_subscription(diff --git a/products/alerts_platform/backend/tests/test_delivery_message.py b/products/alerts_platform/backend/tests/test_delivery_message.pyindex 7b136745a0c2..4e872855663c 100644--- a/products/alerts_platform/backend/tests/test_delivery_message.py+++ b/products/alerts_platform/backend/tests/test_delivery_message.py@@ -3,12 +3,13 @@ from typing import Anyimport pytest-from products.alerts_platform.backend.delivery.message import MessageDetail, build_message+from products.alerts_platform.backend.delivery.message import AlertMessage, MessageDetail, build_messagefrom products.alerts_platform.backend.facade.contracts import (AlertEventKind,AnnouncedTransition,EvaluationAnnouncement,IncidentAction,+ SourceKind,)CONDITION = {"threshold_count": 100, "threshold_operator": "above", "window_minutes": 5}@@ -30,17 +31,50 @@ def _transition(kind: AlertEventKind, **overrides: Any) -> AnnouncedTransition:return AnnouncedTransition(**fields)-def _announcement(consecutive_failures: int = 0) -> EvaluationAnnouncement:+def _announcement(consecutive_failures: int = 0, source: SourceKind = SourceKind.LOGS) -> EvaluationAnnouncement:return EvaluationAnnouncement(- configuration_id="cfg-1", alert_name="API errors", consecutive_failures=consecutive_failures, transitions=()+ configuration_id="cfg-1",+ source=source,+ alert_name="API errors",+ consecutive_failures=consecutive_failures,+ transitions=(),)+def _build(+ announcement: EvaluationAnnouncement,+ transition: AnnouncedTransition,+ *,+ incident_action: IncidentAction | None = None,+) -> AlertMessage:+ return build_message(announcement, transition, team_id=7, incident_action=incident_action)++class TestAlertMessage:+ @pytest.mark.parametrize(+ "source,expected_headline",+ [+ (SourceKind.LOGS, "Log alert 'API errors' is firing"),+ (SourceKind.INSIGHT, "Insight alert 'API errors' is firing"),+ ],+ )+ def test_a_message_names_its_source_and_links_to_its_alert(+ self, source: SourceKind, expected_headline: str+ ) -> None:+ message = _build(_announcement(source=source), _transition(AlertEventKind.FIRING))++ assert message.headline == expected_headline+ assert message.alert_url.endswith("/project/7/platform-alerts/cfg-1")++ @pytest.mark.parametrize("source", list(SourceKind))+ def test_every_source_kind_has_a_headline(self, source: SourceKind) -> None:+ message = _build(_announcement(source=source), _transition(AlertEventKind.FIRING))++ assert message.headline.endswith("alert 'API errors' is firing")+def test_a_breach_states_what_it_measured_against_what_it_allowed(self) -> None:- message = build_message(_announcement(), _transition(AlertEventKind.FIRING))+ message = _build(_announcement(), _transition(AlertEventKind.FIRING))- assert message.headline == "API errors is firing"assert message.details == (MessageDetail(label="Value", value="300"),MessageDetail(label="Threshold", value="above 100"),@@ -48,12 +82,12 @@ class TestAlertMessage:)def test_a_failed_check_states_the_reason_rather_than_a_threshold(self) -> None:- message = build_message(+ message = _build(_announcement(consecutive_failures=3),_transition(AlertEventKind.ERRORED, value=None, error_message="Query is too expensive"),)- assert message.headline == "API errors could not be checked"+ assert message.headline == "Log alert 'API errors' could not be checked"assert message.details == (MessageDetail(label="Error", value="Query is too expensive"),MessageDetail(label="Failed checks", value="3"),@@ -65,24 +99,27 @@ class TestAlertMessage:)def test_the_window_reads_as_a_duration(self, window_minutes: int, expected: str) -> None:condition = {**CONDITION, "window_minutes": window_minutes}- message = build_message(_announcement(), _transition(AlertEventKind.FIRING, condition=condition))+ message = _build(_announcement(), _transition(AlertEventKind.FIRING, condition=condition))assert MessageDetail(label="Window", value=expected) in message.detailsdef test_a_check_that_announces_nothing_has_no_message(self) -> None:with pytest.raises(ValueError):- build_message(_announcement(), _transition(AlertEventKind.CHECK))+ _build(_announcement(), _transition(AlertEventKind.CHECK))@pytest.mark.parametrize("action,expected",- [(IncidentAction.TRIGGER, "API errors is firing"), (IncidentAction.RESOLVE, "API errors is resolved")],+ [+ (IncidentAction.TRIGGER, "Log alert 'API errors' is firing"),+ (IncidentAction.RESOLVE, "Log alert 'API errors' is resolved"),+ ],)def test_a_held_check_speaks_for_the_incident_it_moved(self, action: IncidentAction, expected: str) -> None:- message = build_message(_announcement(), _transition(AlertEventKind.CHECK), incident_action=action)+ message = _build(_announcement(), _transition(AlertEventKind.CHECK), incident_action=action)assert (message.headline, message.incident_action) == (expected, action)def test_a_partial_condition_drops_the_line_it_cannot_state(self) -> None:- message = build_message(_announcement(), _transition(AlertEventKind.FIRING, condition={}))+ message = _build(_announcement(), _transition(AlertEventKind.FIRING, condition={}))assert message.details == (MessageDetail(label="Value", value="300"),)diff --git a/products/alerts_platform/backend/tests/test_delivery_pagerduty.py b/products/alerts_platform/backend/tests/test_delivery_pagerduty.pyindex dde429cde1a9..e36d12c08159 100644--- a/products/alerts_platform/backend/tests/test_delivery_pagerduty.py+++ b/products/alerts_platform/backend/tests/test_delivery_pagerduty.py@@ -18,7 +18,12 @@ from products.alerts_platform.backend.facade.contracts import (IncidentAction,PagerDutySeverity,)-from products.alerts_platform.backend.tests.delivery_messages import alert_message, announced_transition, pinned_post+from products.alerts_platform.backend.tests.delivery_messages import (+ ALERT_URL,+ alert_message,+ announced_transition,+ pinned_post,+)ROUTING_KEY = "not-a-real-routing-key-0000000000"TARGET = cast(AlertDestinationData, {"type": "pagerduty", "pagerduty_routing_key": ROUTING_KEY})@@ -44,6 +49,7 @@ class TestPagerDutyBody(SimpleTestCase):"event_action": "trigger","dedup_key": "cfg-1::2026-09-30T09:00:00+00:00","client": "PostHog",+ "client_url": ALERT_URL,"payload": {"summary": "API errors is firing","source": "PostHog alerts platform",diff --git a/products/alerts_platform/backend/tests/test_delivery_slack.py b/products/alerts_platform/backend/tests/test_delivery_slack.pyindex f9cc748369c8..c6574b6d9a29 100644--- a/products/alerts_platform/backend/tests/test_delivery_slack.py+++ b/products/alerts_platform/backend/tests/test_delivery_slack.py@@ -15,7 +15,7 @@ from products.alerts_platform.backend.delivery.message import MessageDetailfrom products.alerts_platform.backend.delivery.slack import SlackTransport, blocks_forfrom products.alerts_platform.backend.delivery.transport import DeliveryError, MessageHandlefrom products.alerts_platform.backend.facade.contracts import AlertDestinationData-from products.alerts_platform.backend.tests.delivery_messages import alert_message+from products.alerts_platform.backend.tests.delivery_messages import ALERT_URL, alert_messageMESSAGE = alert_message(headline="API errors is firing",@@ -65,7 +65,8 @@ class TestSlackBlocks(SimpleTestCase):def test_a_message_without_details_carries_no_empty_section(self) -> None:blocks = blocks_for(alert_message(headline="API errors is resolved", details=()))- assert [block["type"] for block in blocks] == ["header"]+ assert [block["type"] for block in blocks] == ["header", "actions"]+ assert blocks[1]["elements"][0]["url"] == ALERT_URLclass TestSlackTransport(APIBaseTest):diff --git a/products/alerts_platform/backend/tests/test_delivery_teams.py b/products/alerts_platform/backend/tests/test_delivery_teams.pyindex 07226beb1be5..c4631d5cfe98 100644--- a/products/alerts_platform/backend/tests/test_delivery_teams.py+++ b/products/alerts_platform/backend/tests/test_delivery_teams.py@@ -11,7 +11,7 @@ from products.alerts_platform.backend.delivery.message import MessageDetailfrom products.alerts_platform.backend.delivery.teams import TeamsTransport, card_forfrom products.alerts_platform.backend.delivery.transport import DeliveryErrorfrom products.alerts_platform.backend.facade.contracts import AlertDestinationData-from products.alerts_platform.backend.tests.delivery_messages import alert_message, pinned_post+from products.alerts_platform.backend.tests.delivery_messages import ALERT_URL, alert_message, pinned_postTEAMS_URL = "https://prod-00.westus.logic.azure.com:443/workflows/abc/triggers/manual/paths/invoke?sig=fake"@@ -48,6 +48,7 @@ class TestTeamsCard(SimpleTestCase):],},],+ "actions": [{"type": "Action.OpenUrl", "title": "View alert", "url": ALERT_URL}],},}],diff --git a/products/alerts_platform/backend/tests/test_delivery_webhook.py b/products/alerts_platform/backend/tests/test_delivery_webhook.pyindex 7026bace562a..525186d4599e 100644--- a/products/alerts_platform/backend/tests/test_delivery_webhook.py+++ b/products/alerts_platform/backend/tests/test_delivery_webhook.py@@ -22,9 +22,15 @@ from products.alerts_platform.backend.facade.contracts import (AlertDestinationData,AlertEventKind,EvaluationAnnouncement,+ SourceKind,)from products.alerts_platform.backend.models import PlatformAlertConfiguration, PlatformAlertThread-from products.alerts_platform.backend.tests.delivery_messages import alert_message, announced_transition, pinned_post+from products.alerts_platform.backend.tests.delivery_messages import (+ ALERT_URL,+ alert_message,+ announced_transition,+ pinned_post,+)SECRET_URL = "https://hooks.example.com/services/T000/B000/not-a-real-token"TARGET = cast(AlertDestinationData, {"type": "webhook", "webhook_url": SECRET_URL})@@ -47,6 +53,7 @@ class TestAlertmanagerBody(SimpleTestCase):"service": "checkout","alertname": "API errors","posthog_configuration_id": "cfg-1",+ "posthog_source_kind": "logs","posthog_event_kind": "firing",}annotations = {"summary": "API errors is firing", "description": "Value: 312\nThreshold: > 300", "value": "312"}@@ -56,7 +63,11 @@ class TestAlertmanagerBody(SimpleTestCase):"truncatedAlerts": 0,"status": "firing","receiver": "posthog",- "groupLabels": {"alertname": "API errors", "posthog_configuration_id": "cfg-1"},+ "groupLabels": {+ "alertname": "API errors",+ "posthog_configuration_id": "cfg-1",+ "posthog_source_kind": "logs",+ },"commonLabels": labels,"commonAnnotations": annotations,"externalURL": "https://us.posthog.com",@@ -67,7 +78,7 @@ class TestAlertmanagerBody(SimpleTestCase):"annotations": annotations,"startsAt": "2026-09-30T09:00:00+00:00","endsAt": "0001-01-01T00:00:00Z",- "generatorURL": "",+ "generatorURL": ALERT_URL,"fingerprint": body["alerts"][0]["fingerprint"],}],@@ -179,6 +190,7 @@ class TestWebhookThreads(APIBaseTest):def _deliver(self, kind: AlertEventKind, evaluation_key: str) -> Any:announcement = EvaluationAnnouncement(+ source=SourceKind.LOGS,configuration_id=str(self.configuration.id),alert_name="API errors",consecutive_failures=0,diff --git a/products/alerts_platform/backend/tests/test_platform_announcement.py b/products/alerts_platform/backend/tests/test_platform_announcement.pyindex dff1b3b25af8..3df31a5c2bae 100644--- a/products/alerts_platform/backend/tests/test_platform_announcement.py+++ b/products/alerts_platform/backend/tests/test_platform_announcement.py@@ -6,7 +6,7 @@ from posthog.test.base import APIBaseTest, ClickhouseTestMixinfrom posthog.clickhouse.client import sync_executefrom posthog.models.scoping import team_scope-from products.alerts_platform.backend.facade.contracts import AlertEventKind+from products.alerts_platform.backend.facade.contracts import AlertEventKind, SourceKindfrom products.alerts_platform.backend.logic.platform_alert_events import (_INSERT_SQL,PlatformAlertEventRow,@@ -57,7 +57,7 @@ class TestAnnouncement(ClickhouseTestMixin, APIBaseTest):return PlatformAlertEventRow(**fields)def _announcement(self, evaluation_key: str = "eval-1"):- return announcement(self.team.id, str(self.configuration.id), evaluation_key)+ return announcement(self.team.id, str(self.configuration.id), evaluation_key, source=SourceKind.LOGS)def test_a_recorded_firing_comes_back_as_the_message_it_should_send(self) -> None:insert_events(self.team.id, [self._row()])@@ -95,6 +95,7 @@ class TestAnnouncement(ClickhouseTestMixin, APIBaseTest):self.team.id,str(self.configuration.id),"eval-1",+ source=SourceKind.LOGS,incident_grouping_keys=["checkout"],)