> ## 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="安排一个每日的 Devin 会话，在夜间拉取新的 Sentry 错误，为每个错误启动修复会话，并在早晨前准备好 PR。" prompt="使用 Sentry MCP 从 payments-api 项目中拉取过去 24 小时内所有未解决的错误，并按事件数量排序。针对排名前 5 的错误，分析其堆栈追踪和根本原因，然后为每个错误启动一个 Devin 会话，以打开包含修复和回归测试的 PR。跳过带有 wontfix 或 expected-behavior 标签的错误。" category="自动化" features="计划, MCP, 高级" type="schedule" agent="advanced" />

<div className="uc-detail-wrapper">
  <Tip>如需更详细的 Sentry 集成指南，请[点击此处](/zh/enterprise/integrations/sentry)。</Tip>

  <Steps>
    <Step title="连接 Sentry MCP">
      在创建计划之前，Devin 需要访问你的 Sentry 数据。

      1. 前往 **Settings > Connections > MCP servers** 并搜索 **Sentry**
      2. 点击 **Enable** 并通过 OAuth 进行身份验证 —— 这将授予 Devin 对你的 Sentry 问题 (issues) 、事件 (events) 和堆栈跟踪 (stack traces) 的只读访问权限
      3. 点击 **Test listing tools** 以验证连接是否正常

      连接成功后，Devin 可以在会话中查询你的 Sentry 项目、获取问题详情和堆栈跟踪，并读取面包屑数据。了解更多：[配置 MCP 服务器](/zh/work-with-devin/mcp)。
    </Step>

    <Step title="创建日程安排">
      Go to **Settings > [Schedules](/zh/product-guides/scheduled-sessions)** and click **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. 拉取完整堆栈追踪和 breadcrumbs
        2. 在我们的代码库中找到相关源文件
        3. 找出根本原因
        4. 启动一个 Devin 会话，打开一个包含修复和回归测试的 PR，
           并在 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（pull request，拉取请求）——查找
           出错方式及其修复方式中的模式
        2. 检查已解决的 Sentry 问题中是否存在反复出现的根本原因
           （空值检查、N+1 查询、缺失错误边界）
        3. 查看我们在代码库中的错误处理规范——
           我们使用哪些包装类、如何记录错误日志、
           我们的重试/回退模式

        对于你发现的每种模式，创建一个带有
        明确触发条件（例如："TypeError in checkout"、"database
        timeout in reports"）且包含可执行修复指导的 Knowledge 条目。
        ```
      </PromptBlock>

      当 Devin 在计划任务运行期间遇到匹配的错误时，这些条目会被自动调用——而上面的定时提示会指示 Devin 基于你的 PR 反馈更新 Knowledge，从而随着时间的推移不断改进。
    </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 (pull request) 都包含一个 Sentry issue 链接、根因说明、修复方法，以及一项本可以捕获该原始错误的测试。
    </Step>

    <Step title="优化与迭代">
      运行一周后，查看哪些有效并进行调整：

      **限定错误数量范围。** 每次运行先从 `top 5` 个错误开始。如果 Devin 能稳定产出可直接合并的拉取请求 (PR)，可以增加到 8-10 个。如果修复需要大量人工修改，就降低到 3 个。

      **按项目或标签过滤。** 将提示缩小到特定的 Sentry 项目 (`payments-api`、`web-frontend`)，或排除噪声较大的标签。如果不同项目的错误量差异较大，可以为每个项目单独设置运行计划。

      **从结果中学习。** 运行几周后，让 Devin 分析哪些修复实际已经上线，并将结论整理进 Knowledge：

      <PromptBlock agent="advanced">
        ```txt 分析 Sentry 修复结果并更新 Knowledge theme={null}
        查看过去 2 周内，Devin 为 Sentry 错误创建的所有 PR。
        对每个 PR，检查它是被合并还是被关闭。

        识别其中的共性和经验——哪些修复模式有效、哪些
        方法被拒绝、哪些错误属于误报，以及 Devin 缺乏
        上下文的地方。然后相应更新你的 Knowledge：
        新增条目、编辑现有条目，或删除导致错误修复的条目。
        ```
      </PromptBlock>
    </Step>
  </Steps>
</div>
