Skip to content

Commit 7ef333d

Browse files
committed
add renamed file
1 parent 99b0d15 commit 7ef333d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Diff for: packages/sveltekit/src/worker/cloudflare.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { type CloudflareOptions, wrapRequestHandler } from '@sentry/cloudflare';
2+
import { getDefaultIntegrations as getDefaultCloudflareIntegrations } from '@sentry/cloudflare';
3+
import type { Handle } from '@sveltejs/kit';
4+
5+
import { addNonEnumerableProperty } from '@sentry/core';
6+
import { rewriteFramesIntegration } from '../server-common/rewriteFramesIntegration';
7+
8+
/**
9+
* Initializes Sentry SvelteKit Cloudflare SDK
10+
* This should be before the sentryHandle() call.
11+
*
12+
* In the Node export, this is a stub that does nothing.
13+
*/
14+
export function initCloudflareSentryHandle(options: CloudflareOptions): Handle {
15+
const opts: CloudflareOptions = {
16+
defaultIntegrations: [...getDefaultCloudflareIntegrations(options), rewriteFramesIntegration()],
17+
...options,
18+
};
19+
20+
const handleInitSentry: Handle = ({ event, resolve }) => {
21+
// if event.platform exists (should be there in a cloudflare worker), then do the cloudflare sentry init
22+
if (event.platform) {
23+
// This is an optional local that the `sentryHandle` handler checks for to avoid double isolation
24+
// In Cloudflare the `wrapRequestHandler` function already takes care of
25+
// - request isolation
26+
// - trace continuation
27+
// -setting the request onto the scope
28+
addNonEnumerableProperty(event.locals, '_sentrySkipRequestIsolation', true);
29+
return wrapRequestHandler(
30+
{
31+
options: opts,
32+
request: event.request,
33+
// @ts-expect-error This will exist in Cloudflare
34+
context: event.platform.context,
35+
},
36+
() => resolve(event),
37+
);
38+
}
39+
return resolve(event);
40+
};
41+
42+
return handleInitSentry;
43+
}

0 commit comments

Comments
 (0)