feat(automations): Sentry trigger provider with internal-integration connection
Summary
Sentry trigger provider (kind sentry): a public Sentry integration (OAuth app) connection, the inbound webhook, the editor provider, and the matcher — in one PR, rebased onto the consolidated seam (#6594).
Product note: an earlier revision of this PR used a Sentry internal integration (paste a token + per-connection secret). Satya's call is that internal is too clunky for users, so this is now the public OAuth app. The commit history reflects that pivot.
Connection — public OAuth app.
GET /api/integrations/sentry/connect?organizationId=verifies membership and redirects the admin to Sentry's install URL (/sentry-apps/<slug>/external-install/). Because Sentry's install redirect echoes no state of ours and its webhooks name no Superset org, the Superset org is carried to the callback in a signed, first-party cookie scoped to/api/integrations/sentry.GET /api/integrations/sentry/callbackreadscode+installationId, recovers the org from the cookie (re-verifies membership), exchanges the code at/sentry-app-installations/{id}/authorizations/for{token, refreshToken, expiresAt}, learns the Sentry org slug/region from/organizations/with the fresh token, upserts the connection (installationUuid+regionUrlinconfig), and does the Verify-InstallPUT.- Tokens live ~8h;
getSentryAccessTokenrefreshes within a 5-min buffer under an advisory lock (Linear's pattern) solistProjectskeeps working.getConnection/disconnect/listProjectsround out the tRPC router.
Webhook — POST /api/integrations/sentry/webhook. One fixed URL for the app. Verified first with the app's single client secret (SENTRY_CLIENT_SECRET, env) via constant-time HMAC-SHA256 over the raw body. The delivery is attributed by installation.uuid (the callback stored it on the connection); ?organization= remains a fallback only if a payload carries no installation. installation.created is a no-op (the callback is the only writer that knows the org); installation.deleted disconnects the connection and drops its tokens, so a later issue delivery for that install is refused. Issue deliveries are recorded (recordAutomationEvent, connection-scoped dedupe) and dispatched via the shared @/lib/automations/dispatchMatchingTriggers.
The create race (called out because it bites in prod). Sentry fires installation.created and redirects the browser in parallel; either can land first. Only the callback knows the Superset org, so it is the sole creator (upsert on (org, provider)); the webhook only ever updates a row the callback already wrote, or no-ops if it hasn't yet. Both orders — and an issue delivery arriving before the callback finishes — are handled without a "row exists"/"row not found" failure. Verified both orders below.
Desktop. providers/sentry/ — sentence Sentry issue [created|resolved|assigned|archived|unresolved|any] in [projects] with level [levels]; menu Sentry › the six events; projects starts null (save-blocked until chosen), level starts {mode:"any"} (a set, not a threshold). Namespaced options: useSentryOptions → { sentry: { projects, levels } }.
Shared. automation-matching/sentry.ts (SentryMatchableEvent, sentryEventNames, sentryTriggerMatches), added to the MatchableEvent union + a case in triggerMatches; sentry rules in describeTriggerProblems. No edits to providers/types.ts, automation-matching/core.ts, or the shared dispatcher.
Security bullet
integration.listno longer returnsconfig. It handed the wholeconfigjsonb to every org member; Sentry stores itsinstallationUuidthere (the webhook's link back to the row). Nothing readconfigfromlist.
Verification (workspace Neon branch; API-only, SENTRY_CLIENT_SECRET set in env; desktop editor unchanged from the prior rebase, so its screenshots stand — s17-after-reload.png, s18-post-rebase-level-menu.png)
Signed replays (HMAC over the exact body with the env client secret):
- Bad signature → 401.
installation.created(row already present) → 200 no-op, connection unchanged. - Valid
issue.createdlevelerror, matching install uuid → matched → reaches the shared dispatcher'sqstash.batchJSON(fails locally with QStash'sendpoint resolves to a loopback address— the standard local "matched" signal) and writes anautomation_eventsrow (provider=sentry,event_type=issue.created,external_event_id=<Request-ID>,resource_key=sentry:<projectId>#<issueId>,integration_connection_id). - Same Request-ID again → 200
duplicate delivery, no second row. Levelinfo(trigger filters fatal+error) → 200, not matched. Unknown install uuid → 200No connection. installation.deleted→ connectiondisconnected_atset, reason recorded,access_tokenemptied,refresh_tokennulled; a subsequent issue delivery for that install → 200No connection(refused).bun run typecheck→ exit 0;bun run lint→ exit 0.
Not exercised locally (needs a registered Sentry app, which is the external item below): the browser install/redirect, the real code→token exchange and refresh, listProjects against a live token, and Verify-Install. The token exchange / refresh / org-lookup calls are structured to Sentry's documented public-app contract.
External item (for Satya)
Register the Superset public integration in Sentry: name, Redirect URL = <API>/api/integrations/sentry/callback, Webhook URL = <API>/api/integrations/sentry/webhook, permissions Organization/Project/Issue&Event: Read, the issue webhook, Verify Install on. Then set SENTRY_CLIENT_ID / SENTRY_CLIENT_SECRET / SENTRY_APP_SLUG. Until Sentry publishes the app, only Superset's own Sentry org can install it — that's inherent to Sentry's public-integration model.
Follow-ups
- Marketplace-initiated installs (from Sentry, not our Connect button) have no org cookie and currently error to "start from Superset"; a Sentry-side install landing page could attribute via the authenticated session's active org later.
Summary by CodeRabbit
- New Features
- Added Sentry integration with OAuth connection and disconnection flows.
- Added Sentry organization and project browsing.
- Added Sentry automation triggers with project and severity-level filters.
- Added webhook processing for Sentry issue events, including duplicate prevention and trigger dispatch.
- Added Sentry to the integrations directory with connection status and error feedback.