Skip to content

Commit 6ed2b20

Browse files
committed
new sourcemaps API
1 parent bbeece8 commit 6ed2b20

File tree

2 files changed

+71
-13
lines changed

2 files changed

+71
-13
lines changed

packages/astro/src/integration/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,23 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
1919
// see: https://main.vitejs.dev/config/#using-environment-variables-in-config
2020
const env = loadEnv('production', process.cwd(), '');
2121

22-
if (options.authToken ?? env.SENTRY_AUTH_TOKEN) {
22+
const uploadOptions = options.sourceMapsUploadOptions || {};
23+
24+
const shouldUploadSourcemaps = uploadOptions?.enabled ?? true;
25+
const authToken = uploadOptions.authToken || env.SENTRY_AUTH_TOKEN;
26+
27+
if (shouldUploadSourcemaps && authToken) {
2328
updateConfig({
2429
vite: {
2530
build: {
2631
sourcemap: true,
2732
},
2833
plugins: [
2934
sentryVitePlugin({
30-
org: options.org ?? env.SENTRY_ORG,
31-
project: options.project ?? env.SENTRY_PROJECT,
32-
authToken: options.authToken ?? env.SENTRY_AUTH_TOKEN,
33-
telemetry: options.telemetry,
35+
org: uploadOptions.org ?? env.SENTRY_ORG,
36+
project: uploadOptions.project ?? env.SENTRY_PROJECT,
37+
authToken: uploadOptions.authToken ?? env.SENTRY_AUTH_TOKEN,
38+
telemetry: uploadOptions.telemetry ?? true,
3439
}),
3540
],
3641
},
@@ -52,7 +57,6 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
5257
options.debug && console.log(`[sentry-astro] Using ${pathToServerInit} for server init.`);
5358
// For whatever reason, we need to move one level up to import the server file correctly
5459
injectScript('page-ssr', buildSdkInitFileImportSnippet(path.join('..', pathToServerInit)));
55-
} else {
5660
options.debug && console.log('[sentry-astro] Using default server init.');
5761
injectScript('page-ssr', buildServerSnippet(options || {}));
5862
}
Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,76 @@
11
import type { BrowserOptions } from '@sentry/browser';
22
import type { Options } from '@sentry/types';
3-
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';
43

54
type SdkInitPaths = {
65
/**
76
* Path to a `sentry.client.config.(js|ts)` file that contains a `Sentry.init` call.
8-
* If this option is not specified, the default location (`src/sentry.client.config.(js|ts)`) will be used.
9-
* If there is no file at the default location, a default `Sentry.init` call will made.
7+
*
8+
* If this option is not specified, the default location (`<projectRoot>/sentry.client.config.(js|ts)`)
9+
* will be used to look up the config file.
10+
* If there is no file at the default location either, the SDK will initalize with the options
11+
* specified in the `sentryAstro` integration or with default options.
1012
*/
1113
clientInitPath?: string;
14+
1215
/**
13-
* Path to a `sentry.client.config.(js|ts)` file that contains a `Sentry.init` call.
14-
* If this option is not specified, the default location (`src/sentry.client.config.(js|ts)`) will be used.
15-
* If there is no file at the default location, a default `Sentry.init` call will made.
16+
* Path to a `sentry.server.config.(js|ts)` file that contains a `Sentry.init` call.
17+
*
18+
* If this option is not specified, the default location (`<projectRoot>/sentry.server.config.(js|ts)`)
19+
* will be used to look up the config file.
20+
* If there is no file at the default location either, the SDK will initalize with the options
21+
* specified in the `sentryAstro` integration or with default options.
1622
*/
1723
serverInitPath?: string;
1824
};
1925

26+
type SourceMapsOptions = {
27+
/**
28+
* Options for the Sentry Vite plugin to customize the source maps upload process.
29+
*
30+
* These options are always read from the `sentryAstro` integration.
31+
* Do not define them in the `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.
32+
*/
33+
sourceMapsUploadOptions?: {
34+
/**
35+
* If this flag is `true`, and an auth token is detected, the Sentry integration will
36+
* automatically generate and upload source maps to Sentry during a production build.
37+
*
38+
* @default true
39+
*/
40+
enabled?: boolean;
41+
42+
/**
43+
* The auth token to use when uploading source maps to Sentry.
44+
*
45+
* Instead of specifying this option, you can also set the `SENTRY_AUTH_TOKEN` environment variable.
46+
*
47+
* To create an auth token, follow this guide:
48+
* @see https://docs.sentry.io/product/accounts/auth-tokens/#organization-auth-tokens
49+
*/
50+
authToken?: string;
51+
52+
/**
53+
* The organization slug of your Sentry organization.
54+
* Instead of specifying this option, you can also set the `SENTRY_ORG` environment variable.
55+
*/
56+
org?: string;
57+
58+
/**
59+
* The project slug of your Sentry project.
60+
* Instead of specifying this option, you can also set the `SENTRY_PROJECT` environment variable.
61+
*/
62+
project?: string;
63+
64+
/**
65+
* If this flag is `true`, the Sentry plugin will collect some telemetry data and send it to Sentry.
66+
* It will not collect any sensitive or user-specific data.
67+
*
68+
* @default true
69+
*/
70+
telemetry?: boolean;
71+
};
72+
};
73+
2074
/**
2175
* A subset of Sentry SDK options that can be set via the `sentryAstro` integration.
2276
* Some options (e.g. integrations) are set by default and cannot be changed here.
@@ -29,4 +83,4 @@ type SdkInitPaths = {
2983
export type SentryOptions = SdkInitPaths &
3084
Pick<Options, 'dsn' | 'release' | 'environment' | 'sampleRate' | 'tracesSampleRate' | 'debug'> &
3185
Pick<BrowserOptions, 'replaysSessionSampleRate' | 'replaysOnErrorSampleRate'> &
32-
Pick<SentryVitePluginOptions, 'authToken' | 'org' | 'project' | 'telemetry'>;
86+
SourceMapsOptions;

0 commit comments

Comments
 (0)