Skip to content

Commit dce23f3

Browse files
SG60Lms24
authored andcommitted
fix(sveltekit): use the new unified continueTrace function
1 parent 77381e5 commit dce23f3

File tree

5 files changed

+27
-68
lines changed

5 files changed

+27
-68
lines changed

packages/sveltekit/src/server-common/handle.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { continueTrace, Span } from '@sentry/core';
1+
import type { Span } from '@sentry/core';
22
import {
33
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
44
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
5+
continueTrace,
56
getActiveSpan,
67
getCurrentScope,
78
getDefaultIsolationScope,
@@ -153,13 +154,18 @@ export function isFetchProxyRequired(version: string): boolean {
153154
* A SvelteKit handle function that wraps the request for Sentry error and
154155
* performance monitoring.
155156
*
156-
* Some environments require a different continueTrace function. E.g. Node can use
157-
* the Opentelemetry SDK, whereas Cloudflare cannot.
157+
* Usage:
158+
* ```
159+
* // src/hooks.server.ts
160+
* import { sentryHandle } from '@sentry/sveltekit';
161+
*
162+
* export const handle = sentryHandle();
163+
*
164+
* // Optionally use the `sequence` function to add additional handlers.
165+
* // export const handle = sequence(sentryHandle(), yourCustomHandler);
166+
* ```
158167
*/
159-
export function sentryHandleGeneric(
160-
continueTraceFunction: typeof continueTrace,
161-
handlerOptions?: SentryHandleOptions,
162-
): Handle {
168+
export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle {
163169
const options = {
164170
handleUnknownRoutes: false,
165171
injectFetchProxyScript: true,
@@ -189,7 +195,7 @@ export function sentryHandleGeneric(
189195
isolationScope.setSDKProcessingMetadata({
190196
normalizedRequest: winterCGRequestToRequestData(input.event.request.clone()),
191197
});
192-
return continueTraceFunction(getTracePropagationData(input.event), () => instrumentHandle(input, options));
198+
return continueTrace(getTracePropagationData(input.event), () => instrumentHandle(input, options));
193199
});
194200
};
195201

packages/sveltekit/src/server/handle.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
1-
import { continueTrace } from '@sentry/node';
21
import type { Handle } from '@sveltejs/kit';
32

4-
import type { SentryHandleOptions } from '../server-common/handle';
5-
import { sentryHandleGeneric } from '../server-common/handle';
6-
7-
/**
8-
* A SvelteKit handle function that wraps the request for Sentry error and
9-
* performance monitoring.
10-
*
11-
* Usage:
12-
* ```
13-
* // src/hooks.server.ts
14-
* import { sentryHandle } from '@sentry/sveltekit';
15-
*
16-
* export const handle = sentryHandle();
17-
*
18-
* // Optionally use the `sequence` function to add additional handlers.
19-
* // export const handle = sequence(sentryHandle(), yourCustomHandler);
20-
* ```
21-
*/
22-
export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle {
23-
const sentryRequestHandler = sentryHandleGeneric(continueTrace, handlerOptions);
24-
25-
return sentryRequestHandler;
26-
}
27-
283
/** Documented in `worker/handle.ts` */
294
export function initCloudflareSentryHandle(_options: any): Handle {
305
return ({ event, resolve }) => resolve(event);

packages/sveltekit/src/server/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ export * from '@sentry/node';
125125
export { init } from './sdk';
126126
export { handleErrorWithSentry } from '../server-common/handleError';
127127
export { wrapLoadWithSentry, wrapServerLoadWithSentry } from '../server-common/load';
128-
export { sentryHandle, initCloudflareSentryHandle } from './handle';
128+
export { sentryHandle } from '../server-common/handle';
129+
export { initCloudflareSentryHandle } from './handle';
129130
export { wrapServerRouteWithSentry } from '../server-common/serverRoute';
130131

131132
/**

packages/sveltekit/src/worker/handle.ts

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
1-
import { CloudflareOptions, continueTrace, wrapRequestHandler } from '@sentry/cloudflare';
1+
import { CloudflareOptions, wrapRequestHandler } from '@sentry/cloudflare';
22
import { getDefaultIntegrations as getDefaultCloudflareIntegrations } from '@sentry/cloudflare';
33
import type { Handle } from '@sveltejs/kit';
44

5-
import { sentryHandleGeneric, SentryHandleOptions } from '../server-common/handle';
65
import { rewriteFramesIntegration } from '../server-common/rewriteFramesIntegration';
76

8-
/**
9-
* A SvelteKit handle function that wraps the request for Sentry error and
10-
* performance monitoring.
11-
*
12-
* This doesn't currently use OTEL, as it isn't available outside of Node
13-
*
14-
* Usage:
15-
* ```
16-
* // src/hooks.server.ts
17-
* import { sentryHandle } from '@sentry/sveltekit';
18-
*
19-
* export const handle = sentryHandle();
20-
*
21-
* // Optionally use the `sequence` function to add additional handlers.
22-
* // export const handle = sequence(sentryHandle(), yourCustomHandler);
23-
* ```
24-
*/
25-
export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle {
26-
const sentryRequestHandler = sentryHandleGeneric(continueTrace, handlerOptions);
27-
28-
return sentryRequestHandler;
29-
}
30-
317
/** Initializes Sentry SvelteKit Cloudflare SDK
328
* This should be before the sentryHandle() call.
339
*
@@ -43,14 +19,14 @@ export function initCloudflareSentryHandle(options: CloudflareOptions): Handle {
4319
// if event.platform exists (should be there in a cloudflare worker), then do the cloudflare sentry init
4420
return event.platform
4521
? wrapRequestHandler(
46-
{
47-
options: opts,
48-
request: event.request,
49-
// @ts-expect-error This will exist in Cloudflare
50-
context: event.platform.context,
51-
},
52-
() => resolve(event),
53-
)
22+
{
23+
options: opts,
24+
request: event.request,
25+
// @ts-expect-error This will exist in Cloudflare
26+
context: event.platform.context,
27+
},
28+
() => resolve(event),
29+
)
5430
: resolve(event);
5531
};
5632

packages/sveltekit/src/worker/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
// SvelteKit SDK exports:
1111
export { handleErrorWithSentry } from '../server-common/handleError';
1212
export { wrapLoadWithSentry, wrapServerLoadWithSentry } from '../server-common/load';
13-
export { sentryHandle, initCloudflareSentryHandle } from './handle';
13+
export { sentryHandle } from '../server-common/handle';
14+
export { initCloudflareSentryHandle } from './handle';
1415
export { wrapServerRouteWithSentry } from '../server-common/serverRoute';
1516

1617
// Re-export some functions from Cloudflare SDK

0 commit comments

Comments
 (0)