From 8a4098ab469c31d86f18d6dc8a99139a735995fb Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Thu, 28 Nov 2024 11:16:40 +0100 Subject: [PATCH] feat(astro): Deprecate passing init options to sentry integration (#14489) --- docs/migration/draft-v9-migration-guide.md | 4 ++ packages/astro/src/integration/snippets.ts | 8 ++++ packages/astro/src/integration/types.ts | 43 +++++++++++++++++++++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/docs/migration/draft-v9-migration-guide.md b/docs/migration/draft-v9-migration-guide.md index 0d652449b025..7115fe6133d7 100644 --- a/docs/migration/draft-v9-migration-guide.md +++ b/docs/migration/draft-v9-migration-guide.md @@ -89,6 +89,10 @@ }); ``` +## `@sentry/astro` + +- Deprecated passing `dsn`, `release`, `environment`, `sampleRate`, `tracesSampleRate`, `replaysSessionSampleRate` to the integration. Use the runtime-specific `Sentry.init()` calls for passing these options instead. + ## `@sentry/remix` - Deprecated `autoInstrumentRemix: false`. The next major version will default to behaving as if this option were `true` and the option itself will be removed. diff --git a/packages/astro/src/integration/snippets.ts b/packages/astro/src/integration/snippets.ts index 4b784170d330..7ac05c163079 100644 --- a/packages/astro/src/integration/snippets.ts +++ b/packages/astro/src/integration/snippets.ts @@ -14,6 +14,7 @@ export function buildSdkInitFileImportSnippet(filePath: string): string { * default options. */ export function buildClientSnippet(options: SentryOptions): string { + /* eslint-disable deprecation/deprecation */ return `import * as Sentry from "@sentry/astro"; Sentry.init({ @@ -22,6 +23,7 @@ Sentry.init({ replaysSessionSampleRate: ${options.replaysSessionSampleRate ?? 0.1}, replaysOnErrorSampleRate: ${options.replaysOnErrorSampleRate ?? 1.0}, });`; + /* eslint-enable deprecation/deprecation */ } /** @@ -36,6 +38,7 @@ Sentry.init({ });`; } +/* eslint-disable deprecation/deprecation */ const buildCommonInitOptions = (options: SentryOptions): string => `dsn: ${ options.dsn ? JSON.stringify(options.dsn) : 'import.meta.env.PUBLIC_SENTRY_DSN' }, @@ -45,6 +48,7 @@ const buildCommonInitOptions = (options: SentryOptions): string => `dsn: ${ tracesSampleRate: ${options.tracesSampleRate ?? 1.0},${ options.sampleRate ? `\n sampleRate: ${options.sampleRate},` : '' }`; +/* eslint-enable deprecation/deprecation */ /** * We don't include the `BrowserTracing` integration if `bundleSizeOptimizations.excludeTracing` is falsy. @@ -61,9 +65,13 @@ const buildClientIntegrations = (options: SentryOptions): string => { } if ( + // eslint-disable-next-line deprecation/deprecation options.replaysSessionSampleRate == null || + // eslint-disable-next-line deprecation/deprecation options.replaysSessionSampleRate || + // eslint-disable-next-line deprecation/deprecation options.replaysOnErrorSampleRate == null || + // eslint-disable-next-line deprecation/deprecation options.replaysOnErrorSampleRate ) { integrations.push('Sentry.replayIntegration()'); diff --git a/packages/astro/src/integration/types.ts b/packages/astro/src/integration/types.ts index ede2f49ff732..fc523ced9cd0 100644 --- a/packages/astro/src/integration/types.ts +++ b/packages/astro/src/integration/types.ts @@ -150,6 +150,7 @@ type SdkEnabledOptions = { * Sentry code will be added to your bundle. * * @default true - the SDK is enabled by default for both, client and server. + * */ enabled?: | boolean @@ -159,6 +160,41 @@ type SdkEnabledOptions = { }; }; +type DeprecatedRuntimeOptions = Pick< + Options, + 'environment' | 'release' | 'dsn' | 'debug' | 'sampleRate' | 'tracesSampleRate' +> & + Pick & { + /** + * @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. + */ + environment?: string; + /** + * @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. + */ + release?: string; + /** + * @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. + */ + dsn?: string; + /** + * @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. + */ + sampleRate?: number; + /** + * @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. + */ + tracesSampleRate?: number; + /** + * @deprecated Use the `replaysSessionSampleRate` option in your Sentry.init() call in sentry.client.config.(js|ts) instead. + */ + replaysSessionSampleRate?: number; + /** + * @deprecated Use the `replaysOnErrorSampleRate` option in your Sentry.init() call in sentry.client.config.(js|ts) instead. + */ + replaysOnErrorSampleRate?: number; + }; + /** * 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. @@ -169,8 +205,7 @@ type SdkEnabledOptions = { * If you specify a dedicated init file, the SDK options passed to `sentryAstro` will be ignored. */ export type SentryOptions = SdkInitPaths & - Pick & - Pick & + DeprecatedRuntimeOptions & InstrumentationOptions & SdkEnabledOptions & { /** @@ -187,4 +222,8 @@ export type SentryOptions = SdkInitPaths & * Do not define them in the `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files. */ bundleSizeOptimizations?: BundleSizeOptimizationOptions; + /** + * If enabled, prints debug logs during the build process. + */ + debug?: boolean; };