Skip to content

Commit 86644ca

Browse files
SG60Lms24
authored andcommitted
chore(sveltekit): refactor the rest of the common server-side code
1 parent 79662d9 commit 86644ca

File tree

11 files changed

+32
-287
lines changed

11 files changed

+32
-287
lines changed

packages/sveltekit/src/server/handleError.ts renamed to packages/sveltekit/src/server-common/handleError.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { consoleSandbox } from '@sentry/core';
2-
import { captureException } from '@sentry/node';
1+
import { captureException, consoleSandbox } from '@sentry/core';
32
import type { HandleServerError } from '@sveltejs/kit';
43

54
import { flushIfServerless } from '../server-common/utils';

packages/sveltekit/src/server/load.ts renamed to packages/sveltekit/src/server-common/load.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { addNonEnumerableProperty } from '@sentry/core';
2-
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, startSpan } from '@sentry/node';
1+
import {
2+
addNonEnumerableProperty,
3+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
4+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
5+
startSpan,
6+
} from '@sentry/core';
37
import type { LoadEvent, ServerLoadEvent } from '@sveltejs/kit';
48

59
import type { SentryWrappedFlag } from '../common/utils';
6-
import { flushIfServerless, sendErrorToSentry } from '../server-common/utils';
10+
import { flushIfServerless, sendErrorToSentry } from './utils';
711

812
type PatchedLoadEvent = LoadEvent & SentryWrappedFlag;
913
type PatchedServerLoadEvent = ServerLoadEvent & SentryWrappedFlag;

packages/sveltekit/src/server/rewriteFramesIntegration.ts renamed to packages/sveltekit/src/server-common/rewriteFramesIntegration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export function rewriteFramesIteratee(frame: StackFrame): StackFrame {
5353
if (isWindowsFrame || startsWithSlash) {
5454
const filename = isWindowsFrame
5555
? frame.filename
56-
.replace(/^[a-zA-Z]:/, '') // remove Windows-style prefix
57-
.replace(/\\/g, '/') // replace all `\\` instances with `/`
56+
.replace(/^[a-zA-Z]:/, '') // remove Windows-style prefix
57+
.replace(/\\/g, '/') // replace all `\\` instances with `/`
5858
: frame.filename;
5959

6060
let strippedFilename;

packages/sveltekit/src/server/serverRoute.ts renamed to packages/sveltekit/src/server-common/serverRoute.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { addNonEnumerableProperty } from '@sentry/core';
2-
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, startSpan } from '@sentry/node';
1+
import {
2+
addNonEnumerableProperty,
3+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
4+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
5+
startSpan,
6+
} from '@sentry/core';
37
import type { RequestEvent } from '@sveltejs/kit';
4-
import { flushIfServerless, sendErrorToSentry } from '../server-common/utils';
8+
import { flushIfServerless, sendErrorToSentry } from './utils';
59

610
type PatchedServerRouteEvent = RequestEvent & { __sentry_wrapped__?: boolean };
711

packages/sveltekit/src/server/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ export * from '@sentry/node';
123123
// -------------------------
124124
// SvelteKit SDK exports:
125125
export { init } from './sdk';
126-
export { handleErrorWithSentry } from './handleError';
127-
export { wrapLoadWithSentry, wrapServerLoadWithSentry } from './load';
126+
export { handleErrorWithSentry } from '../server-common/handleError';
127+
export { wrapLoadWithSentry, wrapServerLoadWithSentry } from '../server-common/load';
128128
export { sentryHandle } from './handle';
129-
export { wrapServerRouteWithSentry } from './serverRoute';
129+
export { wrapServerRouteWithSentry } from '../server-common/serverRoute';
130130

131131
/**
132132
* Tracks the Svelte component's initialization and mounting operation as well as

packages/sveltekit/src/server/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { NodeClient, NodeOptions } from '@sentry/node';
33
import { getDefaultIntegrations as getDefaultNodeIntegrations } from '@sentry/node';
44
import { init as initNodeSdk } from '@sentry/node';
55

6-
import { rewriteFramesIntegration } from './rewriteFramesIntegration';
6+
import { rewriteFramesIntegration } from '../server-common/rewriteFramesIntegration';
77

88
/**
99
*

packages/sveltekit/src/worker/handle.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { CloudflareOptions, continueTrace, wrapRequestHandler } from '@sentry/cloudflare';
2+
import { getDefaultIntegrations as getDefaultCloudflareIntegrations } from '@sentry/cloudflare';
23
import type { Handle } from '@sveltejs/kit';
34

45
import { sentryHandleGeneric, SentryHandleOptions } from '../server-common/handle';
6+
import { rewriteFramesIntegration } from '../server-common/rewriteFramesIntegration';
57

68
/**
79
* A SvelteKit handle function that wraps the request for Sentry error and
@@ -29,15 +31,18 @@ export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle {
2931
/** Initializes Sentry SvelteKit Cloudflare SDK
3032
* This should be before the sentryHandle() call.
3133
* */
32-
export function initCloudflareSentryHandle(handlerOptions: CloudflareOptions): Handle {
33-
const options = { ...handlerOptions };
34+
export function initCloudflareSentryHandle(options: CloudflareOptions): Handle {
35+
const opts: CloudflareOptions = {
36+
defaultIntegrations: [...getDefaultCloudflareIntegrations(options), rewriteFramesIntegration()],
37+
...options,
38+
};
3439

3540
const handleInitSentry: Handle = ({ event, resolve }) => {
3641
// if event.platform exists (should be there in a cloudflare worker), then do the cloudflare sentry init
3742
return event.platform
3843
? wrapRequestHandler(
3944
{
40-
options,
45+
options: opts,
4146
request: event.request,
4247
// @ts-expect-error This will exist in Cloudflare
4348
context: event.platform.context,

packages/sveltekit/src/worker/handleError.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

packages/sveltekit/src/worker/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
//
99
// -------------------------
1010
// SvelteKit SDK exports:
11-
export { handleErrorWithSentry } from './handleError';
12-
export { wrapLoadWithSentry, wrapServerLoadWithSentry } from './load';
11+
export { handleErrorWithSentry } from '../server-common/handleError';
12+
export { wrapLoadWithSentry, wrapServerLoadWithSentry } from '../server-common/load';
1313
export { sentryHandle, initCloudflareSentryHandle } from './handle';
14-
export { wrapServerRouteWithSentry } from './serverRoute';
14+
export { wrapServerRouteWithSentry } from '../server-common/serverRoute';
1515

1616
// Re-export some functions from Cloudflare SDK
1717
export {

packages/sveltekit/src/worker/load.ts

Lines changed: 0 additions & 120 deletions
This file was deleted.

packages/sveltekit/src/worker/serverRoute.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)