diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts index 79b74b8804c1..fb26e956daeb 100644 --- a/packages/astro/src/integration/index.ts +++ b/packages/astro/src/integration/index.ts @@ -30,7 +30,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { }; const sourceMapsNeeded = sdkEnabled.client || sdkEnabled.server; - const uploadOptions = options.sourceMapsUploadOptions || {}; + const { unstable_sentryVitePluginOptions, ...uploadOptions } = options.sourceMapsUploadOptions || {}; const shouldUploadSourcemaps = (sourceMapsNeeded && uploadOptions?.enabled) ?? true; // We don't need to check for AUTH_TOKEN here, because the plugin will pick it up from the env @@ -68,23 +68,26 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { project: uploadOptions.project ?? env.SENTRY_PROJECT, authToken: uploadOptions.authToken ?? env.SENTRY_AUTH_TOKEN, telemetry: uploadOptions.telemetry ?? true, + _metaOptions: { + telemetry: { + metaFramework: 'astro', + }, + }, + ...unstable_sentryVitePluginOptions, + debug: options.debug ?? false, sourcemaps: { assets: uploadOptions.assets ?? [getSourcemapsAssetsGlob(config)], filesToDeleteAfterUpload: uploadOptions?.filesToDeleteAfterUpload ?? updatedFilesToDeleteAfterUpload, + ...unstable_sentryVitePluginOptions?.sourcemaps, }, bundleSizeOptimizations: { ...options.bundleSizeOptimizations, // TODO: with a future version of the vite plugin (probably 2.22.0) this re-mapping is not needed anymore // ref: https://github.com/getsentry/sentry-javascript-bundler-plugins/pull/582 excludePerformanceMonitoring: options.bundleSizeOptimizations?.excludeTracing, + ...unstable_sentryVitePluginOptions?.bundleSizeOptimizations, }, - _metaOptions: { - telemetry: { - metaFramework: 'astro', - }, - }, - debug: options.debug ?? false, }), ), ], diff --git a/packages/astro/src/integration/types.ts b/packages/astro/src/integration/types.ts index 6c2e41808eca..5b5308e3a474 100644 --- a/packages/astro/src/integration/types.ts +++ b/packages/astro/src/integration/types.ts @@ -1,5 +1,6 @@ import type { BrowserOptions } from '@sentry/browser'; import type { Options } from '@sentry/core'; +import type { SentryVitePluginOptions } from '@sentry/vite-plugin'; type SdkInitPaths = { /** @@ -83,6 +84,20 @@ type SourceMapsOptions = { * The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob) */ filesToDeleteAfterUpload?: string | Array; + + /** + * Options to further customize the Sentry Vite Plugin (@sentry/vite-plugin) behavior directly. + * Options specified in this object take precedence over all other options. + * + * @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 Astro specifically. Use with caution. + */ + unstable_sentryVitePluginOptions?: Partial; }; type BundleSizeOptimizationOptions = { diff --git a/packages/astro/test/integration/index.test.ts b/packages/astro/test/integration/index.test.ts index 6684a841ba4e..01d86e85baee 100644 --- a/packages/astro/test/integration/index.test.ts +++ b/packages/astro/test/integration/index.test.ts @@ -202,6 +202,59 @@ describe('sentryAstro integration', () => { ); }); + it('prefers user-specified unstable vite plugin options and merges them with default values', async () => { + const integration = sentryAstro({ + bundleSizeOptimizations: { + excludeReplayShadowDom: true, + }, + sourceMapsUploadOptions: { + enabled: true, + org: 'my-org', + project: 'my-project', + assets: ['dist/server/**/*, dist/client/**/*'], + unstable_sentryVitePluginOptions: { + org: 'my-other-org', + project: 'my-other-project', + applicationKey: 'my-application-key', + sourcemaps: { + assets: ['foo/*.js'], + ignore: ['bar/*.js'], + }, + bundleSizeOptimizations: { + excludeReplayIframe: true, + }, + }, + }, + }); + // @ts-expect-error - the hook exists, and we only need to pass what we actually use + await integration.hooks['astro:config:setup']({ + updateConfig, + injectScript, + // @ts-expect-error - only passing in partial config + config: { + outDir: new URL('file://path/to/project/build'), + }, + }); + + expect(sentryVitePluginSpy).toHaveBeenCalledTimes(1); + expect(sentryVitePluginSpy).toHaveBeenCalledWith( + expect.objectContaining({ + org: 'my-other-org', + project: 'my-other-project', + applicationKey: 'my-application-key', + sourcemaps: { + assets: ['foo/*.js'], + ignore: ['bar/*.js'], + filesToDeleteAfterUpload: ['./dist/**/client/**/*.map', './dist/**/server/**/*.map'], + }, + bundleSizeOptimizations: { + excludeReplayShadowDom: true, + excludeReplayIframe: true, + }, + }), + ); + }); + it("doesn't enable source maps if `sourceMapsUploadOptions.enabled` is `false`", async () => { const integration = sentryAstro({ sourceMapsUploadOptions: { enabled: false },