sentry-create-alert について
Sentry workflow engine API を使って問題アラートを作成するスキルです。通知や自動化を設定するチーム向けに、設定情報の収集、リクエストの構築、作成結果の確認を案内します。API は現在ベータ版です。
主な機能
- 01組織、リージョン、アラート設定を収集
- 02問題のトリガーと条件を構成
- 03メールや連携先への通知アクションを設定
- 04API でアラートを作成して確認
- 05ワークフローの参照と更新方法を案内
活用シーン
- 01新規問題の通知を設定
- 02優先度やイベント頻度を条件にアラート
- 03Slack、PagerDuty、メールへ通知
- 04Sentry のワークフローアラートを作成・確認
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ getsentry/ sentry-agent-skills --skill sentry-create-alertインストール後、Claude Code で/sentry-create-alertを入力して読み込まれたか確認します。
詳細
Sentry アラートの作成
Sentry のワークフローエンジン API を使用してアラートを作成します。
注: この API は現在 ベータ版であり、変更される場合があります。New Monitors and Alerts の一部であり、従来の Alerts UI では表示されないことがあります。
このスキルを使用する場面
- ユーザーが「Sentry アラートを作成」または「通知を設定」と依頼した場合
- ユーザーが、特定の条件に一致する問題が発生したときにメールや通知を受け取りたい場合
- ユーザーが優先度アラート、優先度引き下げアラート、またはワークフローの自動化について言及した場合
- ユーザーが Sentry の問題に対する Slack、PagerDuty、またはメール通知の設定を希望する場合
前提条件
- シェルで
curlを使用できること alerts:writeスコープを持つ Sentry 組織の認証トークン(org:adminまたはorg:writeも使用できます)
フェーズ 1:設定情報の収集
不足している情報があれば、ユーザーに尋ねます。
| 詳細 | 必須 | 例 |
|---|---|---|
| 組織のスラッグ | はい | sentry、my-org |
| 認証トークン | はい | sntryu_...(alerts:write スコープが必要) |
| リージョン | はい(デフォルト:us) | us → us.sentry.io、de → de.sentry.io |
| アラート名 | はい | "High Priority De-escalation Alert" |
| トリガーイベント | はい | ワークフローを起動する問題イベント |
| 条件 | 任意 | アクションの実行前に適用するフィルター条件 |
| アクションの種類 | はい | email、slack、または pagerduty |
| アクションの対象 | はい | ユーザーのメールアドレス、チーム、チャンネル、またはサービス |
フェーズ 2:ID の検索
必要に応じて、次の API 呼び出しを使用して名前を ID に解決します。
API="https://{region}.sentry.io/api/0/organizations/{org}"
AUTH="Authorization: Bearer {token}"
# Find user ID by email
curl -s "$API/members/" -H "$AUTH" | python3 -c "
import json,sys
for m in json.load(sys.stdin):
if m.get('email')=='USER_EMAIL' or m.get('user',{}).get('email')=='USER_EMAIL':
print(m['user']['id']); break"
# List teams
curl -s "$API/teams/" -H "$AUTH" | python3 -c "
import json,sys
for t in json.load(sys.stdin):
print(t['id'], t['slug'])"
# List integrations (for Slack/PagerDuty)
curl -s "$API/integrations/" -H "$AUTH" | python3 -c "
import json,sys
for i in json.load(sys.stdin):
print(i['id'], i['provider']['key'], i['name'])"
フェーズ 3:ペイロードの構築
トリガーイベント
ワークフローを起動する問題イベントを選択します。logicType: "any-short" を使用してください(トリガーでは必ずこれを使用します)。
| 種類 | 発生するタイミング |
|---|---|
first_seen_event | 新しい問題が作成されたとき |
regression_event | 解決済みの問題が再発したとき |
reappeared_event | アーカイブ済みの問題が再表示されたとき |
issue_resolved_trigger | 問題が解決されたとき |
フィルター条件
アクションの実行前に満たす必要がある条件です。logicType: "all"、"any-short"、または "none" を使用します。
comparison フィールドはポリモーフィックです。形式は条件の type によって異なります。
| 種類 | comparison の形式 | 説明 |
|---|---|---|
issue_priority_greater_or_equal | 75(整数値のみ) | 優先度 >= Low(25)/Medium(50)/High(75) |
issue_priority_deescalating | true(ブール値のみ) | 優先度が最高値を下回った |
event_frequency_count | {"value": 100, "interval": "1hr"} | 時間枠内のイベント数 |
event_unique_user_frequency_count | {"value": 50, "interval": "1hr"} | 時間枠内の影響を受けたユーザー数 |
tagged_event | {"key": "level", "match": "eq", "value": "error"} | イベントのタグが一致する |
assigned_to | {"targetType": "Member", "targetIdentifier": 123} | 問題が対象に割り当てられている |
level | {"level": 40, "match": "gte"} | イベントレベル(fatal=50、error=40、warning=30) |
age_comparison | {"time": "hour", "value": 24, "comparisonType": "older"} | 問題の経過時間 |
issue_category | {"value": 1} | カテゴリ(1=Error、6=Feedback) |
issue_occurrences | {"value": 100} | 発生回数の合計 |
インターバルの選択肢: "1min"、"5min"、"15min"、"1hr"、"1d"、"1w"、"30d"
タグのマッチタイプ: "co"(含む)、"nc"(含まない)、"eq"、"ne"、"sw"(次で始まる)、"ew"(次で終わる)、"is"(設定済み)、"ns"(未設定)
conditionResult を false に設定すると、条件を反転できます(条件を満たさない場合に発火します)。
アクション
| 種類 | 主な設定 |
|---|---|
email | config.targetType: "user" / "team" / "issue_owners"、config.targetIdentifier: <id> |
slack | integrationId: <id>、config.targetDisplay: "#channel-name" |
pagerduty | integrationId: <id>、config.targetDisplay: <service_name>、data.priority: "critical" |
discord | integrationId: <id>、data.tags: タグのリスト |
msteams | integrationId: <id>、config.targetDisplay: <channel> |
opsgenie | integrationId: <id>、data.priority: "P1"-"P5" |
jira | integrationId: <id>、data: プロジェクト/課題の設定 |
github | integrationId: <id>、data: リポジトリ/課題の設定 |
ペイロードの全体構造
{
"name": "<Alert Name>",
"enabled": true,
"environment": null,
"config": { "frequency": 30 },
"triggers": {
"logicType": "any-short",
"conditions": [
{ "type": "first_seen_event", "comparison": true, "conditionResult": true }
],
"actions": []
},
"actionFilters": [{
"logicType": "all",
"conditions": [
{ "type": "issue_priority_greater_or_equal", "comparison": 75, "conditionResult": true },
{ "type": "event_frequency_count", "comparison": {"value": 50, "interval": "1hr"}, "conditionResult": true }
],
"actions": [{
"type": "email",
"integrationId": null,
"data": {},
"config": {
"targetType": "user",
"targetIdentifier": "<user_id>",
"targetDisplay": null
},
"status": "active"
}]
}]
}
frequency:通知を繰り返す間隔(分)。指定可能な値は 0、5、10、30、60、180、720、1440 です。
構造に関する注意: triggers.actions は常に [] です。アクションは actionFilters[].actions 内に配置します。
フェーズ 4:アラートを作成する
curl -s -w "\n%{http_code}" -X POST \
"https://{region}.sentry.io/api/0/organizations/{org}/workflows/" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{payload}'
HTTP 201 が返されることを確認します。レスポンスにはワークフローの id が含まれます。
フェーズ 5:確認する
アラートが作成されたことを確認し、UI のリンクを提示します。
https://{org_slug}.sentry.io/monitors/alerts/{workflow_id}/
組織で workflow-engine-ui 機能フラグが有効になっていない場合、アラートは次の場所に表示されます。
https://{org_slug}.sentry.io/alerts/rules/
アラートの管理
# List all workflows
curl -s "$API/workflows/" -H "$AUTH"
# Get one workflow
curl -s "$API/workflows/{id}/" -H "$AUTH"
# Update a workflow
curl -s -X PUT "$API/workflows/{id}/" -H "$AUTH" -H "Content-Type: application/json" -d '{payload}'
# Delete a workflow
curl -s -X DELETE "$API/workflows/{id}/" -H "$AUTH"
# Expect 204
トラブルシューティング
| 問題 | 解決策 |
|---|---|
| 401 Unauthorized | トークンに alerts:write スコープが必要です |
| 403 Forbidden | トークンは対象の組織に属している必要があります |
| 404 Not Found | 組織のスラッグとリージョン(us と de)を確認してください |
| 400 Bad Request | ペイロードの JSON 構造を検証し、必須フィールドを確認してください |
| ユーザー ID が見つからない | メールアドレスが組織のメンバーのものと一致するか確認してください |