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

# 端到端调试 Bug 报告

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="端到端排查一个 Bug 报告" description="将包含 Datadog 日志和数据库访问权限的缺陷报告交给 Devin，即可获得根因分析和修复 PR。" prompt="使用 Datadog MCP 查找过去 24 小时内生产环境中最频繁出现的错误。获取完整的堆栈跟踪和相关日志，查询只读数据库副本以获取相关数据，在代码库中定位问题根因，并发起一个包含修复和回归测试的 PR。" category="事件响应" features="MCP" />

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

  <Steps>
    <Step title="连接 Datadog">
      Devin 需要访问你的 Datadog 日志，以搜索与该 bug 相关的错误。如果你尚未启用，请先开启 Datadog MCP：

      1. 前往 **Settings > Connections > MCP servers**，找到 **Datadog**
      2. 点击 **Enable**，选择你的 Datadog 站点/区域，并提供两个请求头：
         * `DD-API-KEY` — 来自你的 [Datadog API keys 页面](https://app.datadoghq.com/organization-settings/api-keys)
         * `DD-APPLICATION-KEY` — 来自你的 [Datadog application keys 页面](https://app.datadoghq.com/organization-settings/application-keys)

      连接完成后，Devin 可以搜索日志、拉取错误追踪信息，并将问题与部署关联——全部在当前会话内完成。完整的设置细节请参见 [MCP Marketplace](/zh/integrations/overview)。
    </Step>

    <Step title="为 Devin 授予数据库的只读访问权限">
      对于数据类 bug —— 错误的数值、缺失的字段、出错的查询 —— 当 Devin 能够直接验证数据状态时，效果会显著更好。将只读连接字符串作为 [Secret](/zh/product-guides/secrets) 传入：

      1. 前往 **Settings > Secrets** 并添加一个新的 Secret：
         * **Name**: `DATABASE_READ_REPLICA_URL`
         * **Value**: `postgresql://readonly_user:password@read-replica.internal:5432/production`
      2. 添加类似这样的备注：*“Read-only connection to the production read replica. Safe for SELECT queries only.”*

      或者，在 **Settings > Connections > MCP servers** 中连接一个数据库 MCP (PostgreSQL、MySQL 等) ——Devin 可以通过任一方式查询你的数据。

      <Tip>始终使用只读副本或仅具有 SELECT 权限的用户。Devin 在排查 bug 时从不需要写入权限。如果你担心高开销查询影响性能，可以让 Devin 指向一个专用只读副本，或一个与生产数据库分离的现有分析副本。</Tip>
    </Step>

    <Step title="将错误报告发送给 Devin">
      将 bug 报告直接粘贴到 Devin 会话中。尽量包含报告者提供的全部上下文——问题什么时候开始、受影响的是谁、出了什么问题、以及发生在什么位置。若需要结构化排查，可以使用 [`!triage` 模板 playbook](https://app.devin.ai/settings/playbooks/14fed18b89d44713a26e673cf258f548?utm_source=docs\&utm_medium=use-case-gallery)——复制一份，并根据你的技术栈自定义各个步骤。

      <PromptBlock>
        ```txt Debug billing page bug theme={null}
        Bug report from support: Pro plan users are seeing "undefined" instead of
        their company name on the billing page. This started after last Friday's
        deploy (around 2026-02-13 18:00 UTC).

        Steps to investigate:
        1. Use Datadog to pull error logs for the billing service since Friday —
           look for null reference errors or API response changes
        2. Query the read replica to check whether Pro plan users actually have a
           company_name value: SELECT id, company_name, plan FROM users WHERE plan = 'pro' LIMIT 20
        3. Check git log for Friday's deploy — what changed in the billing page
           or user API response?
        4. Identify the root cause and fix it
        5. Add a regression test that would catch this if it happened again
        6. Run the app locally and verify the billing page renders correctly
           using your browser
        7. Open a PR with the fix
        ```
      </PromptBlock>

      报告越具体，Devin 找到答案就越快。“自上周五的部署以来”可以让 Devin 缩小 Datadog 的时间窗口，“Pro plan 用户”则能精确限定需要查询的记录。
    </Step>

    <Step title="Devin 会排查和修复问题">
      在接入 Datadog 并配置好数据库访问后，Devin 会执行一次完整的排查：

      **拉取 Datadog 日志** — 从周五起搜索计费服务 (billing service) 的错误日志，按服务名和错误状态进行过滤。发现从部署当天 UTC 时间 18:12 开始，`TypeError: Cannot read property 'name' of undefined` 错误开始激增。

      **查询数据库** — 在只读副本上运行 `SELECT id, company_name, plan FROM users WHERE plan = 'pro' LIMIT 20`。确认 Pro 用户确实*有* `company_name` 字段值——数据没有问题，因此 bug 出在代码中。

      **追踪代码变更** — 检查 `git log --since="2026-02-13"`，发现提交 `a1b2c3d` 重构了用户 API 响应，把 `company` 重命名为 `organization`。而位于 `src/pages/billing/BillingHeader.tsx` 的计费页面仍然引用 `user.company.name`。

      **编写修复** — 将 `BillingHeader.tsx` 更新为使用 `user.organization?.name ?? 'Your Company'`，并添加一个回归测试，用旧的和新的 API 响应结构分别渲染该组件。

      **在浏览器中验证** — 启动开发服务器，在 Devin 内置浏览器中打开计费页面，并确认测试用户的公司名称现在可以正确渲染。

      **创建一个 PR**，其中包含修复代码、测试，以及说明根本原因和影响范围 (所有 Pro 和 Enterprise 用户，约 350 个账户) 。
    </Step>

    <Step title="后续跟进">
      一旦修复 PR 合并完成后，你可以让 Devin 排查相关问题或添加监控：

      <PromptBlock>
        ```txt Find other references to the old field theme={null}
        The root cause was user.company being renamed to user.organization in the
        API response. Search the entire frontend for other references to
        "user.company" and update them all.
        ```
      </PromptBlock>

      如果你希望 Devin 在下次也记住这次排查中的某些信息，只需直接告诉它——例如，*"记住 user API 使用的是 `user.organization`，而不是 `user.company`。"* Devin 会建议创建一个 [Knowledge](/zh/product-guides/knowledge) 条目，供你查看和保存。这样，后续会话就会从你团队已经掌握的上下文开始。
    </Step>
  </Steps>
</div>
