From a9c3a28cf3c134435b9088b6baa9e20003d0f704 Mon Sep 17 00:00:00 2001 From: RulaKhaled Date: Tue, 11 Aug 2026 11:25:54 +0200 Subject: [PATCH 1/2] ref(astro): Remove deprecated release/debug conflict workaround from BuildTimeOptionsBase --- docs/migration/v11-end-state.md | 52 ++++++++++++ packages/astro/src/integration/index.ts | 17 ++-- packages/astro/src/integration/snippets.ts | 34 +++----- packages/astro/src/integration/types.ts | 30 ++----- packages/astro/test/buildOptions.test-d.ts | 8 -- packages/astro/test/integration/index.test.ts | 30 +++---- .../astro/test/integration/snippets.test.ts | 82 +++++-------------- 7 files changed, 106 insertions(+), 147 deletions(-) diff --git a/docs/migration/v11-end-state.md b/docs/migration/v11-end-state.md index 6e87345c90cd..fa364d86d2b1 100644 --- a/docs/migration/v11-end-state.md +++ b/docs/migration/v11-end-state.md @@ -952,6 +952,58 @@ export default defineConfig({ }); ``` +### `@sentry/astro` + +Runtime SDK options (`dsn`, `environment`, `release` as a string, `sampleRate`, `tracesSampleRate`, `replaysSessionSampleRate`, `replaysOnErrorSampleRate`) can no longer be passed to `sentryAstro()`. Configure them in `sentry.client.config.ts` / `sentry.server.config.ts` instead. `release` and `debug` on `sentryAstro()` are now build-time options (`release` for source map uploads, `debug` for build-time logging). If no config files exist, the generated default init snippets still pick them up (`release.name` as the runtime `release`, `debug` for SDK debug logging). The generated client snippet now always includes the `Replay` integration with default sample rates — to customize or remove it (previously done by setting both replay sample rates to `0`), create a `sentry.client.config.ts`. + +```ts +// astro.config.mjs — before +import { defineConfig } from 'astro/config'; +import sentry from '@sentry/astro'; + +export default defineConfig({ + integrations: [ + sentry({ + // runtime SDK options on the integration + dsn: 'https://example@sentry.io/123', + release: '1.0.0', + environment: 'production', + tracesSampleRate: 0.5, + }), + ], +}); +``` + +```ts +// astro.config.mjs — after (build-time options only) +import { defineConfig } from 'astro/config'; +import sentry from '@sentry/astro'; + +export default defineConfig({ + integrations: [ + sentry({ + org: 'my-org', + project: 'my-project', + authToken: process.env.SENTRY_AUTH_TOKEN, + release: { name: '1.0.0' }, + debug: true, + }), + ], +}); +``` + +```ts +// sentry.client.config.ts — after (runtime SDK options) +import * as Sentry from '@sentry/astro'; + +Sentry.init({ + dsn: 'https://example@sentry.io/123', + release: '1.0.0', + environment: 'production', + tracesSampleRate: 0.5, +}); +``` + ## 4. Package Removals ### `@sentry/types` is no longer published diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts index 5e2f4a76f479..ec353cbe567f 100644 --- a/packages/astro/src/integration/index.ts +++ b/packages/astro/src/integration/index.ts @@ -34,8 +34,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { // eslint-disable-next-line typescript/no-deprecated sourceMapsUploadOptions, sourcemaps, - // todo(v11): Extract `release` build time option here - cannot be done currently, because it conflicts with the `DeprecatedRuntimeOptions` type - // release, + release, buildTimeInstrumentation, bundleSizeOptimizations, applicationKey, @@ -49,18 +48,8 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { telemetry, silent, errorHandler, - ...deprecatedOptions } = options; - const deprecatedOptionsKeys = Object.keys(deprecatedOptions); - if (deprecatedOptionsKeys.length > 0) { - logger.warn( - `You passed in additional options (${deprecatedOptionsKeys.join( - ', ', - )}) to the Sentry integration. This is deprecated and will stop working in a future version. Instead, configure the Sentry SDK in your \`sentry.client.config.(js|ts)\` or \`sentry.server.config.(js|ts)\` files.`, - ); - } - const sdkEnabled = { client: typeof enabled === 'boolean' ? enabled : (enabled?.client ?? true), server: typeof enabled === 'boolean' ? enabled : (enabled?.server ?? true), @@ -134,6 +123,10 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { }, ...unstableMerged_sentryVitePluginOptions, debug: debug ?? false, + release: { + ...unstableMerged_sentryVitePluginOptions?.release, + ...release, + }, sourcemaps: { ...sourcemaps, // eslint-disable-next-line typescript/no-deprecated diff --git a/packages/astro/src/integration/snippets.ts b/packages/astro/src/integration/snippets.ts index 82278da28925..e578f417490c 100644 --- a/packages/astro/src/integration/snippets.ts +++ b/packages/astro/src/integration/snippets.ts @@ -18,8 +18,8 @@ export function buildClientSnippet(options: SentryOptions): string { Sentry.init({ ${buildCommonInitOptions(options)} integrations: [${buildClientIntegrations(options)}], - replaysSessionSampleRate: ${options.replaysSessionSampleRate ?? 0.1}, - replaysOnErrorSampleRate: ${options.replaysOnErrorSampleRate ?? 1.0}, + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0, });`; } @@ -35,22 +35,17 @@ Sentry.init({ });`; } -const buildCommonInitOptions = (options: SentryOptions): string => `dsn: ${ - options.dsn ? JSON.stringify(options.dsn) : 'import.meta.env.PUBLIC_SENTRY_DSN' -}, +const buildCommonInitOptions = (options: SentryOptions): string => `dsn: import.meta.env.PUBLIC_SENTRY_DSN, debug: ${options.debug ? true : false}, - environment: ${options.environment ? JSON.stringify(options.environment) : 'import.meta.env.PUBLIC_VERCEL_ENV'}, - release: ${options.release ? JSON.stringify(options.release) : 'import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA'}, - tracesSampleRate: ${options.tracesSampleRate ?? 1.0},${ - options.sampleRate ? `\n sampleRate: ${options.sampleRate},` : '' - }`; + environment: import.meta.env.PUBLIC_VERCEL_ENV, + release: ${ + options.release?.name ? JSON.stringify(options.release.name) : 'import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA' + }, + tracesSampleRate: 1.0,`; /** - * We don't include the `BrowserTracing` integration if `bundleSizeOptimizations.excludeTracing` is falsy. - * Likewise, we don't include the `Replay` integration if the replaysSessionSampleRate - * and replaysOnErrorSampleRate are set to 0. - * - * This way, we avoid unnecessarily adding the integrations and thereby enable tree shaking of the integrations. + * We don't include the `BrowserTracing` integration if `bundleSizeOptimizations.excludeTracing` is set. + * The `Replay` integration, however, is always included with default sample rates in the generated snippet. */ const buildClientIntegrations = (options: SentryOptions): string => { const integrations: string[] = []; @@ -59,14 +54,7 @@ const buildClientIntegrations = (options: SentryOptions): string => { integrations.push('Sentry.browserTracingIntegration()'); } - if ( - options.replaysSessionSampleRate == null || - options.replaysSessionSampleRate || - options.replaysOnErrorSampleRate == null || - options.replaysOnErrorSampleRate - ) { - integrations.push('Sentry.replayIntegration()'); - } + integrations.push('Sentry.replayIntegration()'); return integrations.join(', '); }; diff --git a/packages/astro/src/integration/types.ts b/packages/astro/src/integration/types.ts index b43061b2d24c..ba45ba2bb6d4 100644 --- a/packages/astro/src/integration/types.ts +++ b/packages/astro/src/integration/types.ts @@ -8,8 +8,7 @@ type SdkInitPaths = { * * If this option is not specified, the default location (`/sentry.client.config.(js|ts)`) * will be used to look up the config file. - * If there is no file at the default location either, the SDK will initialize with the options - * specified in the `sentryAstro` integration or with default options. + * If there is no file at the default location either, the SDK will initialize with default options. */ clientInitPath?: string; @@ -18,8 +17,7 @@ type SdkInitPaths = { * * If this option is not specified, the default location (`/sentry.server.config.(js|ts)`) * will be used to look up the config file. - * If there is no file at the default location either, the SDK will initialize with the options - * specified in the `sentryAstro` integration or with default options. + * If there is no file at the default location either, the SDK will initialize with default options. */ serverInitPath?: string; }; @@ -158,25 +156,14 @@ type SdkEnabledOptions = { }; /** - * We accept aribtrary options that are passed through to the Sentry SDK. - * This is not recommended and will stop working in a future version. - * Note: Not all options are actually passed through, only a select subset: - * release, environment, dsn, debug, sampleRate, tracesSampleRate, replaysSessionSampleRate, replaysOnErrorSampleRate - * @deprecated This will be removed in a future major. - **/ -type DeprecatedRuntimeOptions = Record; - -/** - * A subset of Sentry SDK options that can be set via the `sentryAstro` integration. - * Some options (e.g. integrations) are set by default and cannot be changed here. + * Options for the `sentryAstro` integration. * - * If you want a more fine-grained control over the SDK, with all options, - * you can call Sentry.init in `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files. + * Build-time options (source maps, release management, etc.) are configured here. + * Runtime SDK options must be set in `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)`. * - * If you specify a dedicated init file, the SDK options passed to `sentryAstro` will be ignored. + * If you specify a dedicated init file, the SDK options passed to `sentryAstro` will be ignored for init. */ -export type SentryOptions = Omit & - // todo(v11): `release` and `debug` need to be removed from BuildTimeOptionsBase as it is currently conflicting with `DeprecatedRuntimeOptions` +export type SentryOptions = BuildTimeOptionsBase & UnstableVitePluginOptions & SdkInitPaths & InstrumentationOptions & @@ -192,8 +179,7 @@ export type SentryOptions = Omit & */ // eslint-disable-next-line typescript/no-deprecated sourceMapsUploadOptions?: SourceMapsOptions; - // eslint-disable-next-line typescript/no-deprecated - } & DeprecatedRuntimeOptions; + }; /** * Routes inside 'astro:routes:resolved' hook (Astro v5+) diff --git a/packages/astro/test/buildOptions.test-d.ts b/packages/astro/test/buildOptions.test-d.ts index ec4c9c5330f7..ea649ec7b2c2 100644 --- a/packages/astro/test/buildOptions.test-d.ts +++ b/packages/astro/test/buildOptions.test-d.ts @@ -69,14 +69,6 @@ describe('Sentry Astro build-time options type', () => { autoInstrumentation: { requestHandler: true, }, - - // Deprecated runtime options - environment: 'test', - dsn: 'https://test@sentry.io/123', - sampleRate: 1.0, - tracesSampleRate: 1.0, - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1.0, }; expectTypeOf(completeOptions).toEqualTypeOf(); diff --git a/packages/astro/test/integration/index.test.ts b/packages/astro/test/integration/index.test.ts index 992ec9832144..c1c9b0d1f2a8 100644 --- a/packages/astro/test/integration/index.test.ts +++ b/packages/astro/test/integration/index.test.ts @@ -524,38 +524,30 @@ describe('sentryAstro integration', () => { expect(injectScript).toHaveBeenCalledWith('page-ssr', expect.stringContaining('Sentry.init')); }); - it('injects runtime config into client and server init scripts and warns about deprecation', async () => { + it('passes build-time release options to the Sentry vite plugin and init snippets', async () => { const integration = sentryAstro({ project: 'my-project', - environment: 'test', - release: '1.0.0', - dsn: 'https://test.sentry.io/123', - bundleSizeOptimizations: {}, - // this also warns when debug is not enabled + release: { name: '1.0.0' }, + debug: true, }); - const logger = { - warn: vi.fn(), - info: vi.fn(), - }; - expect(integration.hooks['astro:config:setup']).toBeDefined(); // @ts-expect-error - the hook exists and we only need to pass what we actually use - await integration.hooks['astro:config:setup']({ updateConfig, injectScript, config, logger }); + await integration.hooks['astro:config:setup']({ ...baseConfigHookObject, updateConfig, injectScript, config }); - expect(logger.warn).toHaveBeenCalledWith( - 'You passed in additional options (environment, release, dsn) to the Sentry integration. This is deprecated and will stop working in a future version. Instead, configure the Sentry SDK in your `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.', + expect(sentryVitePluginSpy).toHaveBeenCalledWith( + expect.objectContaining({ + release: { name: '1.0.0' }, + debug: true, + }), ); expect(injectScript).toHaveBeenCalledTimes(2); expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('Sentry.init')); - expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('dsn: "https://test.sentry.io/123"')); expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('release: "1.0.0"')); - expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('environment: "test"')); - expect(injectScript).toHaveBeenCalledWith('page-ssr', expect.stringContaining('Sentry.init')); - expect(injectScript).toHaveBeenCalledWith('page-ssr', expect.stringContaining('dsn: "https://test.sentry.io/123"')); + expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('debug: true')); + expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('dsn: import.meta.env.PUBLIC_SENTRY_DSN')); expect(injectScript).toHaveBeenCalledWith('page-ssr', expect.stringContaining('release: "1.0.0"')); - expect(injectScript).toHaveBeenCalledWith('page-ssr', expect.stringContaining('environment: "test"')); }); it("doesn't inject client init script if `enabled.client` is `false`", async () => { diff --git a/packages/astro/test/integration/snippets.test.ts b/packages/astro/test/integration/snippets.test.ts index 4c3f1a88d25d..0525e4fe1feb 100644 --- a/packages/astro/test/integration/snippets.test.ts +++ b/packages/astro/test/integration/snippets.test.ts @@ -2,14 +2,8 @@ import { describe, expect, it } from 'vitest'; import { buildClientSnippet, buildSdkInitFileImportSnippet, buildServerSnippet } from '../../src/integration/snippets'; import type { SentryOptions } from '../../src/integration/types'; -const allSdkOptions: SentryOptions = { - dsn: 'my-dsn', - release: '1.0.0', - environment: 'staging', - sampleRate: 0.2, - tracesSampleRate: 0.3, - replaysOnErrorSampleRate: 0.4, - replaysSessionSampleRate: 0.5, +const buildTimeSdkOptions: SentryOptions = { + release: { name: '1.0.0' }, debug: true, }; @@ -24,30 +18,29 @@ describe('buildClientSnippet', () => { debug: false, environment: import.meta.env.PUBLIC_VERCEL_ENV, release: import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA, - tracesSampleRate: 1, + tracesSampleRate: 1.0, integrations: [Sentry.browserTracingIntegration(), Sentry.replayIntegration()], replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1, + replaysOnErrorSampleRate: 1.0, });" `); }); - it('returns a basic Sentry init call with custom options', () => { - const snippet = buildClientSnippet(allSdkOptions); + it('returns a basic Sentry init call with build-time options', () => { + const snippet = buildClientSnippet(buildTimeSdkOptions); expect(snippet).toMatchInlineSnapshot(` "import * as Sentry from "@sentry/astro"; Sentry.init({ - dsn: "my-dsn", + dsn: import.meta.env.PUBLIC_SENTRY_DSN, debug: true, - environment: "staging", + environment: import.meta.env.PUBLIC_VERCEL_ENV, release: "1.0.0", - tracesSampleRate: 0.3, - sampleRate: 0.2, + tracesSampleRate: 1.0, integrations: [Sentry.browserTracingIntegration(), Sentry.replayIntegration()], - replaysSessionSampleRate: 0.5, - replaysOnErrorSampleRate: 0.4, + replaysSessionSampleRate: 0.1, + replaysOnErrorSampleRate: 1.0, });" `); }); @@ -62,51 +55,15 @@ describe('buildClientSnippet', () => { debug: false, environment: import.meta.env.PUBLIC_VERCEL_ENV, release: import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA, - tracesSampleRate: 1, + tracesSampleRate: 1.0, integrations: [Sentry.replayIntegration()], replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1, - });" - `); - }); - - it('still include browserTracingIntegration if tracesSampleRate is 0', () => { - const snippet = buildClientSnippet({ tracesSampleRate: 0 }); - expect(snippet).toMatchInlineSnapshot(` - "import * as Sentry from "@sentry/astro"; - - Sentry.init({ - dsn: import.meta.env.PUBLIC_SENTRY_DSN, - debug: false, - environment: import.meta.env.PUBLIC_VERCEL_ENV, - release: import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA, - tracesSampleRate: 0, - integrations: [Sentry.browserTracingIntegration(), Sentry.replayIntegration()], - replaysSessionSampleRate: 0.1, - replaysOnErrorSampleRate: 1, + replaysOnErrorSampleRate: 1.0, });" `); }); }); -it('does not include Replay if replay sample ratest are 0', () => { - const snippet = buildClientSnippet({ replaysSessionSampleRate: 0, replaysOnErrorSampleRate: 0 }); - expect(snippet).toMatchInlineSnapshot(` - "import * as Sentry from "@sentry/astro"; - - Sentry.init({ - dsn: import.meta.env.PUBLIC_SENTRY_DSN, - debug: false, - environment: import.meta.env.PUBLIC_VERCEL_ENV, - release: import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA, - tracesSampleRate: 1, - integrations: [Sentry.browserTracingIntegration()], - replaysSessionSampleRate: 0, - replaysOnErrorSampleRate: 0, - });" - `); -}); - describe('buildServerSnippet', () => { it('returns a basic Sentry init call with default options', () => { const snippet = buildServerSnippet({}); @@ -118,24 +75,23 @@ describe('buildServerSnippet', () => { debug: false, environment: import.meta.env.PUBLIC_VERCEL_ENV, release: import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA, - tracesSampleRate: 1, + tracesSampleRate: 1.0, });" `); }); - it('returns a basic Sentry init call with custom options', () => { - const snippet = buildServerSnippet(allSdkOptions); + it('returns a basic Sentry init call with build-time options', () => { + const snippet = buildServerSnippet(buildTimeSdkOptions); expect(snippet).toMatchInlineSnapshot(` "import * as Sentry from "@sentry/astro"; Sentry.init({ - dsn: "my-dsn", + dsn: import.meta.env.PUBLIC_SENTRY_DSN, debug: true, - environment: "staging", + environment: import.meta.env.PUBLIC_VERCEL_ENV, release: "1.0.0", - tracesSampleRate: 0.3, - sampleRate: 0.2, + tracesSampleRate: 1.0, });" `); }); From 6fab126b1e3c006e1e686d41355b2815a1d8e4da Mon Sep 17 00:00:00 2001 From: RulaKhaled Date: Tue, 11 Aug 2026 11:55:39 +0200 Subject: [PATCH 2/2] fix format --- packages/astro/test/integration/index.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/astro/test/integration/index.test.ts b/packages/astro/test/integration/index.test.ts index c1c9b0d1f2a8..132c280e3a9a 100644 --- a/packages/astro/test/integration/index.test.ts +++ b/packages/astro/test/integration/index.test.ts @@ -546,7 +546,10 @@ describe('sentryAstro integration', () => { expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('Sentry.init')); expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('release: "1.0.0"')); expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('debug: true')); - expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('dsn: import.meta.env.PUBLIC_SENTRY_DSN')); + expect(injectScript).toHaveBeenCalledWith( + 'page', + expect.stringContaining('dsn: import.meta.env.PUBLIC_SENTRY_DSN'), + ); expect(injectScript).toHaveBeenCalledWith('page-ssr', expect.stringContaining('release: "1.0.0"')); });