@sentry/cloudflare/vite: Auto-instrumentation skips the Worker when wrangler `main` is a package specifier
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 58/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript, vite
- Lĩnh vực
- backend, build-system
Hướng nghiên cứu
Start with packages/cloudflare/src/vite/wranglerConfig.ts, autoInstrument.ts, and instrumentFile.ts, then inspect the existing Cloudflare Vite test fixtures. Trace how Wrangler's main value is resolved and compared with transformed module IDs. Done means package-specifier entries are instrumented, node_modules entries find the project instrument file, unmatched entries produce a warning, and a package-specifier fixture passes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
sentryCloudflareVitePlugin() does not wrap the Worker when main in the Wrangler config is a package specifier and not a file path. The build succeeds, but the bundle contains no Sentry code, and the plugin logs no warning.
@cloudflare/vite-plugin supports this config, and vinext generates it by default with vinext init --platform=cloudflare:
// wrangler.jsonc
{
"main": "vinext/server/fetch-handler",
// ...
}
// vite.config.ts
export default defineConfig({
plugins: [
vinext(),
cloudflare({ viteEnvironment: { name: "rsc", childEnvironments: ["ssr"] } }),
sentryCloudflareVitePlugin(),
],
});
Tested with @sentry/cloudflare@11.0.0-rc.0, @cloudflare/vite-plugin@1.56.0, wrangler@4.135.0, vinext@1.0.0-beta.10 and Vite 8.3.
Cause
resolveWranglerConfig() calls unstable_readConfig() without preserveOriginalMain (wranglerConfig.ts#L70). Wrangler then resolves every main as a path relative to the config file:
main: "vinext/server/fetch-handler"
-> <project>/vinext/server/fetch-handler (file does not exist)
autoInstrument.ts compares this path with the module IDs in transform (L75), so no module matches. resolveInstrumentFile() also looks for instrument.server.* in the directory of this path (instrumentFile.ts#L23), and a package entry has no such file.
@cloudflare/vite-plugin handles the same value differently:
- It reads the config with
unstable_readConfig(..., { preserveOriginalMain: true }). maybeResolveMain()makesmainabsolute only when it ends with a JS or TS extension.- It resolves the entry with Vite:
await this.resolve(workerConfig.main).
Workaround
Add a local entry that re-exports the package entry, and set main to it. Put instrument.server.ts in the same directory:
// worker/index.ts
import handler from "vinext/server/fetch-handler";
export default handler;
{ "main": "./worker/index.ts" }
Proposed fix
- Read the config with
preserveOriginalMain: true, and keep a package specifier unchanged. - Resolve
mainwiththis.resolve()(for example inbuildStart, or lazily intransform), and compare the resolved module ID. - When the resolved entry is in
node_modules, look forinstrument.server.*in the Wrangler config directory (the Vite root) and not next to the entry. - Log a warning when
maindoes not resolve to a module that the plugin transforms, so the failure is not silent. - Add a test fixture where
mainis a package specifier.
- Ngôn ngữ chính
- TypeScript
- Star
- 8.7k
- Fork
- 1.9k
- Merge trung bình
- 1 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 562
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của getsentry/sentry-javascript
-
Browser Waiting for: Product Owner
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
getsentry/sentry-javascript#24577 · 1 bình luận ·
-
Task
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
getsentry/sentry-javascript#24558 · 1 bình luận ·
-
Task
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
getsentry/sentry-javascript#24557 · 1 bình luận ·
-
Task
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
getsentry/sentry-javascript#24556 · 1 bình luận ·
-
Task
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 90/100
getsentry/sentry-javascript#24555 · 1 bình luận ·
Tất cả issue của getsentry/sentry-javascript
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
modelcontextprotocol/inspector#2458 · 1 bình luận ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
railmapgen/rmp-gallery#4068 ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
carbon-design-system/ibm-products#9907 ·