Skip to content

Commit 857c7f8

Browse files
ref(astro)!: Remove deprecated release/debug conflict workaround from BuildTimeOptionsBase (#23270)
Removes the `DeprecatedRuntimeOptions` catch-all type in `@sentry/astro` that was blocking `release` and `debug` from being proper build-time options on `BuildTimeOptionsBase`. The other deprecated runtime options (`dsn`, `environment`, `sampleRate`, `tracesSampleRate`, `replaysSessionSampleRate`, `replaysOnErrorSampleRate`) have no build-time equivalent, so they can no longer be set via `sentryAstro()` at all. The generated snippet now falls back to fixed defaults for them. This was already the deprecated, discouraged path; anyone needing non-default values already needs (and can continue using) a dedicated `sentry.client.config.ts` / `sentry.server.config.ts` file with a direct `Sentry.init()` call, which is unaffected by this change. Closes #22248 --------- Co-authored-by: Fable 5 <cursoragent@cursor.com>
1 parent 3ea17e4 commit 857c7f8

7 files changed

Lines changed: 109 additions & 147 deletions

File tree

‎docs/migration/v11-end-state.md‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,58 @@ export default defineConfig({
979979
});
980980
```
981981
982+
### `@sentry/astro`
983+
984+
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`.
985+
986+
```ts
987+
// astro.config.mjs — before
988+
import { defineConfig } from 'astro/config';
989+
import sentry from '@sentry/astro';
990+
991+
export default defineConfig({
992+
integrations: [
993+
sentry({
994+
// runtime SDK options on the integration
995+
dsn: 'https://example@sentry.io/123',
996+
release: '1.0.0',
997+
environment: 'production',
998+
tracesSampleRate: 0.5,
999+
}),
1000+
],
1001+
});
1002+
```
1003+
1004+
```ts
1005+
// astro.config.mjs — after (build-time options only)
1006+
import { defineConfig } from 'astro/config';
1007+
import sentry from '@sentry/astro';
1008+
1009+
export default defineConfig({
1010+
integrations: [
1011+
sentry({
1012+
org: 'my-org',
1013+
project: 'my-project',
1014+
authToken: process.env.SENTRY_AUTH_TOKEN,
1015+
release: { name: '1.0.0' },
1016+
debug: true,
1017+
}),
1018+
],
1019+
});
1020+
```
1021+
1022+
```ts
1023+
// sentry.client.config.ts — after (runtime SDK options)
1024+
import * as Sentry from '@sentry/astro';
1025+
1026+
Sentry.init({
1027+
dsn: 'https://example@sentry.io/123',
1028+
release: '1.0.0',
1029+
environment: 'production',
1030+
tracesSampleRate: 0.5,
1031+
});
1032+
```
1033+
9821034
### `@sentry/react-router`
9831035
9841036
The deprecated `sourceMapsUploadOptions` option was removed from `sentryReactRouter()`. Move its fields to the root level of the `sentryConfig` passed to `sentryReactRouter()`. Note that `enabled` was replaced by `sourcemaps.disable` (inverted: `enabled: false` becomes `sourcemaps: { disable: true }`).

‎packages/astro/src/integration/index.ts‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
3434
// eslint-disable-next-line typescript/no-deprecated
3535
sourceMapsUploadOptions,
3636
sourcemaps,
37-
// todo(v11): Extract `release` build time option here - cannot be done currently, because it conflicts with the `DeprecatedRuntimeOptions` type
38-
// release,
37+
release,
3938
buildTimeInstrumentation,
4039
bundleSizeOptimizations,
4140
applicationKey,
@@ -49,18 +48,8 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
4948
telemetry,
5049
silent,
5150
errorHandler,
52-
...deprecatedOptions
5351
} = options;
5452

