Skip to main content

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.

概述

PagerDuty 可与 Devin 集成,作为一种告警路由机制。当 PagerDuty 中发生事件时,会通过轻量级 webhook 桥接层,借助 Devin API 触发 Devin 会话。随后,Devin 会自动调查该事件——拉取遥测数据、追查根因,并可选地创建修复 PR。 这种模式与 Datadog MCP 集成 结合使用时尤其有效:PagerDuty 将告警路由给 Devin,而 Devin 则使用 Datadog 调查日志和指标。

设置

1

部署一个 webhook 桥接服务

构建一个小型处理程序,用于接收 PagerDuty 事件负载,并调用 Devin API 启动调查会话。Settings > Service Users 中创建一个具有 ManageOrgSessions 权限的服务用户。将 API 令牌存储为 DEVIN_API_KEY,将你的组织 ID 存储为 DEVIN_ORG_ID,并在桥接服务上将共享密钥存储为 WEBHOOK_SECRET。下一步中,你将在 PagerDuty webhook 的 Custom Headers 中配置这个相同的密钥。
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-alert', async (req, res) => {
  if (!verifySignature(req)) return res.status(401).send('Bad signature');

  const event = req.body?.event;
  if (!event || event.event_type !== 'incident.triggered') {
    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 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: [
        `PagerDuty incident triggered: "${title}"`,
        `Service: ${service}`,
        `Urgency: ${urgency}`,
        `Incident URL: ${incidentUrl}`,
        ``,
        `Investigate this incident:`,
        `1. Check recent logs and metrics for ${service}`,
        `2. Identify the root cause of the issue`,
        `3. If the root cause is a code issue, open a hotfix PR`,
        `4. Post your findings to #incidents on Slack`,
      ].join('\n'),
      tags: ['pagerduty-triage', `service:${service}`],
    }),
  });

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

app.listen(3000);
将它部署到任何能够接收 HTTPS 流量的地方,例如 Cloudflare Worker、AWS Lambda 或一个小型容器。
2

在 PagerDuty 中添加 webhook 集成

  1. 在 PagerDuty 中,前往 Services > [your service] > Integrations
  2. 点击 Add Integration,然后选择 Generic Webhooks (v3)
  3. Webhook URL 设置为你的桥接服务端点 (例如:https://your-bridge.example.com/pagerduty-alert)
  4. Custom Headers 下,添加 X-Webhook-Secret,其值与您在桥接服务上存储为 WEBHOOK_SECRET 的值相同
  5. Event Subscription 下,按事件类型 incident.triggered 进行筛选,以便仅在新事件触发时发送 webhook
3

验证流程

在 PagerDuty 中触发一个测试事件 (或使用测试服务) ,并确认:
  1. 你的桥接服务收到了 webhook 负载
  2. app.devin.ai 中已创建一个新的 Devin 会话
  3. Devin 已开始调查该事件

最佳实践

  • 从 warning 级别的监控开始。 在将生产环境中的 P1 告警路由到 Devin 之前,先用非关键事件测试这条流程。
  • 按服务或严重程度过滤。 使用 PagerDuty 的 webhook 事件订阅,或在你的桥接服务中添加逻辑,跳过低优先级或噪声较大的服务。这样可以避免 Devin 被价值较低的告警淹没。
  • 针对不同严重程度使用不同的 playbooks。 将 P1 告警路由到立即调查和热修复流程。将 P3 告警仅路由到根因分析。根据紧急程度,在 Devin API 请求中传入不同的 playbook_id 值。
  • 为会话添加标签以便跟踪。 示例代码会为每个会话添加 pagerduty-triage 和服务名称标签,方便你在 Devin 控制台中过滤和查看。

结合 Datadog 使用

PagerDuty 通常与 Datadog MCP 集成 配合使用。在这种模式下:
  1. PagerDuty 将告警路由到 Devin (触发调查会话)
  2. Devin 使用 Datadog MCP 查询受影响服务的日志、指标和追踪数据
这样,Devin 既能获得来自 PagerDuty 的告警上下文,也能获取来自 Datadog 的深度可观测性数据,从而进行更全面的调查。
添加有关你的服务架构和 on-call 运行手册的 Knowledge,这样 Devin 就能自动遵循你团队的调查流程。