From 69e5a3b2c72d910914a319ba3ec10066c63159b3 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 14 Jan 2025 18:16:31 +0100 Subject: [PATCH 1/3] feat(sveltekit)!: Remove fetch proxy script injection and options --- packages/sveltekit/src/server/handle.ts | 41 +++---------------- packages/sveltekit/test/server/handle.test.ts | 33 ++------------- 2 files changed, 10 insertions(+), 64 deletions(-) diff --git a/packages/sveltekit/src/server/handle.ts b/packages/sveltekit/src/server/handle.ts index 8d5fe21de1c1..5120e2c10244 100644 --- a/packages/sveltekit/src/server/handle.ts +++ b/packages/sveltekit/src/server/handle.ts @@ -35,23 +35,6 @@ export type SentryHandleOptions = { * @default false */ handleUnknownRoutes?: boolean; - - /** - * Controls if `sentryHandle` should inject a script tag into the page that enables instrumentation - * of `fetch` calls in `load` functions. - * - * @default true - */ - injectFetchProxyScript?: boolean; - - /** - * If this option is set, the `sentryHandle` handler will add a nonce attribute to the script - * tag it injects into the page. This script is used to enable instrumentation of `fetch` calls - * in `load` functions. - * - * Use this if your CSP policy blocks the fetch proxy script injected by `sentryHandle`. - */ - fetchProxyScriptNonce?: string; }; /** @@ -72,23 +55,11 @@ export const FETCH_PROXY_SCRIPT = ` * * Exported only for testing */ -export function addSentryCodeToPage(options: SentryHandleOptions): NonNullable { - const { fetchProxyScriptNonce, injectFetchProxyScript } = options; - // if injectFetchProxyScript is not set, we default to true - const shouldInjectScript = injectFetchProxyScript !== false; - const nonce = fetchProxyScriptNonce ? `nonce="${fetchProxyScriptNonce}"` : ''; - - return ({ html }) => { - const metaTags = getTraceMetaTags(); - const headWithMetaTags = metaTags ? `\n${metaTags}` : ''; - - const headWithFetchScript = shouldInjectScript ? `\n` : ''; - - const modifiedHead = `${headWithMetaTags}${headWithFetchScript}`; - - return html.replace('', modifiedHead); - }; -} +export const addSentryCodeToPage = (({ html }) => { + const metaTags = getTraceMetaTags(); + const headWithMetaTags = metaTags ? `\n${metaTags}` : ''; + return html.replace('', headWithMetaTags); +}) satisfies NonNullable; /** * A SvelteKit handle function that wraps the request for Sentry error and @@ -174,7 +145,7 @@ async function instrumentHandle( normalizedRequest: winterCGRequestToRequestData(event.request.clone()), }); const res = await resolve(event, { - transformPageChunk: addSentryCodeToPage(options), + transformPageChunk: addSentryCodeToPage, }); if (span) { setHttpStatus(span, res.status); diff --git a/packages/sveltekit/test/server/handle.test.ts b/packages/sveltekit/test/server/handle.test.ts index c5225124ace3..805c9f656a30 100644 --- a/packages/sveltekit/test/server/handle.test.ts +++ b/packages/sveltekit/test/server/handle.test.ts @@ -429,46 +429,21 @@ describe('addSentryCodeToPage', () => { `; - it("Adds add meta tags and fetch proxy script if there's no active transaction", () => { - const transformPageChunk = addSentryCodeToPage({}); - const transformed = transformPageChunk({ html, done: true }); + it("Adds add meta tags if there's no active transaction", () => { + const transformed = addSentryCodeToPage({ html, done: true }); expect(transformed).toContain(' { - const transformPageChunk = addSentryCodeToPage({}); + it('adds meta tags if there is an active transaction', () => { SentryNode.startSpan({ name: 'test' }, () => { - const transformed = transformPageChunk({ html, done: true }) as string; + const transformed = addSentryCodeToPage({ html, done: true }); expect(transformed).toContain('${FETCH_PROXY_SCRIPT}`); }); }); - - it('adds a nonce attribute to the script if the `fetchProxyScriptNonce` option is specified', () => { - const transformPageChunk = addSentryCodeToPage({ fetchProxyScriptNonce: '123abc' }); - SentryNode.startSpan({ name: 'test' }, () => { - const transformed = transformPageChunk({ html, done: true }) as string; - - expect(transformed).toContain('${FETCH_PROXY_SCRIPT}`); - }); - }); - - it('does not add the fetch proxy script if the `injectFetchProxyScript` option is false', () => { - const transformPageChunk = addSentryCodeToPage({ injectFetchProxyScript: false }); - const transformed = transformPageChunk({ html, done: true }) as string; - - expect(transformed).toContain('${FETCH_PROXY_SCRIPT}`); - }); }); From 682a818ae9c74d77fdeba672e583e1dd04ecaaa3 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 14 Jan 2025 18:24:32 +0100 Subject: [PATCH 2/3] add migration note --- docs/migration/v8-to-v9.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/migration/v8-to-v9.md b/docs/migration/v8-to-v9.md index ba1208a4b6a4..e1a3d83615c1 100644 --- a/docs/migration/v8-to-v9.md +++ b/docs/migration/v8-to-v9.md @@ -116,6 +116,11 @@ Older Typescript versions _may_ still work, but we will not test them anymore an - By default, source maps will now be automatically deleted after being uploaded to Sentry for client-side builds. You can opt out of this behavior by explicitly setting `sourcemaps.deleteSourcemapsAfterUpload` to `false` in your Sentry config. +### `@sentry/sveltekit` + +- SvelteKit 1 is no longer supported, due to some features missing in the first version of the framework. This allows the SDK to remove some brittle workarounds that were necessary for proper 1.x support. +- In v8, the Sentry SvelteKit SDK would inject a small `