Skip to content

feat(astro): Align options with shared build time options type #17396

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/astro/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
{
files: ['vite.config.ts'],
parserOptions: {
project: ['tsconfig.test.json'],
project: ['tsconfig.vite.json'],
},
},
],
Expand Down
58 changes: 46 additions & 12 deletions packages/astro/src/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
clientInitPath,
serverInitPath,
autoInstrumentation,
// eslint-disable-next-line deprecation/deprecation
sourceMapsUploadOptions,
sourcemaps,
// todo(v11): Extract `release` build time option here - cannot be done currently, because it conflicts with the `DeprecatedRuntimeOptions` type
// release,
bundleSizeOptimizations,
unstable_sentryVitePluginOptions,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Sentry Vite Plugin Misinterprets Configuration Options

New top-level build-time options (e.g., org, project, authToken, sentryUrl, headers, telemetry, silent, errorHandler) are not destructured from the options object. This causes them to be incorrectly included in otherOptions, triggering a deprecation warning for 'additional options'. As a result, misleading warnings appear in production builds, despite these options being valid and used for Sentry Vite plugin configuration.

Fix in Cursor Fix in Web

debug,
...otherOptions
} = options;
Expand All @@ -48,8 +53,21 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
};

const sourceMapsNeeded = sdkEnabled.client || sdkEnabled.server;
const { unstable_sentryVitePluginOptions, ...uploadOptions } = sourceMapsUploadOptions || {};
const shouldUploadSourcemaps = (sourceMapsNeeded && uploadOptions?.enabled) ?? true;
// eslint-disable-next-line deprecation/deprecation
const { unstable_sentryVitePluginOptions: deprecatedVitePluginOptions, ...uploadOptions } =
sourceMapsUploadOptions || {};

const unstableMerged_sentryVitePluginOptions = {
...deprecatedVitePluginOptions,
...unstable_sentryVitePluginOptions,
};

const shouldUploadSourcemaps =
(sourceMapsNeeded &&
sourcemaps?.disable !== true &&
// eslint-disable-next-line deprecation/deprecation
uploadOptions?.enabled) ??
true;

