> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devin.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# インシデントのポストモーテムを自動生成

export const UseCaseHero = ({title, description, prompt, category, features, devinUrl, agent, intent, playbookId, type}) => {
  const encodedPrompt = encodeURIComponent(prompt || '');
  const tag = 'docs-use-case-gallery';
  const utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=hero-cta';
  const agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  const devinHref = type === 'schedule' ? 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + (prompt ? '&prompt=' + encodedPrompt : '') : type === 'review' ? 'https://app.devin.ai/review?' + utm : agent === 'ada' ? 'https://app.devin.ai/search?' + utm + '&noSubmit=true' + (prompt ? '&prompt=' + encodedPrompt : '') : devinUrl ? devinUrl.includes('?') ? devinUrl + '&' + utm + agentParams : devinUrl + '?' + utm + agentParams : prompt ? 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encodedPrompt : 'https://app.devin.ai/?' + utm + agentParams;
  const buttonLabel = type === 'schedule' ? 'Schedule in Devin ↗' : type === 'review' ? 'Set Up Devin Review ↗' : agent === 'advanced' ? 'Try in Devin ↗' : agent === 'dana' ? 'Try in Dana ↗' : agent === 'ada' ? 'Try in Ask Devin ↗' : 'Try in Devin ↗';
  const featureList = features ? features.split(',').map(f => f.trim()) : [];
  return <div className="uc-hero">
      <div className="uc-hero-inner">
        <div className="uc-hero-left">
          <h1 className="uc-hero-title">{title}</h1>
          <p className="uc-hero-desc">{description}</p>
          <div>
            <a href={devinHref} target="_blank" rel="noopener noreferrer" className="try-in-devin-btn">
              {buttonLabel}
            </a>
          </div>
        </div>
        <div className="uc-hero-meta">
          <div className="uc-meta-item">
            <span className="uc-meta-label">Author</span>
            <span className="uc-meta-value">Cognition</span>
          </div>
          <div className="uc-meta-item">
            <span className="uc-meta-label">Category</span>
            <span className="uc-meta-value">{category}</span>
          </div>
          {featureList.length > 0 && <div className="uc-meta-item">
              <span className="uc-meta-label">Features</span>
              <span className="uc-meta-value">{featureList.join(', ')}</span>
            </div>}
        </div>
      </div>
    </div>;
};

export const PromptBlock = ({children, type, agent, intent, playbookId}) => {
  var utm = 'utm_source=docs&utm_medium=use-case-gallery&utm_campaign=prompt-block';
  var tag = 'docs-use-case-gallery';
  var agentParams = (agent ? '&agent=' + agent : '') + (intent ? '&intent=' + intent : '') + (playbookId ? '&playbookId=' + playbookId : '');
  var label = type === 'schedule' ? 'Schedule in Devin' : type === 'playbook' ? 'Create Playbook' : type === 'knowledge' ? 'Add to Knowledge' : agent === 'advanced' ? 'Try in Devin' : agent === 'dana' ? 'Try in Dana' : agent === 'ada' ? 'Try in Ask Devin' : 'Try in Devin';
  var buildUrl = function (text) {
    var encoded = encodeURIComponent(text);
    if (type === 'schedule') return 'https://app.devin.ai/settings/schedules/create?' + utm + agentParams + '&prompt=' + encoded;
    if (type === 'playbook') return 'https://app.devin.ai/settings/playbooks/create?' + utm + '&body=' + encoded;
    if (type === 'knowledge') return 'https://app.devin.ai/knowledge?' + utm + '&body=' + encoded;
    if (agent === 'ada') return 'https://app.devin.ai/search?' + utm + '&noSubmit=true&prompt=' + encoded;
    return 'https://app.devin.ai/?tags=' + tag + '&' + utm + agentParams + '&prompt=' + encoded;
  };
  const ref = React.useRef(null);
  const [href, setHref] = React.useState('#');
  React.useEffect(() => {
    if (!ref.current) return;
    var codeEl = ref.current.querySelector('pre code');
    if (codeEl) {
      var text = codeEl.textContent.trim();
      if (text) setHref(buildUrl(text));
    }
    var header = ref.current.querySelector('[data-component-part="code-block-header"]');
    if (header && !header.querySelector('.prompt-block-devin-link')) {
      var link = document.createElement('a');
      link.href = href;
      link.target = '_blank';
      link.rel = 'noopener noreferrer';
      link.className = 'prompt-block-devin-link';
      link.style.cssText = 'display:inline-flex;align-items:center;gap:6px;text-decoration:none;color:#fff;font-size:11px;font-weight:500;padding:4px 10px;border-radius:6px;white-space:nowrap;background:#317CFF;transition:background 0.2s;margin-left:8px;';
      link.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg> ' + label;
      link.onmouseenter = function () {
        link.style.background = '#2968D9';
      };
      link.onmouseleave = function () {
        link.style.background = '#317CFF';
      };
      header.appendChild(link);
    }
    var existingLink = ref.current.querySelector('.prompt-block-devin-link');
    if (existingLink && href !== '#') existingLink.href = href;
  });
  return <div className="prompt-block" ref={ref}>{children}</div>;
};

