Skip to content

feat(astro): Deprecate passing init options to sentry integration #14489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/migration/draft-v9-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions packages/astro/src/integration/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -22,6 +23,7 @@ Sentry.init({
replaysSessionSampleRate: ${options.replaysSessionSampleRate ?? 0.1},
replaysOnErrorSampleRate: ${options.replaysOnErrorSampleRate ?? 1.0},
});`;
/* eslint-enable deprecation/deprecation */
}

/**
Expand All @@ -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'
},
Expand All @@ -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.
Expand All @@ -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()');
Expand Down
43 changes: 41 additions & 2 deletions packages/astro/src/integration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -159,6 +160,41 @@ type SdkEnabledOptions = {
};
};

type DeprecatedRuntimeOptions = Pick<
Options,
'environment' | 'release' | 'dsn' | 'debug' | 'sampleRate' | 'tracesSampleRate'
> &
Pick<BrowserOptions, 'replaysSessionSampleRate' | 'replaysOnErrorSampleRate'> & {
/**
* @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.
Expand All @@ -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<Options, 'dsn' | 'release' | 'environment' | 'sampleRate' | 'tracesSampleRate' | 'debug'> &
Pick<BrowserOptions, 'replaysSessionSampleRate' | 'replaysOnErrorSampleRate'> &
DeprecatedRuntimeOptions &
InstrumentationOptions &
SdkEnabledOptions & {
/**
Expand All @@ -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;
};
Loading