55-
const deprecatedOptionsKeys = Object.keys(deprecatedOptions);
56-
if (deprecatedOptionsKeys.length > 0) {
57-
logger.warn(
58-
`You passed in additional options (${deprecatedOptionsKeys.join(
59-
', ',
60-
)}) 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.`,
61-
);
62-
}
63-
6453
const sdkEnabled = {
6554
client: typeof enabled === 'boolean' ? enabled : (enabled?.client ?? true),
6655
server: typeof enabled === 'boolean' ? enabled : (enabled?.server ?? true),
@@ -134,6 +123,10 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
134123
},
135124
...unstableMerged_sentryVitePluginOptions,
136125
debug: debug ?? false,
126+
release: {
127+
...unstableMerged_sentryVitePluginOptions?.release,
128+
...release,
129+
},
137130
sourcemaps: {
138131
...sourcemaps,
139132
// eslint-disable-next-line typescript/no-deprecated

‎packages/astro/src/integration/snippets.ts‎

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export function buildClientSnippet(options: SentryOptions): string {
1818
Sentry.init({
1919
${buildCommonInitOptions(options)}
2020
integrations: [${buildClientIntegrations(options)}],
21-
replaysSessionSampleRate: ${options.replaysSessionSampleRate ?? 0.1},
22-
replaysOnErrorSampleRate: ${options.replaysOnErrorSampleRate ?? 1.0},
21+
replaysSessionSampleRate: 0.1,
22+
replaysOnErrorSampleRate: 1.0,
2323
});`;
2424
}
2525

@@ -35,22 +35,17 @@ Sentry.init({
3535
});`;
3636
}
3737

38-
const buildCommonInitOptions = (options: SentryOptions): string => `dsn: ${
39-
options.dsn ? JSON.stringify(options.dsn) : 'import.meta.env.PUBLIC_SENTRY_DSN'
40-
},
38+
const buildCommonInitOptions = (options: SentryOptions): string => `dsn: import.meta.env.PUBLIC_SENTRY_DSN,
4139
debug: ${options.debug ? true : false},
42-
environment: ${options.environment ? JSON.stringify(options.environment) : 'import.meta.env.PUBLIC_VERCEL_ENV'},
43-
release: ${options.release ? JSON.stringify(options.release) : 'import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA'},
44-
tracesSampleRate: ${options.tracesSampleRate ?? 1.0},${
45-
options.sampleRate ? `\n sampleRate: ${options.sampleRate},` : ''
46-
}`;
40+
environment: import.meta.env.PUBLIC_VERCEL_ENV,
41+
release: ${
42+
options.release?.name ? JSON.stringify(options.release.name) : 'import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA'
43+
},
44+
tracesSampleRate: 1.0,`;
4745

4846
/**
49-
* We don't include the `BrowserTracing` integration if `bundleSizeOptimizations.excludeTracing` is falsy.
50-
* Likewise, we don't include the `Replay` integration if the replaysSessionSampleRate
51-
* and replaysOnErrorSampleRate are set to 0.
52-
*
53-
* This way, we avoid unnecessarily adding the integrations and thereby enable tree shaking of the integrations.
47+
* We don't include the `BrowserTracing` integration if `bundleSizeOptimizations.excludeTracing` is set.
48+
* The `Replay` integration, however, is always included with default sample rates in the generated snippet.
5449
*/
5550
const buildClientIntegrations = (options: SentryOptions): string => {
5651
const integrations: string[] = [];
@@ -59,14 +54,7 @@ const buildClientIntegrations = (options: SentryOptions): string => {
5954
integrations.push('Sentry.browserTracingIntegration()');
6055
}
6156

62-
if (
63-
options.replaysSessionSampleRate == null ||
64-
options.replaysSessionSampleRate ||
65-
options.replaysOnErrorSampleRate == null ||
66-
options.replaysOnErrorSampleRate
67-
) {
68-
integrations.push('Sentry.replayIntegration()');
69-
}
57+
integrations.push('Sentry.replayIntegration()');
7058

7159
return integrations.join(', ');
7260
};

‎packages/astro/src/integration/types.ts‎

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ type SdkInitPaths = {
88
*
99
* If this option is not specified, the default location (`<projectRoot>/sentry.client.config.(js|ts)`)
1010
* will be used to look up the config file.
11-
* If there is no file at the default location either, the SDK will initialize with the options
12-
* specified in the `sentryAstro` integration or with default options.
11+
* If there is no file at the default location either, the SDK will initialize with default options.
1312
*/
1413
clientInitPath?: string;
1514

@@ -18,8 +17,7 @@ type SdkInitPaths = {
1817
*
1918
* If this option is not specified, the default location (`<projectRoot>/sentry.server.config.(js|ts)`)
2019
* will be used to look up the config file.
21-
* If there is no file at the default location either, the SDK will initialize with the options
22-
* specified in the `sentryAstro` integration or with default options.
20+
* If there is no file at the default location either, the SDK will initialize with default options.
2321
*/
2422
serverInitPath?: string;
2523
};
@@ -158,25 +156,14 @@ type SdkEnabledOptions = {
158156
};
159157

160158
/**
161-
* We accept aribtrary options that are passed through to the Sentry SDK.
162-
* This is not recommended and will stop working in a future version.
163-
* Note: Not all options are actually passed through, only a select subset:
164-
* release, environment, dsn, debug, sampleRate, tracesSampleRate, replaysSessionSampleRate, replaysOnErrorSampleRate
165-
* @deprecated This will be removed in a future major.
166-
**/
167-
type DeprecatedRuntimeOptions = Record<string, unknown>;
168-
169-
/**
170-
* A subset of Sentry SDK options that can be set via the `sentryAstro` integration.
171-
* Some options (e.g. integrations) are set by default and cannot be changed here.
159+
* Options for the `sentryAstro` integration.
172160
*
173-
* If you want a more fine-grained control over the SDK, with all options,
174-
* you can call Sentry.init in `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.
161+
* Build-time options (source maps, release management, etc.) are configured here.
162+
* Runtime SDK options must be set in `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)`.
175163
*
176-
* If you specify a dedicated init file, the SDK options passed to `sentryAstro` will be ignored.
164+
* If you specify a dedicated init file, the SDK options passed to `sentryAstro` will be ignored for init.
177165
*/
178-
export type SentryOptions = Omit<BuildTimeOptionsBase, 'release'> &
179-
// todo(v11): `release` and `debug` need to be removed from BuildTimeOptionsBase as it is currently conflicting with `DeprecatedRuntimeOptions`
166+
export type SentryOptions = BuildTimeOptionsBase &
180167
UnstableVitePluginOptions<SentryVitePluginOptions> &
181168
SdkInitPaths &
182169
InstrumentationOptions &
@@ -192,8 +179,7 @@ export type SentryOptions = Omit<BuildTimeOptionsBase, 'release'> &
192179
*/
193180
// eslint-disable-next-line typescript/no-deprecated
194181
sourceMapsUploadOptions?: SourceMapsOptions;
195-
// eslint-disable-next-line typescript/no-deprecated
196-
} & DeprecatedRuntimeOptions;
182+
};
197183

198184
/**
199185
* Routes inside 'astro:routes:resolved' hook (Astro v5+)

‎packages/astro/test/buildOptions.test-d.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,6 @@ describe('Sentry Astro build-time options type', () => {
6969
autoInstrumentation: {
7070
requestHandler: true,
7171
},
72-
73-
// Deprecated runtime options
74-
environment: 'test',
75-
dsn: 'https://test@sentry.io/123',
76-
sampleRate: 1.0,
77-
tracesSampleRate: 1.0,
78-
replaysSessionSampleRate: 0.1,
79-
replaysOnErrorSampleRate: 1.0,
8072
};
8173

8274
expectTypeOf(completeOptions).toEqualTypeOf<SentryOptions>();

‎packages/astro/test/integration/index.test.ts‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -524,38 +524,33 @@ describe('sentryAstro integration', () => {
524524
expect(injectScript).toHaveBeenCalledWith('page-ssr', expect.stringContaining('Sentry.init'));
525525
});
526526

527-
it('injects runtime config into client and server init scripts and warns about deprecation', async () => {
527+
it('passes build-time release options to the Sentry vite plugin and init snippets', async () => {
528528
const integration = sentryAstro({
529529
project: 'my-project',
530-
environment: 'test',
531-
release: '1.0.0',
532-
dsn: 'https://test.sentry.io/123',
533-
bundleSizeOptimizations: {},
534-
// this also warns when debug is not enabled
530+
release: { name: '1.0.0' },
531+
debug: true,
535532
});
536533

537-
const logger = {
538-
warn: vi.fn(),
539-
info: vi.fn(),
540-
};
541-
542534
expect(integration.hooks['astro:config:setup']).toBeDefined();
543535
// @ts-expect-error - the hook exists and we only need to pass what we actually use
544-
await integration.hooks['astro:config:setup']({ updateConfig, injectScript, config, logger });
536+
await integration.hooks['astro:config:setup']({ ...baseConfigHookObject, updateConfig, injectScript, config });
545537

546-
expect(logger.warn).toHaveBeenCalledWith(
547-
'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.',
538+
expect(sentryVitePluginSpy).toHaveBeenCalledWith(
539+
expect.objectContaining({
540+
release: { name: '1.0.0' },
541+
debug: true,
542+
}),
548543
);
549544

550545
expect(injectScript).toHaveBeenCalledTimes(2);
551546
expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('Sentry.init'));
552-
expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('dsn: "https://test.sentry.io/123"'));
553547
expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('release: "1.0.0"'));
554-
expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('environment: "test"'));
555-
expect(injectScript).toHaveBeenCalledWith('page-ssr', expect.stringContaining('Sentry.init'));
556-
expect(injectScript).toHaveBeenCalledWith('page-ssr', expect.stringContaining('dsn: "https://test.sentry.io/123"'));
548+
expect(injectScript).toHaveBeenCalledWith('page', expect.stringContaining('debug: true'));
549+
expect(injectScript).toHaveBeenCalledWith(
550+
'page',
551+
expect.stringContaining('dsn: import.meta.env.PUBLIC_SENTRY_DSN'),
552+
);
557553
expect(injectScript).toHaveBeenCalledWith('page-ssr', expect.stringContaining('release: "1.0.0"'));
558-
expect(injectScript).toHaveBeenCalledWith('page-ssr', expect.stringContaining('environment: "test"'));
559554
});
560555

561556
it("doesn't inject client init script if `enabled.client` is `false`", async () => {

0 commit comments

Comments
 (0)