getsentry / getsentry/sentry-javascript

Auto instrumentation in Cloudflare with Vite plugin

Đang mở
#22,066 1 bình luận 0 reaction 1 người được giao Được @JPeer264 nhận Xem trên GitHub
Cloudflare Workers Feature
Ngôn ngữ chính
TypeScript
Star
8.7k
Fork
1.8k
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
515

Mô tả

### Problem Statement

As of now people need to manually wrap their worker with `withSentry` or `instrumentDurableObjectWithSentry` in their source code, which needs intervention. Also the config needs to be adapted in multiple places, and users already have helper functions that reuses their config.

### Solution Brainstorm

Vite could auto wrap all functions, as during build time we have access to `wrangler.jsonc` and could therefore read out which classes are meant to be wrapped with which function of ours. That would mean that users only have to add our Cloudflare Vite plugin, add a `instrument.server.ts` or similar, which could include the following code:

```js
import { defineCloudflareOptions } from '@sentry/cloudflare';

export default defineCloudflareOptions((env) => ({
dsn: env.SENTRY_DSN,
tracesSampleRate: 1,
}));
```

Since the config is a callback, which makes it possible to use the environment variables `defineCloudflareOptions` could be the solution to use these variables. On top if users wish to have different configs per worker, they could use it differently

```js
import { defineCloudflareOptions } from '@sentry/cloudflare';

// default worker
export default defineCloudflareOptions((env) => ({
dsn: env.SENTRY_DSN,
tracesSampleRate: 1,
}));

// matched name as the binding from the default worker entrypoint, will warn if it doesn't exist
export const MY_WORKER = defineCloudflareOptions((env) => ({
dsn: env.SENTRY_DSN,
tracesSampleRate: 1,
}));
```

### Additional Context

_No response_

### Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.