Skip to content

Commit f7bdc4c

Browse files
authored
feat(core): Add applicationKey to BuildTimeOptionsBase (#20789)
Adds a top-level `applicationKey` option to the shared `BuildTimeOptionsBase` interface, so users can configure `thirdPartyErrorFilterIntegration` without needing `unstable_*` escape hatches. Wires up forwarding in: - React Router - SvelteKit - Astro - Nuxt Will do Next.js in a follow up as this does not implement the interface closes #17384
1 parent e2b9cda commit f7bdc4c

10 files changed

Lines changed: 81 additions & 0 deletions

File tree

packages/astro/src/integration/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
3535
// todo(v11): Extract `release` build time option here - cannot be done currently, because it conflicts with the `DeprecatedRuntimeOptions` type
3636
// release,
3737
bundleSizeOptimizations,
38+
applicationKey,
3839
unstable_sentryVitePluginOptions,
3940
debug,
4041
org,
@@ -109,6 +110,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
109110
},
110111
plugins: [
111112
sentryVitePlugin({
113+
applicationKey,
112114
// Priority: top-level options > deprecated options > env vars
113115
// eslint-disable-next-line deprecation/deprecation
114116
org: org ?? uploadOptions.org ?? env.SENTRY_ORG,

packages/astro/test/integration/index.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,21 @@ describe('sentryAstro integration', () => {
269269
);
270270
});
271271

272+
it('passes top-level applicationKey to the vite plugin', async () => {
273+
const integration = sentryAstro({
274+
applicationKey: 'my-app-key',
275+
sourceMapsUploadOptions: { enabled: true, org: 'my-org', project: 'my-project' },
276+
});
277+
// @ts-expect-error - the hook exists and we only need to pass what we actually use
278+
await integration.hooks['astro:config:setup']({ ...baseConfigHookObject, updateConfig, injectScript, config });
279+
280+
expect(sentryVitePluginSpy).toHaveBeenCalledWith(
281+
expect.objectContaining({
282+
applicationKey: 'my-app-key',
283+
}),
284+
);
285+
});
286+
272287
it("doesn't enable source maps if `sourceMapsUploadOptions.enabled` is `false`", async () => {
273288
const integration = sentryAstro({
274289
sourceMapsUploadOptions: { enabled: false },

packages/core/src/build-time-plugins/buildTimeOptionsBase.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ export interface BuildTimeOptionsBase {
125125
* Options for bundle size optimizations by excluding certain features of the Sentry SDK.
126126
*/
127127
bundleSizeOptimizations?: BundleSizeOptimizationsOptions;
128+
129+
/**
130+
* A key that is used to identify the application in the Sentry bundler plugins.
131+
* This key is used by the `thirdPartyErrorFilterIntegration` to filter out errors
132+
* originating from third-party scripts.
133+
*
134+
* @see https://docs.sentry.io/platforms/javascript/configuration/filtering/#using-thirdpartyerrorfilterintegration
135+
*/
136+
applicationKey?: string;
128137
}
129138

130139
/**

packages/nuxt/src/vite/sourceMaps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export function getPluginOptions(
171171
}
172172

173173
return {
174+
applicationKey: moduleOptions.applicationKey,
174175
// eslint-disable-next-line deprecation/deprecation
175176
org: moduleOptions.org ?? sourceMapsUploadOptions.org ?? process.env.SENTRY_ORG,
176177
// eslint-disable-next-line deprecation/deprecation

packages/nuxt/test/vite/sourceMaps.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ describe('getPluginOptions', () => {
231231
});
232232
});
233233

234+
it('passes applicationKey to plugin options', () => {
235+
const options: SentryNuxtModuleOptions = {
236+
applicationKey: 'my-app-key',
237+
};
238+
239+
const result = getPluginOptions(options);
240+
241+
expect(result).toMatchObject({
242+
applicationKey: 'my-app-key',
243+
});
244+
});
245+
234246
it('supports bundleSizeOptimizations', () => {
235247
const options: SentryNuxtModuleOptions = {
236248
bundleSizeOptimizations: {

packages/react-router/src/vite/makeCustomSentryVitePlugins.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export async function makeCustomSentryVitePlugins(options: SentryReactRouterBuil
1010
debug,
1111
unstable_sentryVitePluginOptions,
1212
bundleSizeOptimizations,
13+
applicationKey,
1314
authToken,
1415
org,
1516
project,
@@ -19,6 +20,7 @@ export async function makeCustomSentryVitePlugins(options: SentryReactRouterBuil
1920
} = options;
2021

2122
const sentryVitePlugins = sentryVitePlugin({
23+
applicationKey,
2224
authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN,
2325
bundleSizeOptimizations,
2426
debug: debug ?? false,

packages/react-router/test/vite/makeCustomSentryVitePlugins.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ describe('makeCustomSentryVitePlugins', () => {
4848
);
4949
});
5050

51+
it('should pass applicationKey to sentryVitePlugin', async () => {
52+
await makeCustomSentryVitePlugins({
53+
applicationKey: 'my-app-key',
54+
});
55+
56+
expect(sentryVitePlugin).toHaveBeenCalledWith(
57+
expect.objectContaining({
58+
applicationKey: 'my-app-key',
59+
}),
60+
);
61+
});
62+
5163
it('should return all plugins from sentryVitePlugin', async () => {
5264
const plugins = await makeCustomSentryVitePlugins({});
5365
expect(plugins).toHaveLength(1);

packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,20 @@ describe('generateVitePluginOptions', () => {
207207
expect(result).toBeNull();
208208
});
209209

210+
it('passes applicationKey through to vite plugin options', () => {
211+
const originalEnv = process.env.NODE_ENV;
212+
process.env.NODE_ENV = 'production';
213+
214+
const options: SentrySvelteKitPluginOptions = {
215+
autoUploadSourceMaps: true,
216+
applicationKey: 'my-app-key',
217+
};
218+
const result = generateVitePluginOptions(options);
219+
expect(result).toEqual(expect.objectContaining({ applicationKey: 'my-app-key' }));
220+
221+
process.env.NODE_ENV = originalEnv;
222+
});
223+
210224
it('uses default `debug` value if only default options are provided', () => {
211225
const originalEnv = process.env.NODE_ENV;
212226
process.env.NODE_ENV = 'production'; // Ensure we're not in development mode

packages/tanstackstart-react/src/vite/sourceMaps.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type FilesToDeleteAfterUpload = string | string[] | undefined;
99
*/
1010
export function makeAddSentryVitePlugin(options: BuildTimeOptionsBase): Plugin[] {
1111
const {
12+
applicationKey,
1213
authToken,
1314
bundleSizeOptimizations,
1415
debug,
@@ -52,6 +53,7 @@ export function makeAddSentryVitePlugin(options: BuildTimeOptionsBase): Plugin[]
5253
};
5354

5455
const sentryPlugins = sentryVitePlugin({
56+
applicationKey,
5557
authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN,
5658
bundleSizeOptimizations: bundleSizeOptimizations ?? undefined,
5759
debug: debug ?? false,

packages/tanstackstart-react/test/vite/sourceMaps.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ describe('makeAddSentryVitePlugin()', () => {
9898
);
9999
});
100100

101+
it('passes applicationKey to sentryVitePlugin', () => {
102+
makeAddSentryVitePlugin({
103+
applicationKey: 'my-app-key',
104+
});
105+
106+
expect(sentryVitePluginSpy).toHaveBeenCalledWith(
107+
expect.objectContaining({
108+
applicationKey: 'my-app-key',
109+
}),
110+
);
111+
});
112+
101113
it('returns Sentry Vite plugins and config plugin', () => {
102114
const plugins = makeAddSentryVitePlugin({
103115
org: 'my-org',

0 commit comments

Comments
 (0)