Skip to content

Commit ef78c1b

Browse files
committed
fix(sveltekit): use the new unified continueTrace function
1 parent df8f314 commit ef78c1b

File tree

5 files changed

+27
-67
lines changed

5 files changed

+27
-67
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,
@@ -137,13 +138,18 @@ export async function instrumentHandle(
137138
* A SvelteKit handle function that wraps the request for Sentry error and
138139
* performance monitoring.
139140
*
140-
* Some environments require a different continueTrace function. E.g. Node can use
141-
* the Opentelemetry SDK, whereas Cloudflare cannot.
141+
* Usage:
142+
* ```
143+
* // src/hooks.server.ts
144+
* import { sentryHandle } from '@sentry/sveltekit';
145+
*
146+
* export const handle = sentryHandle();
147+
*
148+
* // Optionally use the `sequence` function to add additional handlers.
149+
* // export const handle = sequence(sentryHandle(), yourCustomHandler);
150+
* ```
142151
*/
143-
export function sentryHandleGeneric(
144-
continueTraceFunction: typeof continueTrace,
145-
handlerOptions?: SentryHandleOptions,
146-
): Handle {
152+
export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle {
147153
const options = {
148154
handleUnknownRoutes: false,
149155
injectFetchProxyScript: true,
@@ -173,7 +179,7 @@ export function sentryHandleGeneric(
173179
isolationScope.setSDKProcessingMetadata({
174180
normalizedRequest: winterCGRequestToRequestData(input.event.request.clone()),
175181
});
176-
return continueTraceFunction(getTracePropagationData(input.event), () => instrumentHandle(input, options));
182+
return continueTrace(getTracePropagationData(input.event), () => instrumentHandle(input, options));
177183
});
178184
};
179185

packages/sveltekit/src/server/handle.ts

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

4-
import { sentryHandleGeneric, SentryHandleOptions } from '../server-common/handle';
5-
6-
/**
7-
* A SvelteKit handle function that wraps the request for Sentry error and
8-
* performance monitoring.
9-
*
10-
* Usage:
11-
* ```
12-
* // src/hooks.server.ts
13-
* import { sentryHandle } from '@sentry/sveltekit';
14-
*
15-
* export const handle = sentryHandle();
16-
*
17-
* // Optionally use the `sequence` function to add additional handlers.
18-
* // export const handle = sequence(sentryHandle(), yourCustomHandler);
19-
* ```
20-
*/
21-
export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle {
22-
const sentryRequestHandler = sentryHandleGeneric(continueTrace, handlerOptions);
23-
24-
return sentryRequestHandler;
25-
}
26-
273
/** Documented in `worker/handle.ts` */
284
export function initCloudflareSentryHandle(_options: any): Handle {
295
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
@@ -132,7 +132,8 @@ export * from '@sentry/node';
132132
export { init } from './sdk';
133133
export { handleErrorWithSentry } from '../server-common/handleError';
134134
export { wrapLoadWithSentry, wrapServerLoadWithSentry } from '../server-common/load';
135-
export { sentryHandle, initCloudflareSentryHandle } from './handle';
135+
export { sentryHandle } from '../server-common/handle';
136+
export { initCloudflareSentryHandle } from './handle';
136137
export { wrapServerRouteWithSentry } from '../server-common/serverRoute';
137138

138139
/**

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)