MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / sentryAstro

Function sentryAstro

packages/astro/src/integration/index.ts:12–251  ·  view source on GitHub ↗
(options: SentryOptions = {})

Source from the content-addressed store, hash-verified

10const PKG_NAME = '@sentry/astro';
11
12export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
13 return {
14 name: PKG_NAME,
15 hooks: {
16 // eslint-disable-next-line complexity
17 'astro:config:setup': async ({ updateConfig, injectScript, addMiddleware, config, command, logger }) => {
18 // The third param here enables loading of all env vars, regardless of prefix
19 // see: https://main.vitejs.dev/config/#using-environment-variables-in-config
20
21 // TODO: Ideally, we want to load the environment with vite like this:
22 // const env = loadEnv('production', process.cwd(), '');
23 // However, this currently throws a build error.
24 // Will revisit this later.
25 const env = process.env;
26
27 const {
28 enabled,
29 clientInitPath,
30 serverInitPath,
31 autoInstrumentation,
32 // eslint-disable-next-line typescript/no-deprecated
33 sourceMapsUploadOptions,
34 sourcemaps,
35 // todo(v11): Extract `release` build time option here - cannot be done currently, because it conflicts with the `DeprecatedRuntimeOptions` type
36 // release,
37 bundleSizeOptimizations,
38 applicationKey,
39 unstable_sentryVitePluginOptions,
40 debug,
41 org,
42 project,
43 authToken,
44 sentryUrl,
45 headers,
46 telemetry,
47 silent,
48 errorHandler,
49 ...deprecatedOptions
50 } = options;
51
52 const deprecatedOptionsKeys = Object.keys(deprecatedOptions);
53 if (deprecatedOptionsKeys.length > 0) {
54 logger.warn(
55 `You passed in additional options (${deprecatedOptionsKeys.join(
56 ', ',
57 )}) to the Sentry integration. This is deprecated and will stop working in a future version. Instead, configure the Sentry SDK in your \`sentry.client.config.(js|ts)\` or \`sentry.server.config.(js|ts)\` files.`,
58 );
59 }
60
61 const sdkEnabled = {
62 client: typeof enabled === 'boolean' ? enabled : (enabled?.client ?? true),
63 server: typeof enabled === 'boolean' ? enabled : (enabled?.server ?? true),
64 };
65
66 const sourceMapsNeeded = sdkEnabled.client || sdkEnabled.server;
67 // eslint-disable-next-line typescript/no-deprecated
68 const { unstable_sentryVitePluginOptions: deprecatedVitePluginOptions, ...uploadOptions } =
69 sourceMapsUploadOptions || {};

Callers 4

index.test.tsFile · 0.90
cloudflare.test.tsFile · 0.90

Calls 15

buildClientSnippetFunction · 0.90
buildServerSnippetFunction · 0.90
sentryVitePluginFunction · 0.85
getSourcemapsAssetsGlobFunction · 0.85
isCloudflarePagesFunction · 0.85
findDefaultSdkInitFileFunction · 0.70
keysMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected