SuperAPI AI 工具集

sentry-cloudflare-sdk

部署与运维

查看项目

更新于 10-15 21:51

技能介绍

用途:为 Cloudflare Workers 和 Pages 项目完整接入 Sentry SDK,覆盖错误监控、追踪、日志、定时任务、Durable Objects、Queues、Workflows、D1 与 Hono 等场景。当用户要求为 Cloudflare Workers 添加 Sentry、安装或配置 @sentry/cloudflare,或需要 withSentry、sentryPagesPlugin、instrumentDurableObjectWithSentry、instrumentD1WithSentry 等用法时触发。

检测阶段:通过查看 wrangler.toml/wrangler.jsonc、package.json、functions 目录等,判断是 Workers 还是 Pages、是否使用 Hono、是否已有 @sentry/cloudflare、是否配置 Durable Objects、D1、Queues、Workflows、Cron 触发器、AI/LLM 库及兼容性标志。

推荐阶段:错误监控与追踪为核心,日志、Crons、D1、Durable Objects、Workflows、AI Monitoring 按检测结果建议。

接入前提:SDK 依赖 AsyncLocalStorage,需在 Wrangler 配置中加入 compatibility_flags = ["nodejs_als"] 或 ["nodejs_compat"]。安装命令为 npm install @sentry/cloudflare。Workers 用 Sentry.withSentry 包装默认导出;Pages 用 Sentry.sentryPagesPlugin 作为中间件;Hono 推荐使用 @sentry/hono 独立包。DSN 应通过 npx wrangler secret put SENTRY_DSN 存储,不硬编码。源码映射可用 npx @sentry/wizard@latest -i sourcemaps 或 @sentry/vite-plugin 配置。

限制:文档版本为 @sentry/cloudflare v10.61.0,API 可能变化,实施前应核对官方文档;Cloudflare 无专用向导集成,sourcemaps 向导仅处理源码映射上传。