-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(astro): Add
enabled
option to Astro integration options (#10007)
Add a top level `enabled` option to the Astro integration options. This option can be used to globally enable/disable all Sentry features, either for client or server separately or for both sides simultaneously. * Disabeling either side will avoid the respective SDK code being injected into the bundles. * If both sides are disabled, source maps will not be generated and uploaded. * If both or just the server side is disabled, the Sentry middleware won't be added. * Obviously, this options defaults to `true`
- Loading branch information
Showing
3 changed files
with
122 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,14 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { | |
// Will revisit this later. | ||
const env = process.env; | ||
|
||
const uploadOptions = options.sourceMapsUploadOptions || {}; | ||
const sdkEnabled = { | ||
client: typeof options.enabled === 'boolean' ? options.enabled : options.enabled?.client ?? true, | ||
server: typeof options.enabled === 'boolean' ? options.enabled : options.enabled?.server ?? true, | ||
}; | ||
|
||
const shouldUploadSourcemaps = uploadOptions?.enabled ?? true; | ||
const sourceMapsNeeded = sdkEnabled.client || sdkEnabled.server; | ||
const uploadOptions = options.sourceMapsUploadOptions || {}; | ||
const shouldUploadSourcemaps = (sourceMapsNeeded && 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') { | ||
|
@@ -51,31 +56,35 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { | |
}); | ||
} | ||
|
||
const pathToClientInit = options.clientInitPath | ||
? path.resolve(options.clientInitPath) | ||
: findDefaultSdkInitFile('client'); | ||
const pathToServerInit = options.serverInitPath | ||
? path.resolve(options.serverInitPath) | ||
: findDefaultSdkInitFile('server'); | ||
|
||
if (pathToClientInit) { | ||
options.debug && console.log(`[sentry-astro] Using ${pathToClientInit} for client init.`); | ||
injectScript('page', buildSdkInitFileImportSnippet(pathToClientInit)); | ||
} else { | ||
options.debug && console.log('[sentry-astro] Using default client init.'); | ||
injectScript('page', buildClientSnippet(options || {})); | ||
if (sdkEnabled.client) { | ||
const pathToClientInit = options.clientInitPath | ||
? path.resolve(options.clientInitPath) | ||
: findDefaultSdkInitFile('client'); | ||
|
||
if (pathToClientInit) { | ||
options.debug && console.log(`[sentry-astro] Using ${pathToClientInit} for client init.`); | ||
injectScript('page', buildSdkInitFileImportSnippet(pathToClientInit)); | ||
} else { | ||
options.debug && console.log('[sentry-astro] Using default client init.'); | ||
injectScript('page', buildClientSnippet(options || {})); | ||
} | ||
} | ||
|
||
if (pathToServerInit) { | ||
options.debug && console.log(`[sentry-astro] Using ${pathToServerInit} for server init.`); | ||
injectScript('page-ssr', buildSdkInitFileImportSnippet(pathToServerInit)); | ||
} else { | ||
options.debug && console.log('[sentry-astro] Using default server init.'); | ||
injectScript('page-ssr', buildServerSnippet(options || {})); | ||
if (sdkEnabled.server) { | ||
const pathToServerInit = options.serverInitPath | ||
? path.resolve(options.serverInitPath) | ||
: findDefaultSdkInitFile('server'); | ||
if (pathToServerInit) { | ||
options.debug && console.log(`[sentry-astro] Using ${pathToServerInit} for server init.`); | ||
injectScript('page-ssr', buildSdkInitFileImportSnippet(pathToServerInit)); | ||
} else { | ||
options.debug && console.log('[sentry-astro] Using default server init.'); | ||
injectScript('page-ssr', buildServerSnippet(options || {})); | ||
} | ||
} | ||
|
||
const isSSR = config && (config.output === 'server' || config.output === 'hybrid'); | ||
const shouldAddMiddleware = options.autoInstrumentation?.requestHandler !== false; | ||
const shouldAddMiddleware = sdkEnabled.server && options.autoInstrumentation?.requestHandler !== false; | ||
|
||
// Guarding calling the addMiddleware function because it was only introduced in [email protected] | ||
// Users on older versions of astro will need to add the middleware manually. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters