Skip to content

Commit 8a4098a

Browse files
authored
feat(astro): Deprecate passing init options to sentry integration (#14489)
1 parent e2883df commit 8a4098a

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

docs/migration/draft-v9-migration-guide.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
});
9090
```
9191

92+
## `@sentry/astro`
93+
94+
- Deprecated passing `dsn`, `release`, `environment`, `sampleRate`, `tracesSampleRate`, `replaysSessionSampleRate` to the integration. Use the runtime-specific `Sentry.init()` calls for passing these options instead.
95+
9296
## `@sentry/remix`
9397

9498
- Deprecated `autoInstrumentRemix: false`. The next major version will default to behaving as if this option were `true` and the option itself will be removed.

packages/astro/src/integration/snippets.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function buildSdkInitFileImportSnippet(filePath: string): string {
1414
* default options.
1515
*/
1616
export function buildClientSnippet(options: SentryOptions): string {
17+
/* eslint-disable deprecation/deprecation */
1718
return `import * as Sentry from "@sentry/astro";
1819
1920
Sentry.init({
@@ -22,6 +23,7 @@ Sentry.init({
2223
replaysSessionSampleRate: ${options.replaysSessionSampleRate ?? 0.1},
2324
replaysOnErrorSampleRate: ${options.replaysOnErrorSampleRate ?? 1.0},
2425
});`;
26+
/* eslint-enable deprecation/deprecation */
2527
}
2628

2729
/**
@@ -36,6 +38,7 @@ Sentry.init({
3638
});`;
3739
}
3840

41+
/* eslint-disable deprecation/deprecation */
3942
const buildCommonInitOptions = (options: SentryOptions): string => `dsn: ${
4043
options.dsn ? JSON.stringify(options.dsn) : 'import.meta.env.PUBLIC_SENTRY_DSN'
4144
},
@@ -45,6 +48,7 @@ const buildCommonInitOptions = (options: SentryOptions): string => `dsn: ${
4548
tracesSampleRate: ${options.tracesSampleRate ?? 1.0},${
4649
options.sampleRate ? `\n sampleRate: ${options.sampleRate},` : ''
4750
}`;
51+
/* eslint-enable deprecation/deprecation */
4852

4953
/**
5054
* We don't include the `BrowserTracing` integration if `bundleSizeOptimizations.excludeTracing` is falsy.
@@ -61,9 +65,13 @@ const buildClientIntegrations = (options: SentryOptions): string => {
6165
}
6266

6367
if (
68+
// eslint-disable-next-line deprecation/deprecation
6469
options.replaysSessionSampleRate == null ||
70+
// eslint-disable-next-line deprecation/deprecation
6571
options.replaysSessionSampleRate ||
72+
// eslint-disable-next-line deprecation/deprecation
6673
options.replaysOnErrorSampleRate == null ||
74+
// eslint-disable-next-line deprecation/deprecation
6775
options.replaysOnErrorSampleRate
6876
) {
6977
integrations.push('Sentry.replayIntegration()');

packages/astro/src/integration/types.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ type SdkEnabledOptions = {
150150
* Sentry code will be added to your bundle.
151151
*
152152
* @default true - the SDK is enabled by default for both, client and server.
153+
*
153154
*/
154155
enabled?:
155156
| boolean
@@ -159,6 +160,41 @@ type SdkEnabledOptions = {
159160
};
160161
};
161162

163+
type DeprecatedRuntimeOptions = Pick<
164+
Options,
165+
'environment' | 'release' | 'dsn' | 'debug' | 'sampleRate' | 'tracesSampleRate'
166+
> &
167+
Pick<BrowserOptions, 'replaysSessionSampleRate' | 'replaysOnErrorSampleRate'> & {
168+
/**
169+
* @deprecated Use the `environment` option in your runtime-specific Sentry.init() call in sentry.client.config.(js|ts) or sentry.server.config.(js|ts) instead.
170+
*/
171+
environment?: string;
172+
/**
173+
* @deprecated Use the `release` option in your runtime-specific Sentry.init() call in sentry.client.config.(js|ts) or sentry.server.config.(js|ts) instead.
174+
*/
175+
release?: string;
176+
/**
177+
* @deprecated Use the `dsn` option in your runtime-specific Sentry.init() call in sentry.client.config.(js|ts) or sentry.server.config.(js|ts) instead.
178+
*/
179+
dsn?: string;
180+
/**
181+
* @deprecated Use the `sampleRate` option in your runtime-specific Sentry.init() call in sentry.client.config.(js|ts) or sentry.server.config.(js|ts) instead.
182+
*/
183+
sampleRate?: number;
184+
/**
185+
* @deprecated Use the `tracesSampleRate` option in your runtime-specific Sentry.init() call in sentry.client.config.(js|ts) or sentry.server.config.(js|ts) instead.
186+
*/
187+
tracesSampleRate?: number;
188+
/**
189+
* @deprecated Use the `replaysSessionSampleRate` option in your Sentry.init() call in sentry.client.config.(js|ts) instead.
190+
*/
191+
replaysSessionSampleRate?: number;
192+
/**
193+
* @deprecated Use the `replaysOnErrorSampleRate` option in your Sentry.init() call in sentry.client.config.(js|ts) instead.
194+
*/
195+
replaysOnErrorSampleRate?: number;
196+
};
197+
162198
/**
163199
* A subset of Sentry SDK options that can be set via the `sentryAstro` integration.
164200
* Some options (e.g. integrations) are set by default and cannot be changed here.
@@ -169,8 +205,7 @@ type SdkEnabledOptions = {
169205
* If you specify a dedicated init file, the SDK options passed to `sentryAstro` will be ignored.
170206
*/
171207
export type SentryOptions = SdkInitPaths &
172-
Pick<Options, 'dsn' | 'release' | 'environment' | 'sampleRate' | 'tracesSampleRate' | 'debug'> &
173-
Pick<BrowserOptions, 'replaysSessionSampleRate' | 'replaysOnErrorSampleRate'> &
208+
DeprecatedRuntimeOptions &
174209
InstrumentationOptions &
175210
SdkEnabledOptions & {
176211
/**
@@ -187,4 +222,8 @@ export type SentryOptions = SdkInitPaths &
187222
* Do not define them in the `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.
188223
*/
189224
bundleSizeOptimizations?: BundleSizeOptimizationOptions;
225+
/**
226+
* If enabled, prints debug logs during the build process.
227+
*/
228+
debug?: boolean;
190229
};

0 commit comments

Comments
 (0)