-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathworker-entrypoint.ts
More file actions
53 lines (46 loc) · 1.62 KB
/
worker-entrypoint.ts
File metadata and controls
53 lines (46 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Note: this custom worker-entrypoint is used so that the worker can include sentry support
// and it has been written by following:
// - the official open-next docs: https://opennext.js.org/cloudflare/howtos/custom-worker
// - the official sentry docs: https://docs.sentry.io/platforms/javascript/guides/cloudflare
import { setTags, withSentry } from '@sentry/cloudflare';
import type {
ExecutionContext,
Iso3166Alpha2Code,
Request,
} from '@cloudflare/workers-types';
import { default as handler } from '../../site/.open-next/worker.js';
export default withSentry(
(env: {
/**
* Sentry DSN, used for error monitoring
* If missing, Sentry isn't used
*/
SENTRY_DSN?: string;
}) => ({
dsn: env.SENTRY_DSN,
// Enable logs to be sent to Sentry
enableLogs: true,
// Set tracesSampleRate to 0.05 to capture 5% of spans for tracing.
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#tracesSampleRate
tracesSampleRate: 0.05,
}),
{
async fetch(
request: Request,
env: Record<string, unknown>,
ctx: ExecutionContext
) {
setTags({
request_id: crypto.randomUUID(),
user_agent: request.headers.get('user-agent'),
ray_id: request.headers.get('cf-ray'),
// Type casts needed to keep lsp happy
ip_country: request.cf?.country as Iso3166Alpha2Code | undefined,
colo: request.cf?.colo as string | undefined,
});
return handler.fetch(request, env, ctx);
},
}
);
export { DOQueueHandler } from '../../site/.open-next/worker.js';