> ## 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.

# Datadog アラートを自動調査する

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="Datadog アラートの自動調査" description="PagerDuty または Datadog のアラートを Devin と連携させて、インシデントを自動で調査します。" prompt="Datadog から Devin へのアラート調査パイプラインのセットアップを手伝ってください。https://docs.devin.ai/use-cases/gallery/api-datadog-alert-investigation のガイドに従い、Datadog MCP を有効化する手順、webhook ハンドラーを作成する手順、それを Datadog モニターに接続する手順について、各ステップを順を追って案内してください。" category="インシデント対応" features="API, MCP" />

<div className="uc-detail-wrapper">
  <Tip>Datadog インテグレーションの詳細なガイドは、[こちら](/ja/enterprise/integrations/datadog)をご覧ください。</Tip>

  <Steps>
    <Step title="Datadog MCP を有効にする">
      Devin が調査中にログ、メトリクス、モニターをクエリできるようにするには、Datadog アカウントへのアクセス権が必要です。

      1. **Settings > Connections > MCP servers** に移動し、**Datadog** を探します
      2. **Enable** をクリックし、Datadog のサイト/リージョンを選択して、`DD-API-KEY` と `DD-APPLICATION-KEY` を入力します — これらは [Datadog > Organization Settings > API Keys](https://app.datadoghq.com/organization-settings/api-keys) で生成できます
      3. **Test listing tools** をクリックして、Devin が接続できることを確認します

      有効化すると、Devin はセッション内でエラーログのクエリ、メトリクスの時系列の取得、アクティブなモニターの一覧表示、トレースの検索を行えるようになります。[MCP サーバーの接続](/ja/work-with-devin/mcp) について詳しくご覧ください。
    </Step>

    <Step title="アラートからDevinへの連携を構築する">
      アラート Webhook を受信し、[Devin API](/ja/api-reference/overview) を通じて Devin セッションを開始する小さなサービスを用意します。これはサーバーレス関数 (AWS Lambda、Cloudflare Worker) または軽量コンテナとしてデプロイします。

      ```python theme={null}
      from flask import Flask, request, jsonify
      import requests, os

      app = Flask(__name__)

      @app.route("/alert", methods=["POST"])
      def handle_alert():
          payload = request.json

          # Datadog Webhook のペイロードフィールド
          alert_title = payload.get("title", "Unknown alert")
          tags_str = payload.get("tags", "")
          service = next(
              (t.split(":", 1)[1] for t in tags_str.split(",") if t.strip().startswith("service:")),
              "unknown-service"
          )
          alert_url = payload.get("link", "")

          org_id = os.environ["DEVIN_ORG_ID"]
          response = requests.post(
              f"https://api.devin.ai/v3/organizations/{org_id}/sessions",
              headers={"Authorization": f"Bearer {os.environ['DEVIN_API_KEY']}"},
              json={
                  "prompt": (
                      f"Datadog alert fired: '{alert_title}'\n"
                      f"Service: {service}\n"
                      f"Alert link: {alert_url}\n\n"
                      "Using the Datadog MCP:\n"
                      "1. Pull error logs for this service from the past 30 min\n"
                      "2. Identify the top error messages and stack traces\n"
                      "3. Check if this correlates with a recent deploy\n"
                      "4. If the root cause is clear, open a hotfix PR\n"
                      "5. Post your findings to #incidents on Slack"
                  ),
                  "playbook_id": "14fed18b89d44713a26e673cf258f548",
              }
          )
          return jsonify(response.json()), 200
      ```

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

      上記のコードは、[`!triage` テンプレートプレイブック](https://app.devin.ai/settings/playbooks/14fed18b89d44713a26e673cf258f548?utm_source=docs\&utm_medium=use-case-gallery) を使用しています — これを複製して自分のスタック向けに調査手順をカスタマイズし、ブリッジサービス内の `playbook_id` を更新してください。
    </Step>

    <Step title="アラートを Webhook に送信する">
      **Datadog から直接設定する場合:**

      1. Datadog ダッシュボードで **Integrations > Webhooks** に移動します
      2. **New Webhook** をクリックし、URL をブリッジのエンドポイントに設定します (例: `https://your-bridge.example.com/alert`)
      3. 任意のモニターの通知メッセージに `@webhook-devin-bridge` を追加します — そのモニターが発報されるたびに Devin が調査します

      **PagerDuty から設定する場合:**

      1. PagerDuty で **Services > \[your service] > Integrations** に移動します
      2. **Generic Webhooks (v3)** インテグレーションを追加します
      3. Webhook URL をブリッジのエンドポイントに設定し、イベントタイプ `incident.triggered` でフィルタリングします

      まずは warning レベルのモニターでパイプラインをテストしてから、重大なアラートをルーティングしてください。
    </Step>

    <Step title="Devin が調査する内容">
      アラートによってセッションが開始されると、Devin は Datadog MCP を使って構造化された調査を行い、ログをクエリしてデプロイとの相関を分析し、エラーの原因をソースコードまで追跡します。

      <PromptBlock>
        ```txt Investigate Datadog alert theme={null}
        Datadog alert: "High error rate on payments-service (5.2%, threshold 1%)"
        fired at 2026-02-10 14:32 UTC.

        Using the Datadog MCP:
        1. Pull error logs for payments-service from the past 30 minutes
        2. Group by error message — what's the dominant failure?
        3. Check Datadog events for recent deploys to payments-service
        4. Read the relevant source code and recent commits for the failing path
        5. If fixable, open a PR with a hotfix. Otherwise, post findings to #incidents.
        ```
      </PromptBlock>

      Devin が Slack に投稿する調査結果の例：

      ```
      アラート調査: payments-service エラー率急増

      タイムライン:
      - 14:28 UTC — Deploy #492 リリース (commit abc123f)
      - 14:31 UTC — エラー率が 0.3% から 5.2% に急増
      - 14:32 UTC — アラート発報

      根本原因: Deploy #492 で Stripe webhook ハンドラー
      (src/webhooks/stripe.ts) を async/await にリファクタリングした際、
      handlePaymentIntent() を囲む try/catch が削除された。
      未処理の rejection により、チェックアウトリクエストの約 4% で 500 エラーが返されている。

      修正: エラーバウンダリーを追加し、構造化ログおよびクライアントエラーに対する適切な 4xx レスポンスを実装。

      PR #493 作成済み → https://github.com/acme/payments/pull/493
      ```
    </Step>

    <Step title="パイプラインを拡張する">
      基本的な調査がうまく回るようになったら、さらに自動化を重ねていきます。

      **トリアージ用プレイブックをカスタマイズする。** ブリッジコードはすでに [`!triage` テンプレートプレイブック](https://app.devin.ai/settings/playbooks/14fed18b89d44713a26e673cf258f548?utm_source=docs\&utm_medium=use-case-gallery) を使用しています。これを複製し、チームのスタックに合わせて調査チェックリストを調整します。サービス固有のランブック、エスカレーションパス、ホットフィックス用 PR の運用ルールなどを追加してください。

      **重大度でスコープを切る。** P1 アラートは即時調査とホットフィックスの対象にします。P3 アラートは根本原因分析のみを行う対象にします。重大度ごとに異なるプロンプトやプレイブックを使い分けてください。

      **サービスに関する [Knowledge](/ja/product-guides/knowledge) を追加する** — 通常のしきい値、アーキテクチャ、オンコール用ランブックなどを登録しておくことで、Devin の調査をゼロからではなく、チームのコンテキストを前提に開始できるようにします。
    </Step>
  </Steps>
</div>
