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

# Sentry エラーの日次修正

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="毎日の Sentry エラー修正" description="毎日 1 回、夜間に新しい Sentry エラーを取得し、それぞれに対して修正セッションを起動し、朝までに PR を用意する Devin セッションをスケジュールします。" prompt="Sentry MCP を使って、過去 24 時間の payments-api プロジェクトから、未解決エラーをイベント数の多い順に並べてすべて取得してください。上位 5 件のエラーについて、スタックトレースと根本原因を調査し、それぞれに対して Devin セッションを開始して、修正および回帰テスト付きの PR を作成します。wontfix または expected-behavior のタグが付いたエラーは除外してください。" category="自動化" features="スケジュール, MCP, 高度" type="schedule" agent="advanced" />

<div className="uc-detail-wrapper">
  <Tip>より詳細な Sentry 統合ガイドについては、[こちら](/ja/enterprise/integrations/sentry)をご覧ください。</Tip>

  <Steps>
    <Step title="Sentry MCP を接続する">
      スケジュールを作成する前に、Devin があなたの Sentry データにアクセスできるようにする必要があります。

      1. **Settings > Connections > MCP servers** に移動し、**Sentry** を検索します
      2. **Enable** をクリックし、OAuth で認証します — これにより Devin にあなたの Sentry の issue、event、および stack trace への読み取りアクセス権が付与されます
      3. 接続が正常に動作していることを確認するために、**Test listing tools** をクリックします

      接続が完了すると、Devin はセッション内から Sentry プロジェクトをクエリし、issue の詳細や stack trace を取得し、breadcrumbs を読み取れるようになります。[MCP サーバーの設定](/ja/work-with-devin/mcp)について詳しくはこちらを参照してください。
    </Step>

    <Step title="スケジュールを作成">
      **Settings > [Schedules](/ja/product-guides/scheduled-sessions)** に移動し、**Create schedule** をクリックします。

      * **Name**: `Daily Sentry remediation — payments-api`
      * **Frequency**: 毎日午前 6:00 (スタンドアップ前に修正用 PR が準備できるように)
      * **Agent**: Devin — Devin がエラーごとに個別のセッションを起動し、修正を並列で実行できるようにします
      * **Slack channel**: チャンネル (例: `#sentry-fixes`) を選択します。実行が完了して PR のレビュー準備が整ったら、チームに通知されるようにします
      * **Prompt**:

      <PromptBlock type="schedule" agent="advanced">
        ```txt Daily Sentry remediation theme={null}
        Sentry MCP を使って、過去 24 時間に payments-api プロジェクトで
        発生した未解決エラーを、イベント数でソートして取得してください。
        タグが `wontfix` または `expected-behavior` のエラーはスキップします。

        上位 5 件のエラーについて:
        1. フルスタックトレースとブレッドクラムを取得する
        2. リポジトリ内の関連ソースファイルを特定する
        3. 根本原因を特定する
        4. 修正と回帰テストを含む PR を作成する Devin セッションを開始し、
           PR の説明に Sentry の Issue URL をリンクする

        すべてのエラーと対応する PR のサマリーを Slack に投稿する。

        いずれかの PR に対して、誤検知としてマークする、別のアプローチを
        要求する、あるいはパターンを承認するといったフィードバックを残した
        場合には、そのフィードバックを記録する Knowledge エントリを作成し、
        今後の実行で同様のエラーを正しく処理できるようにする。
        ```
      </PromptBlock>
    </Step>

    <Step title="コードベースや過去の修正をもとに Knowledge を構築する">
      Devin は、あなたのアプリのエラーパターンを理解していると、より質の高い修正を書けます。自分で Knowledge エントリを書く代わりに、任意のセッションで Devin にコードベースと過去の修正を調査させ、Knowledge を作成させましょう。

      <PromptBlock agent="advanced">
        ```txt 私たちのエラーパターンを学習して Knowledge を作成する theme={null}
        payments-api のコードベースを調査し、よくあるエラーパターン向けに
        Knowledge エントリを作成してください:

        1. Sentry エラーを修正した最近マージ済みの PR を読み、何が壊れ、
           どのように修正されたかのパターンを探す
        2. 解決済みの Sentry issue を確認し、繰り返し発生している根本原因
           （null チェック、N+1 クエリ、エラーバウンダリ欠如など）を特定する
        3. コードベース内のエラーハンドリング規約を確認する — 使用している
           ラッパークラス、エラーのログ方法、リトライ／フォールバックパターン

        見つけた各パターンごとに、特定のトリガー（例: "TypeError in checkout",
        "database timeout in reports"）と、具体的な修正手順を含む
        Knowledge エントリを作成してください。
        ```
      </PromptBlock>

      これらのエントリは、Devin がスケジュールされた実行中に一致するエラーに遭遇したときに自動的に参照されます。また、上記のスケジュール済みプロンプトによって、PR フィードバックに基づいて Knowledge を更新するよう Devin に指示するため、時間の経過とともに精度が向上していきます。
    </Step>

    <Step title="通常の実行で得られる結果">
      毎朝、Devin は夜間のエラーキューを処理し、対象を絞った PR を作成します。以下が実際のセッション出力です：

      ```
      Processed 5 Sentry errors from payments-api (past 24h):

      1. TypeError: Cannot read property 'last4' of null (1,892 events)
         Root cause: Stripe webhook delivers `payment_method: null` for
         bank transfer payments. CheckoutReceipt.tsx:34 destructures
         without a null check.
         PR #612: Add null safety to CheckoutReceipt, show "Bank Transfer"
         fallback for non-card payments.

      2. TimeoutError: Query timeout after 30s on /api/invoices (743 events)
         Root cause: N+1 query in InvoiceService.getMonthly() — each
         line item triggers a separate product lookup.
         PR #613: Add eager loading for invoice line items with
         Sequelize `include`.

      3. RangeError: Maximum call stack size exceeded (412 events)
         Root cause: Circular reference in refund.toJSON() when a
         refund references its parent transaction which references
         the refund.
         PR #614: Break circular ref with a custom serializer,
         add max-depth test.

      4-5. Two lower-frequency validation errors — PRs #615, #616.
      ```

      各PRには、SentryのIssueへのリンク、根本原因の説明、修正内容、および元のエラーを検出できたはずのテストが含まれます。
    </Step>

    <Step title="チューニングと反復">
      1週間ほど運用したら、うまくいっている点を確認し、調整します:

      **対象とするエラー数を決める。** まずは実行ごとに `top 5` 件のエラーから始めます。Devin が継続的にマージ可能な PR を作成できている場合は、8〜10件に増やします。修正に大幅な手直しが必要な場合は、3件に減らします。

      **プロジェクトやタグで絞り込む。** プロンプトを特定の Sentry プロジェクト (`payments-api`、`web-frontend`) に絞り込んだり、ノイズとなるタグを除外したりします。エラー件数が異なる場合は、プロジェクトごとに別々のスケジュールを作成できます。

      **結果から学習する。** 2週間ほど経ったら、どの修正が実際にリリースされたかを Devin に分析させ、それを Knowledge に反映します:

      <PromptBlock agent="advanced">
        ```txt Analyze Sentry fix outcomes and update Knowledge theme={null}
        Look at all PRs Devin opened for Sentry errors in the last 2 weeks.
        For each PR, check whether it was merged or closed.

        Identify themes and learnings — which fix patterns worked, which
        approaches were rejected, what types of errors were false positives,
        and where Devin lacked context. Then update your Knowledge
        accordingly: create new entries, edit existing ones, or delete
        entries that led to bad fixes.
        ```
      </PromptBlock>
    </Step>
  </Steps>
</div>
