From 4983467a082ea09da9597d1b86675b06d4dd4d67 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Wed, 28 Feb 2024 18:37:25 +0100 Subject: [PATCH 1/6] migration guide --- MIGRATION.md | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/MIGRATION.md b/MIGRATION.md index 8b5d1bdf0c0e..b97eb5787d4f 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -12,6 +12,8 @@ The main goal of version 8 is to improve our performance monitoring APIs, integr version is breaking because we removed deprecated APIs, restructured npm package contents, and introduced new dependencies on OpenTelemetry. Below we will outline the steps you need to take to tackle to deprecated methods. +## Removal of Client-Side health check transaction filters + Before updating to `8.x` of the SDK, we recommend upgrading to the latest version of `7.x`. You can then follow [these steps](./MIGRATION.md#deprecations-in-7x) remove deprecated methods in `7.x` before upgrading to `8.x`. @@ -537,6 +539,78 @@ Sentry.init({ }); ``` +### SvelteKit SDK + +#### Breaking `sentrySvelteKit()` changes + +We upgraded the `@sentry/vite-plugin` which is a dependency of the SvelteKit SDK from version 0.x to 2.x. With this +change, resolving uploaded source maps should work out of the box much more often than before (read more about this +[here](https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js/artifact-bundles/)). + +To allow future upgrades of the Vite plugin without breaking stable and public APIs in `sentrySvelteKit`, we modified +the `sourceMapsUploadOptions` to remove the hard dependency on the API of the plugin. While you previously could specify +all [version 0.x Vite plugin options](https://www.npmjs.com/package/@sentry/vite-plugin/v/0.6.1), we now reduced them to +a subset of [2.x options](https://www.npmjs.com/package/@sentry/vite-plugin/v/2.14.2#options). All of these options are +optional just like before but here's an example of using the new options. + +```js +// Before (v7): +sentrySvelteKit({ + sourceMapsUploadOptions: { + org: process.env.SENTRY_ORG, + project: process.env.SENTRY_PROJECT, + authToken: process.env.SENTRY_AUTH_TOKEN, + release: '1.0.1', + injectRelease: true, + include: ['./build/*/**/*'], + ignore: ['**/build/client/**/*'] + }, +}), + +// After (v8): +sentrySvelteKit({ + sourceMapsUploadOptions: { + org: process.env.SENTRY_ORG, + project: process.env.SENTRY_PROJECT, + authToken: process.env.SENTRY_AUTH_TOKEN, + release: { + name: '1.0.1', + inject: true + }, + sourcemaps: { + assets: ['./build/*/**/*'], + ignore: ['**/build/client/**/*'], + filesToDeleteAfterUpload: ['./build/**/*.map'] + }, + }, +}), +``` + +In the future, we might add additional [options](https://www.npmjs.com/package/@sentry/vite-plugin/v/2.14.2#options) +from the Vite plugin but if you would like to specify some of them directly, you can do this by passing in an +`unstable_vitePluginOptions` object: + +```js +sentrySvelteKit({ + sourceMapsUploadOptions: { + // ... + release: { + name: '1.0.1', + }, + unstable_vitePluginOptions: { + release: { + setCommits: { + auto: true + } + } + } + }, +}), +``` + +Please note, that we DO NOT guarantee stability of `unstable_vitePluginOptions`. They can be removed or updated at any +time, including breaking changes within the same major version of the SDK. + ## 5. Behaviour Changes - [Updated behaviour of `tracePropagationTargets` in the browser](./MIGRATION.md#updated-behaviour-of-tracepropagationtargets-in-the-browser-http-tracing-headers--cors) From c74a9cde24786e209c4384a2014bfa4ec7fe88ff Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 5 Mar 2024 14:49:47 +0100 Subject: [PATCH 2/6] wip --- .../sveltekit/src/vite/sentryVitePlugins.ts | 30 ++++++++++++++++++- .../test/vite/sentrySvelteKitPlugins.test.ts | 26 ++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/packages/sveltekit/src/vite/sentryVitePlugins.ts b/packages/sveltekit/src/vite/sentryVitePlugins.ts index 07111432e942..06f65a5d0157 100644 --- a/packages/sveltekit/src/vite/sentryVitePlugins.ts +++ b/packages/sveltekit/src/vite/sentryVitePlugins.ts @@ -1,5 +1,6 @@ import type { Plugin } from 'vite'; +import { SentryVitePluginOptions } from '@sentry/vite-plugin'; import type { AutoInstrumentSelection } from './autoInstrument'; import { makeAutoInstrumentationPlugin } from './autoInstrument'; import type { SupportedSvelteKitAdapters } from './detectAdapter'; @@ -114,6 +115,21 @@ type SourceMapsUploadOptions = { */ inject?: boolean; }; + + /** + * Options to further customize the Sentry Vite Plugin (@sentry/vite-plugin) behavior directly. + * Options specified in this object take precedence over the options specified in + * the `sourcemaps` and `release` objects. + * + * @see https://www.npmjs.com/package/@sentry/vite-plugin/v/2.14.2#options which lists all available options. + * + * Warning: Options within this object are subject to change at any time. + * We DO NOT guarantee semantic versioning for these options, meaning breaking + * changes can occur at any time within a major SDK version. + * + * Furthermore, some options are untested with SvelteKit specifically. Use with caution. + */ + unstable_vitePluginOptions?: Partial; }; }; @@ -196,11 +212,23 @@ export async function sentrySvelteKit(options: SentrySvelteKitPluginOptions = {} } if (mergedOptions.autoUploadSourceMaps && process.env.NODE_ENV !== 'development') { - const sourceMapsUploadOptions = mergedOptions.sourceMapsUploadOptions; + const { unstable_vitePluginOptions, ...sourceMapsUploadOptions } = mergedOptions.sourceMapsUploadOptions || {}; const sentryVitePlugins = await makeCustomSentryVitePlugins({ ...sourceMapsUploadOptions, + ...unstable_vitePluginOptions, + + sourcemaps: { + ...sourceMapsUploadOptions?.sourcemaps, + ...unstable_vitePluginOptions?.sourcemaps, + }, + + release: { + ...sourceMapsUploadOptions?.release, + ...unstable_vitePluginOptions?.release, + }, + adapter: mergedOptions.adapter, // override the plugin's debug flag with the one from the top-level options debug: mergedOptions.debug, diff --git a/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts b/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts index 5519a4e33953..615371a7f8ac 100644 --- a/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts +++ b/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts @@ -113,6 +113,32 @@ describe('sentrySvelteKit()', () => { }); }); + it('passes user-specified vite plugin options to the custom sentry source maps plugin', async () => { + const makePluginSpy = vi.spyOn(sourceMaps, 'makeCustomSentryVitePlugins'); + await getSentrySvelteKitPlugins({ + debug: true, + sourceMapsUploadOptions: { + sourcemaps: { + assets: ['foo/*.js'], + ignore: ['bar/*.js'], + filesToDeleteAfterUpload: ['baz/*.js'], + }, + }, + autoInstrument: false, + adapter: 'vercel', + }); + + expect(makePluginSpy).toHaveBeenCalledWith({ + debug: true, + sourcemaps: { + assets: ['foo/*.js'], + ignore: ['bar/*.js'], + filesToDeleteAfterUpload: ['baz/*.js'], + }, + adapter: 'vercel', + }); + }); + it('passes user-specified options to the auto instrument plugin', async () => { const makePluginSpy = vi.spyOn(autoInstrument, 'makeAutoInstrumentationPlugin'); const plugins = await getSentrySvelteKitPlugins({ From 2f68188f2ca0fae7e14881022209561a5687d3f5 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 5 Mar 2024 16:01:52 +0100 Subject: [PATCH 3/6] feat(sveltekit): Export `unstable_vitePluginOptions` for full Vite plugin customization --- .../sveltekit/src/vite/sentryVitePlugins.ts | 27 ++++++++------ .../test/vite/sentrySvelteKitPlugins.test.ts | 35 +++++++++++++++++-- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/packages/sveltekit/src/vite/sentryVitePlugins.ts b/packages/sveltekit/src/vite/sentryVitePlugins.ts index 06f65a5d0157..c1d359a6e1c5 100644 --- a/packages/sveltekit/src/vite/sentryVitePlugins.ts +++ b/packages/sveltekit/src/vite/sentryVitePlugins.ts @@ -1,6 +1,6 @@ import type { Plugin } from 'vite'; -import { SentryVitePluginOptions } from '@sentry/vite-plugin'; +import type { SentryVitePluginOptions } from '@sentry/vite-plugin'; import type { AutoInstrumentSelection } from './autoInstrument'; import { makeAutoInstrumentationPlugin } from './autoInstrument'; import type { SupportedSvelteKitAdapters } from './detectAdapter'; @@ -214,25 +214,32 @@ export async function sentrySvelteKit(options: SentrySvelteKitPluginOptions = {} if (mergedOptions.autoUploadSourceMaps && process.env.NODE_ENV !== 'development') { const { unstable_vitePluginOptions, ...sourceMapsUploadOptions } = mergedOptions.sourceMapsUploadOptions || {}; - const sentryVitePlugins = await makeCustomSentryVitePlugins({ + const sentryVitePluginsOptions = { ...sourceMapsUploadOptions, ...unstable_vitePluginOptions, - sourcemaps: { + adapter: mergedOptions.adapter, + // override the plugin's debug flag with the one from the top-level options + debug: mergedOptions.debug, + }; + + if (sentryVitePluginsOptions.sourcemaps) { + sentryVitePluginsOptions.sourcemaps = { ...sourceMapsUploadOptions?.sourcemaps, ...unstable_vitePluginOptions?.sourcemaps, - }, + }; + } - release: { + if (sentryVitePluginsOptions.release) { + sentryVitePluginsOptions.release = { ...sourceMapsUploadOptions?.release, ...unstable_vitePluginOptions?.release, - }, + }; + } + + const sentryVitePlugins = await makeCustomSentryVitePlugins(sentryVitePluginsOptions); - adapter: mergedOptions.adapter, - // override the plugin's debug flag with the one from the top-level options - debug: mergedOptions.debug, - }); sentryPlugins.push(...sentryVitePlugins); } diff --git a/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts b/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts index 615371a7f8ac..5988f10349e7 100644 --- a/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts +++ b/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts @@ -118,11 +118,31 @@ describe('sentrySvelteKit()', () => { await getSentrySvelteKitPlugins({ debug: true, sourceMapsUploadOptions: { + org: 'my-org', sourcemaps: { - assets: ['foo/*.js'], - ignore: ['bar/*.js'], + assets: ['nope/*.js'], filesToDeleteAfterUpload: ['baz/*.js'], }, + release: { + inject: false, + name: '2.0.0', + }, + unstable_vitePluginOptions: { + org: 'other-org', + sourcemaps: { + assets: ['foo/*.js'], + ignore: ['bar/*.js'], + }, + release: { + name: '3.0.0', + setCommits: { + auto: true, + }, + }, + headers: { + 'X-My-Header': 'foo', + }, + }, }, autoInstrument: false, adapter: 'vercel', @@ -130,11 +150,22 @@ describe('sentrySvelteKit()', () => { expect(makePluginSpy).toHaveBeenCalledWith({ debug: true, + org: 'other-org', sourcemaps: { assets: ['foo/*.js'], ignore: ['bar/*.js'], filesToDeleteAfterUpload: ['baz/*.js'], }, + release: { + inject: false, + name: '3.0.0', + setCommits: { + auto: true, + }, + }, + headers: { + 'X-My-Header': 'foo', + }, adapter: 'vercel', }); }); From 2ef56caba4efacaf5d380b171392fd6819f56739 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 5 Mar 2024 16:03:47 +0100 Subject: [PATCH 4/6] cleanup migration --- MIGRATION.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index b97eb5787d4f..4152f92bfb2c 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -12,8 +12,6 @@ The main goal of version 8 is to improve our performance monitoring APIs, integr version is breaking because we removed deprecated APIs, restructured npm package contents, and introduced new dependencies on OpenTelemetry. Below we will outline the steps you need to take to tackle to deprecated methods. -## Removal of Client-Side health check transaction filters - Before updating to `8.x` of the SDK, we recommend upgrading to the latest version of `7.x`. You can then follow [these steps](./MIGRATION.md#deprecations-in-7x) remove deprecated methods in `7.x` before upgrading to `8.x`. From 5aa7bdb955fce1538057b18f89988559af24cf85 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 5 Mar 2024 16:08:01 +0100 Subject: [PATCH 5/6] migration --- MIGRATION.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 4152f92bfb2c..2a8fedfcc7c6 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -254,6 +254,7 @@ We now support the following integrations out of the box: - [Browser SDK](./MIGRATION.md#browser-sdk-browser-react-vue-angular-ember-etc) - [Server-side SDKs (Node, Deno, Bun)](./MIGRATION.md#server-side-sdks-node-deno-bun-etc) - [Next.js SDK](./MIGRATION.md#nextjs-sdk) +- [SvelteKit SDK](./MIGRATION.md#sveltekit-sdk) - [Astro SDK](./MIGRATION.md#astro-sdk) ### General @@ -542,8 +543,8 @@ Sentry.init({ #### Breaking `sentrySvelteKit()` changes We upgraded the `@sentry/vite-plugin` which is a dependency of the SvelteKit SDK from version 0.x to 2.x. With this -change, resolving uploaded source maps should work out of the box much more often than before (read more about this -[here](https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js/artifact-bundles/)). +change, resolving uploaded source maps should work out of the box much more often than before +([more information](https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js/artifact-bundles/)). To allow future upgrades of the Vite plugin without breaking stable and public APIs in `sentrySvelteKit`, we modified the `sourceMapsUploadOptions` to remove the hard dependency on the API of the plugin. While you previously could specify @@ -606,8 +607,8 @@ sentrySvelteKit({ }), ``` -Please note, that we DO NOT guarantee stability of `unstable_vitePluginOptions`. They can be removed or updated at any -time, including breaking changes within the same major version of the SDK. +Important: we DO NOT guarantee stability of `unstable_vitePluginOptions`. They can be removed or updated at any time, +including breaking changes within the same major version of the SDK. ## 5. Behaviour Changes From 18c08ee128f722dad23a5ff558f83f7158a72b45 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 5 Mar 2024 17:00:36 +0100 Subject: [PATCH 6/6] change name to `unstable_sentryVitePluginOptions` --- MIGRATION.md | 8 ++++---- packages/sveltekit/src/vite/sentryVitePlugins.ts | 11 ++++++----- .../test/vite/sentrySvelteKitPlugins.test.ts | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index 2a8fedfcc7c6..128c163e216e 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -587,7 +587,7 @@ sentrySvelteKit({ In the future, we might add additional [options](https://www.npmjs.com/package/@sentry/vite-plugin/v/2.14.2#options) from the Vite plugin but if you would like to specify some of them directly, you can do this by passing in an -`unstable_vitePluginOptions` object: +`unstable_sentryVitePluginOptions` object: ```js sentrySvelteKit({ @@ -596,7 +596,7 @@ sentrySvelteKit({ release: { name: '1.0.1', }, - unstable_vitePluginOptions: { + unstable_sentryVitePluginOptions: { release: { setCommits: { auto: true @@ -607,8 +607,8 @@ sentrySvelteKit({ }), ``` -Important: we DO NOT guarantee stability of `unstable_vitePluginOptions`. They can be removed or updated at any time, -including breaking changes within the same major version of the SDK. +Important: we DO NOT guarantee stability of `unstable_sentryVitePluginOptions`. They can be removed or updated at any +time, including breaking changes within the same major version of the SDK. ## 5. Behaviour Changes diff --git a/packages/sveltekit/src/vite/sentryVitePlugins.ts b/packages/sveltekit/src/vite/sentryVitePlugins.ts index c1d359a6e1c5..83a5cf4e19d6 100644 --- a/packages/sveltekit/src/vite/sentryVitePlugins.ts +++ b/packages/sveltekit/src/vite/sentryVitePlugins.ts @@ -129,7 +129,7 @@ type SourceMapsUploadOptions = { * * Furthermore, some options are untested with SvelteKit specifically. Use with caution. */ - unstable_vitePluginOptions?: Partial; + unstable_sentryVitePluginOptions?: Partial; }; }; @@ -212,12 +212,13 @@ export async function sentrySvelteKit(options: SentrySvelteKitPluginOptions = {} } if (mergedOptions.autoUploadSourceMaps && process.env.NODE_ENV !== 'development') { - const { unstable_vitePluginOptions, ...sourceMapsUploadOptions } = mergedOptions.sourceMapsUploadOptions || {}; + const { unstable_sentryVitePluginOptions, ...sourceMapsUploadOptions } = + mergedOptions.sourceMapsUploadOptions || {}; const sentryVitePluginsOptions = { ...sourceMapsUploadOptions, - ...unstable_vitePluginOptions, + ...unstable_sentryVitePluginOptions, adapter: mergedOptions.adapter, // override the plugin's debug flag with the one from the top-level options @@ -227,14 +228,14 @@ export async function sentrySvelteKit(options: SentrySvelteKitPluginOptions = {} if (sentryVitePluginsOptions.sourcemaps) { sentryVitePluginsOptions.sourcemaps = { ...sourceMapsUploadOptions?.sourcemaps, - ...unstable_vitePluginOptions?.sourcemaps, + ...unstable_sentryVitePluginOptions?.sourcemaps, }; } if (sentryVitePluginsOptions.release) { sentryVitePluginsOptions.release = { ...sourceMapsUploadOptions?.release, - ...unstable_vitePluginOptions?.release, + ...unstable_sentryVitePluginOptions?.release, }; } diff --git a/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts b/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts index 5988f10349e7..44f34362162f 100644 --- a/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts +++ b/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts @@ -127,7 +127,7 @@ describe('sentrySvelteKit()', () => { inject: false, name: '2.0.0', }, - unstable_vitePluginOptions: { + unstable_sentryVitePluginOptions: { org: 'other-org', sourcemaps: { assets: ['foo/*.js'],