<UseCaseHero title="インシデントのポストモーテムを自動生成" description="PagerDutyのインシデントが解決すると、Devinがタイムライン、根本原因の分析、アクションアイテムを含む構造化されたポストモーテムのドラフトを作成します。" prompt="PagerDutyからDevinへのポストモーテムパイプラインのセットアップを手伝ってください。https://docs.devin.ai/use-cases/gallery/api-pagerduty-postmortem のガイドに従って、Webhookブリッジのデプロイ、PagerDutyの設定、オブザーバビリティMCPの接続という各ステップを順に案内してください。" category="インシデント対応" features="API, MCP" />

<div className="uc-detail-wrapper">
  <Tip>PagerDuty 連携の詳細なガイドは、[こちら](/ja/enterprise/integrations/pagerduty)をご覧ください。</Tip>

  <Steps>
    <Step title="Webhook ブリッジをデプロイする">
      PagerDuty の `incident.resolved` イベントを受信し、ポストモーテムを作成するための Devin セッションを開始する小規模なサービスを作成します。これをサーバーレス関数 (AWS Lambda、Cloudflare Worker) または軽量コンテナとしてデプロイします：

      ```javascript theme={null}
      const express = require('express');
      const crypto = require('crypto');
      const app = express();
      app.use(express.json());

      function verifySignature(req) {
        const secret = Buffer.from(req.headers['x-webhook-secret'] || '');
        const expected = Buffer.from(process.env.WEBHOOK_SECRET || '');
        if (!expected.length) throw new Error('WEBHOOK_SECRET environment variable is not set');
        if (secret.length !== expected.length) return false;
        return crypto.timingSafeEqual(secret, expected);
      }

      app.post('/pagerduty-resolved', async (req, res) => {
        if (!verifySignature(req)) return res.status(401).send('Bad signature');

        const event = req.body?.event;
        if (!event || event.event_type !== 'incident.resolved') {
          return res.sendStatus(200);
        }

        const incident = event.data;
        const title = incident.title || 'Unknown incident';
        const service = incident.service?.summary || 'unknown-service';
        const urgency = incident.urgency || 'high';
        const incidentUrl = incident.html_url || '';
        const createdAt = incident.created_at || '';
        const resolvedAt = incident.resolved_at || new Date().toISOString();

        const orgId = process.env.DEVIN_ORG_ID;
        const response = await fetch(
          `https://api.devin.ai/v3/organizations/${orgId}/sessions`, {
          method: 'POST',
          headers: {
            'Authorization': `Bearer ${process.env.DEVIN_API_KEY}`,
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({
            prompt: [
              `A PagerDuty incident has been resolved. Draft a postmortem.`,
              ``,
              `Incident: "${title}"`,
              `Service: ${service}`,
              `Urgency: ${urgency}`,
              `Created: ${createdAt}`,
              `Resolved: ${resolvedAt}`,
              `Incident URL: ${incidentUrl}`,
              ``,
              `Write a structured postmortem:`,
              `1. Use the Datadog MCP to pull logs and metrics for ${service} during the incident window`,
              `2. Identify the root cause — check for deploys, config changes, or upstream failures`,
              `3. Build a detailed timeline from first alert to resolution`,
              `4. List action items to prevent recurrence`,
              `5. Post the postmortem as a PR to our docs/postmortems/ directory`,
            ].join('\n'),
            tags: ['pagerduty-postmortem', `service:${service}`],
          }),
        });

        const { session_id } = await response.json();
        console.log(`Started postmortem session ${session_id} for: ${title}`);
        res.sendStatus(200);
      });

      app.listen(3000);
      ```

      [app.devin.ai](https://app.devin.ai/?utm_source=docs\&utm_medium=use-case-gallery) の **設定 > サービスユーザー** で、`ManageOrgSessions` 権限を持つ[サービスユーザー](/ja/api-reference/v3/overview)を作成します。作成後に表示される API トークンをコピーし、ブリッジサービスで `DEVIN_API_KEY` として保存します。`DEVIN_ORG_ID` には組織 ID を設定します。組織 ID は、トークンを使って `GET https://api.devin.ai/v3/enterprise/organizations` を呼び出して取得できます。`WEBHOOK_SECRET` には、PagerDuty にも設定する共有シークレットを指定します。
    </Step>

    <Step title="PagerDuty の設定">
      1. PagerDuty で **Services > \[your service] > Integrations** に移動します
      2. **Add Integration** をクリックし、**Generic Webhooks (v3)** を選択します
      3. **Webhook URL** をブリッジのエンドポイントに設定します (例: `https://your-bridge.example.com/pagerduty-resolved`)
      4. **Custom Headers** で、`WEBHOOK_SECRET` として保存したものと同じ値の `X-Webhook-Secret` を追加します
      5. **Event Subscription** で、イベントタイプ `incident.resolved` で絞り込み、インシデントがクローズされた後にのみ事後検証がトリガーされるようにします

      <Note>
        インシデントの進行中に Devin がデータの収集を開始し、解決時に事後検証を完了できるようにしたい場合は、`incident.acknowledged` を購読することもできます。
      </Note>
    </Step>

    <Step title="可観測性MCPを接続する（任意）">
      Devin は、テレメトリデータにアクセスできると、より質の高いポストモーテムを作成できます。1 つ以上の MCP を有効にして、Devin がインシデント発生期間の実データを取得できるようにします。

      **Datadog MCP** — **Settings > Connections > MCP servers** に移動し、**Datadog** を見つけて **Enable** をクリックし、API キーと Application キーを入力します。Devin はログ、メトリクス、デプロイイベント、モニター履歴を照会します。

      **Sentry MCP** — MCP Marketplace で **Sentry** を見つけ、**Enable** をクリックして OAuth フローを完了します。Devin はエラーの詳細、スタックトレース、リリースタグを取得します。

      接続が完了すると、Devin はテレメトリをインシデントのタイムラインに自動的に関連付け、根拠に基づくポストモーテムを作成します。詳しくは、[MCP サーバーの接続](/ja/work-with-devin/mcp)をご覧ください。
    </Step>

    <Step title="Devinが生成するもの">
      PagerDuty インシデントが解決すると、Devin はインシデント発生から解決までの時間帯を分析し、構造化されたポストモーテムを作成します。

      <PromptBlock>
        ```txt インシデントのポストモーテムを生成 theme={null}
        PagerDuty インシデントが解決されました。ポストモーテムを作成してください。

        インシデント: "orders-service でのデータベース接続プール枯渇"
        サービス: orders-service
        作成日時: 2026-02-10T14:32:00Z
        解決日時: 2026-02-10T15:18:00Z

        Datadog と Sentry の MCP を利用して:
        1. 14:00〜15:30 UTC の orders-service のログとメトリクスを取得する
        2. その時間帯にデプロイ、設定変更、または上流の障害がなかったか確認する
        3. 最初のアラートから解決までの詳細なタイムラインを作成する
        4. 要因と根本原因を特定する
        5. 再発防止のためのアクションアイテムを作成する
        6. ポストモーテムを Markdown ファイルとして docs/postmortems/ にコミットする
        ```
      </PromptBlock>

      Devin が生成するポストモーテムの例:

      ```markdown theme={null}
      # Postmortem: Database Connection Pool Exhaustion — orders-service
      **Date:** 2026-02-10 | **Duration:** 46 minutes | **Severity:** P1

      ## Summary
      orders-service experienced connection pool exhaustion between
      14:32 and 15:18 UTC, causing 502 errors for ~12% of order
      placement requests.

      ## Timeline
      - 14:15 UTC — Deploy #387 released (commit e4f29a1)
      - 14:28 UTC — Connection pool usage climbed from 60% to 92%
      - 14:32 UTC — Pool exhausted; PagerDuty incident triggered
      - 14:38 UTC — On-call engineer acknowledged
      - 14:45 UTC — Identified Deploy #387 added a new inventory
                    check that opens a DB connection per line item
                    without releasing it in the finally block
      - 15:02 UTC — Rollback to Deploy #386 initiated
      - 15:18 UTC — Connection pool recovered; incident resolved

      ## Root Cause
      Deploy #387 introduced `checkInventoryAvailability()` in
      `src/services/orders.ts:142`. The function opens a new DB
      connection for each line item in an order but only releases
      it on the success path. When inventory checks fail (timeout
      or stock unavailable), connections leak.

      Orders with 5+ line items reliably exhausted the pool within
      15 minutes of the deploy.

      ## Action Items
      - [ ] Fix connection leak: add `finally` block to release
            connection (PR #388 opened)
      - [ ] Add connection pool usage monitor with alert at 80%
      - [ ] Add integration test for multi-item orders with
            simulated inventory failures
      - [ ] Review other DB access patterns for similar leak risks
      ```
    </Step>

    <Step title="ポストモーテムをカスタマイズする">
      チームのポストモーテムプロセスに合わせて、パイプラインを調整します。

      **[Playbook](/ja/product-guides/creating-playbooks) を利用する**と、ポストモーテムのテンプレート (セクション、重大度の分類、必須項目、出力の保存先) を定義できます。すべてのポストモーテムを標準化するには、API リクエストで `playbook_id` を渡します。

      **重大度に応じて振り分けます。** ブリッジにロジックを追加し、P1/P2 インシデントについてのみポストモーテムを生成するようにします。重大度の低いインシデントでは、完全なレポートが不要な場合があります。

      **アーキテクチャ、サービスの担当範囲、過去のインシデントに関する [Knowledge](/ja/product-guides/knowledge) を追加します。** これにより、Devin が情報同士のつながりを把握できるようになります。たとえば、「orders-service は inventory-service に依存しており、inventory-service は高負荷時にタイムアウトが発生しやすいことで知られている」といった情報です。

      **wiki に投稿します。** リポジトリにコミットする代わりに、セッションプロンプトを通じて Devin に Confluence、Notion、または社内 wiki へポストモーテムを投稿させます。
    </Step>
  </Steps>
</div>