// We don't need to check for AUTH_TOKEN here, because the plugin will pick it up from the env
if (shouldUploadSourcemaps && command !== 'dev') {
Expand All @@ -58,7 +76,9 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
let updatedFilesToDeleteAfterUpload: string[] | undefined = undefined;

if (
// eslint-disable-next-line deprecation/deprecation
typeof uploadOptions?.filesToDeleteAfterUpload === 'undefined' &&
typeof sourcemaps?.filesToDeleteAfterUpload === 'undefined' &&
computedSourceMapSettings.previousUserSourceMapSetting === 'unset'
) {
// This also works for adapters, as the source maps are also copied to e.g. the .vercel folder
Expand All @@ -79,26 +99,40 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
},
plugins: [
sentryVitePlugin({
org: uploadOptions.org ?? env.SENTRY_ORG,
project: uploadOptions.project ?? env.SENTRY_PROJECT,
authToken: uploadOptions.authToken ?? env.SENTRY_AUTH_TOKEN,
telemetry: uploadOptions.telemetry ?? true,
// Priority: top-level options > deprecated options > env vars
// eslint-disable-next-line deprecation/deprecation
org: options.org ?? uploadOptions.org ?? env.SENTRY_ORG,
// eslint-disable-next-line deprecation/deprecation
project: options.project ?? uploadOptions.project ?? env.SENTRY_PROJECT,
// eslint-disable-next-line deprecation/deprecation
authToken: options.authToken ?? uploadOptions.authToken ?? env.SENTRY_AUTH_TOKEN,
url: options.sentryUrl ?? env.SENTRY_URL,
headers: options.headers,
// eslint-disable-next-line deprecation/deprecation
telemetry: options.telemetry ?? uploadOptions.telemetry ?? true,
silent: options.silent ?? false,
errorHandler: options.errorHandler,
_metaOptions: {
telemetry: {
metaFramework: 'astro',
},
},
...unstable_sentryVitePluginOptions,
debug: debug ?? false,
...unstableMerged_sentryVitePluginOptions,
debug: options.debug ?? false,
sourcemaps: {
assets: uploadOptions.assets ?? [getSourcemapsAssetsGlob(config)],
...options.sourcemaps,
// eslint-disable-next-line deprecation/deprecation
assets: sourcemaps?.assets ?? uploadOptions.assets ?? [getSourcemapsAssetsGlob(config)],
filesToDeleteAfterUpload:
uploadOptions?.filesToDeleteAfterUpload ?? updatedFilesToDeleteAfterUpload,
...unstable_sentryVitePluginOptions?.sourcemaps,
sourcemaps?.filesToDeleteAfterUpload ??
// eslint-disable-next-line deprecation/deprecation
uploadOptions?.filesToDeleteAfterUpload ??
updatedFilesToDeleteAfterUpload,
...unstableMerged_sentryVitePluginOptions?.sourcemaps,
},
bundleSizeOptimizations: {
...bundleSizeOptimizations,
...unstable_sentryVitePluginOptions?.bundleSizeOptimizations,
...unstableMerged_sentryVitePluginOptions?.bundleSizeOptimizations,
},
}),
],
Expand Down
79 changes: 26 additions & 53 deletions packages/astro/src/integration/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { BuildTimeOptionsBase, UnstableVitePluginOptions } from '@sentry/core';
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';
import type { RouteData } from 'astro';

Expand All @@ -23,12 +24,16 @@ type SdkInitPaths = {
serverInitPath?: string;
};

/**
* @deprecated Move these options to the top-level of your Sentry configuration.
*/
type SourceMapsOptions = {
/**
* If this flag is `true`, and an auth token is detected, the Sentry integration will
* automatically generate and upload source maps to Sentry during a production build.
*
* @default true
* @deprecated Use `sourcemaps.disable` instead (with inverted logic)
*/
enabled?: boolean;

Expand All @@ -39,18 +44,24 @@ type SourceMapsOptions = {
*
* To create an auth token, follow this guide:
* @see https://docs.sentry.io/product/accounts/auth-tokens/#organization-auth-tokens
*
* @deprecated Use top-level `authToken` option instead
*/
authToken?: string;

/**
* The organization slug of your Sentry organization.
* Instead of specifying this option, you can also set the `SENTRY_ORG` environment variable.
*
* @deprecated Use top-level `org` option instead
*/
org?: string;

/**
* The project slug of your Sentry project.
* Instead of specifying this option, you can also set the `SENTRY_PROJECT` environment variable.
*
* @deprecated Use top-level `project` option instead
*/
project?: string;

Expand All @@ -59,6 +70,7 @@ type SourceMapsOptions = {
* It will not collect any sensitive or user-specific data.
*
* @default true
* @deprecated Use top-level `telemetry` option instead
*/
telemetry?: boolean;

Expand All @@ -71,6 +83,8 @@ type SourceMapsOptions = {
*
* The globbing patterns must follow the implementation of the `glob` package.
* @see https://www.npmjs.com/package/glob#glob-primer
*
* @deprecated Use `sourcemaps.assets` instead
*/
assets?: string | Array<string>;

Expand All @@ -81,6 +95,8 @@ type SourceMapsOptions = {
* @default [] - By default no files are deleted.
*
* The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob)
*
* @deprecated Use `sourcemaps.filesToDeleteAfterUpload` instead
*/
filesToDeleteAfterUpload?: string | Array<string>;

Expand All @@ -95,49 +111,10 @@ type SourceMapsOptions = {
* changes can occur at any time within a major SDK version.
*
* Furthermore, some options are untested with Astro specifically. Use with caution.
*/
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>;
};

type BundleSizeOptimizationOptions = {
/**
* If set to `true`, the plugin will attempt to tree-shake (remove) any debugging code within the Sentry SDK.
* Note that the success of this depends on tree shaking being enabled in your build tooling.
*
* Setting this option to `true` will disable features like the SDK's `debug` option.
*/
excludeDebugStatements?: boolean;

/**
* If set to true, the plugin will try to tree-shake performance monitoring statements out.
* Note that the success of this depends on tree shaking generally being enabled in your build.
* Attention: DO NOT enable this when you're using any performance monitoring-related SDK features (e.g. Sentry.startSpan()).
*/
excludeTracing?: boolean;

/**
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay Shadow DOM recording functionality.
* Note that the success of this depends on tree shaking being enabled in your build tooling.
*
* This option is safe to be used when you do not want to capture any Shadow DOM activity via Sentry Session Replay.
* @deprecated Use top-level `unstable_sentryVitePluginOptions` instead
*/
excludeReplayShadowDom?: boolean;

/**
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay `iframe` recording functionality.
* Note that the success of this depends on tree shaking being enabled in your build tooling.
*
* You can safely do this when you do not want to capture any `iframe` activity via Sentry Session Replay.
*/
excludeReplayIframe?: boolean;

/**
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay's Compression Web Worker.
* Note that the success of this depends on tree shaking being enabled in your build tooling.
*
* **Notice:** You should only do use this option if you manually host a compression worker and configure it in your Sentry Session Replay integration config via the `workerUrl` option.
*/
excludeReplayWorker?: boolean;
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>;
};

type InstrumentationOptions = {
Expand Down Expand Up @@ -202,27 +179,23 @@ type DeprecatedRuntimeOptions = Record<string, unknown>;
*
* If you specify a dedicated init file, the SDK options passed to `sentryAstro` will be ignored.
*/
export type SentryOptions = SdkInitPaths &
export type SentryOptions = Omit<BuildTimeOptionsBase, 'release'> &
// todo(v11): `release` and `debug` need to be removed from BuildTimeOptionsBase as it is currently conflicting with `DeprecatedRuntimeOptions`
UnstableVitePluginOptions<SentryVitePluginOptions> &
SdkInitPaths &
InstrumentationOptions &
SdkEnabledOptions & {
/**
* Options for the Sentry Vite plugin to customize the source maps upload process.
*
* These options are always read from the `sentryAstro` integration.
* Do not define them in the `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.
*/
sourceMapsUploadOptions?: SourceMapsOptions;
/**
* Options for the Sentry Vite plugin to customize bundle size optimizations.
*
* These options are always read from the `sentryAstro` integration.
* Do not define them in the `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.
* @deprecated This option was deprecated. Please move the options to the top-level configuration.
* See the migration guide in the SourceMapsOptions type documentation.
*/
bundleSizeOptimizations?: BundleSizeOptimizationOptions;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I confused or did this disappear with the changes? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of the shared type so it's possible to delete it here :)

bundleSizeOptimizations?: BundleSizeOptimizationsOptions;

/**
* If enabled, prints debug logs during the build process.
*/
debug?: boolean;
// eslint-disable-next-line deprecation/deprecation
sourceMapsUploadOptions?: SourceMapsOptions;
// eslint-disable-next-line deprecation/deprecation
} & DeprecatedRuntimeOptions;

Expand Down
Loading
Loading