Repository navigation
[HDX-5837] Expose alert tags as a webhook template variable - #3492
Conversation
Add {{tags}} to the Generic/incident.io webhook template variables so a
shared webhook can route alerts by owning team. Tags render
comma-separated and are iterable with {{#each tags}}. The default
incident.io body now carries them in metadata.tags, and the in-repo
template variable docs, webhook form and test send include the variable.
Refs HDX-5837
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 62e113f The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
[Medium impact] The PR appears safe to merge. SummaryAdds alert tags to Generic and incident.io webhook templates.
No actionable issues found. Reviews (2) · Last reviewed commit: "Merge branch 'main' into warren/HDX-5837..." · Reviewed by Greptile |
E2E Test Results✅ All tests passed • 458 passed • 1 skipped • 1545s
Tests ran across 4 shards in parallel. |
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Additional context: touches background tasks or the delivery pipeline lightly (6 lines, under the 30-line bar for Tier 4), spans packages but only 12 prod lines — under the 100-line cross-layer bar Review process: Full human review — logic, architecture, edge cases. Stats
|
| ), | ||
| teamId, | ||
| note: alert.note ?? '', | ||
| tags: alert.tags ?? [], |
There was a problem hiding this comment.
🔵 minor — No test checks that an alert's tags reach the dispatched message
Add a case to the renderWithWebhook suite in packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts: give base.alert some tags and assert dispatched[0].message.tags equals them, plus a case for an alert with no tags that expects []. Today the new unit test only feeds a hand-built Message into buildWebhookTemplateVariables. If this line were deleted, every test would still pass and the customer's original bug ("tags": "") would come back.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| sourceQuery: escapeJsonString(message.sourceQuery ?? ''), | ||
| status: escapeJsonString(message.status ?? ''), | ||
| // An array so `{{tags}}` renders comma-joined and `{{#each tags}}` works. | ||
| tags: (message.tags ?? []).map(escapeJsonString), |
There was a problem hiding this comment.
🔵 minor — Comma-joined {{tags}} is ambiguous because tags can contain commas
alertTagsSchema/tagsSchema in packages/common-utils/src/types.ts:1076 only limits length (z.string().max(32)), so a single tag team-a,prod renders the same as the two tags team-a and prod. That matters for comma-split routing and for the default incident.io metadata.tags. Either reject commas in alert tags, or switch the default body to the {{#each}} JSON-array form and note in the docs and the form description that the joined form is lossy.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
PR Review
2 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 2 minor 2 posted as inline comment(s) on the changed lines. Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical issues found. This is a tight, additive change: 🟡 P2 -- recommended
🔵 P3 nitpicks (3)
Reviewers (10): correctness, testing, maintainability, kieran-typescript, security, api-contract, project-standards, previous-comments, agent-native, learnings-researcher. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
Summary
A customer sends ClickStack alerts to incident.io through one shared webhook per environment and wants to route each alert to its owning team. They put
"tags": "{{tags}}"in the webhook body, buttagswas not a template variable, so it rendered empty.This PR adds
{{tags}}to the Generic and incident.io webhook template variables:{{tags}}renders the alert's tags comma-separated (team-payments,prod). Use{{#each tags}}to emit a JSON array. Each tag is JSON-escaped, like every other string variable.metadata.tags, so webhooks saved without a custom body pick it up. The key is additive, and incident.io surfaces only the metadata keys its alert source is set to parse.docs/alert-webhook-template-variables.md, the variable list on the webhook form, and the Send test sample include the new variable.The ticket also asks to publish the full variable list. The in-repo doc already lists every variable and now includes
tags. Follow-up needed: the public ClickHouse docs alerts page (clickhouse-docsrepo, "Generic" webhook section) still lists only{{title}},{{body}},{{link}}. That page lives in another repo and needs its own PR.Screenshots or video
UI change: one added row in the webhook form's "template variables" list. I couldn't capture screenshots in this session; the author will add them.
How to reproduce
Starting point: full-stack
yarn dev(alerts and webhooks need the API), plus a request inspector such as webhook.site.On
main:{"tags": "{{tags}}"}.team-payments) that uses this webhook, and let it fire."tags": "".On this branch:
"tags": "team-payments"."tags": "test-tag".{{tags}}.How to test on Vercel preview
N/A. Webhooks need the API, which the local-mode preview does not run.
References
Verification:
make ci-lintpasses.make ci-unitpasses apart frompackages/app/src/__tests__/timeZone.test.ts, which fails on this machine with the same ICU timezone formatting error (UTC+0vsUTC) on the base commit as well.