Skip to content
Draft
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
7 changes: 6 additions & 1 deletion packages/tanstackstart-react/src/vite/sentryTanstackStart.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { BuildTimeOptionsBase } from '@sentry/core';
import type { Plugin } from 'vite';
import { makeAutoInstrumentMiddlewarePlugin } from './autoInstrumentMiddleware';
import { makeAddSentryVitePlugin, makeEnableSourceMapsVitePlugin } from './sourceMaps';
import {
makeAddSentryVitePlugin,
makeEnableSourceMapsVitePlugin,
makeNitroSourcemapExcludeSourcesPlugin,
} from './sourceMaps';

/**
* Build-time options for the Sentry TanStack Start SDK.
Expand Down Expand Up @@ -62,6 +66,7 @@ export function sentryTanstackStart(options: SentryTanstackStartOptions = {}): P
const sourceMapsDisabled = options.sourcemaps?.disable === true || options.sourcemaps?.disable === 'disable-upload';
if (!sourceMapsDisabled) {
plugins.push(...makeEnableSourceMapsVitePlugin(options));
plugins.push(makeNitroSourcemapExcludeSourcesPlugin(options));
}

return plugins;
Expand Down
25 changes: 25 additions & 0 deletions packages/tanstackstart-react/src/vite/sourceMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ export function makeEnableSourceMapsVitePlugin(options: BuildTimeOptionsBase): P
];
}

/**
* A Sentry plugin for TanStack Start to set `sourcemapExcludeSources: false` in the Nitro config.
*
* By default, Nitro sets `sourcemapExcludeSources: true`, which means the original source code is not included
* in the source maps. This makes it impossible for Sentry to display un-minified code snippets on the Issues page.
*/
export function makeNitroSourcemapExcludeSourcesPlugin(_options: BuildTimeOptionsBase): Plugin {
return {
name: 'sentry-tanstackstart-nitro-sourcemap-exclude-sources',
apply: 'build',
enforce: 'post',
config() {
return {
nitro: {
rollupConfig: {
output: {
sourcemapExcludeSources: false,
},
},
},
} as UserConfig;
},
};
}

/** There are 3 ways to set up source map generation (https://github.com/getsentry/sentry-javascript/issues/13993)
*
* 1. User explicitly disabled source maps
Expand Down
22 changes: 20 additions & 2 deletions packages/tanstackstart-react/test/vite/sentryTanstackStart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ const mockEnableSourceMapsPlugin: Plugin = {
config: vi.fn(),
};

const mockNitroSourcemapExcludeSourcesPlugin: Plugin = {
name: 'sentry-tanstackstart-nitro-sourcemap-exclude-sources',
apply: 'build',
enforce: 'post',
config: vi.fn(),
};

const mockMiddlewarePlugin: Plugin = {
name: 'sentry-tanstack-middleware-auto-instrument',
apply: 'build',
Expand All @@ -31,6 +38,7 @@ const mockMiddlewarePlugin: Plugin = {
vi.mock('../../src/vite/sourceMaps', () => ({
makeAddSentryVitePlugin: vi.fn(() => [mockSourceMapsConfigPlugin, mockSentryVitePlugin]),
makeEnableSourceMapsVitePlugin: vi.fn(() => [mockEnableSourceMapsPlugin]),
makeNitroSourcemapExcludeSourcesPlugin: vi.fn(() => mockNitroSourcemapExcludeSourcesPlugin),
}));

vi.mock('../../src/vite/autoInstrumentMiddleware', () => ({
Expand All @@ -51,7 +59,12 @@ describe('sentryTanstackStart()', () => {
it('returns source maps plugins in production mode', () => {
const plugins = sentryTanstackStart({ autoInstrumentMiddleware: false });

expect(plugins).toEqual([mockSourceMapsConfigPlugin, mockSentryVitePlugin, mockEnableSourceMapsPlugin]);
expect(plugins).toEqual([
mockSourceMapsConfigPlugin,
mockSentryVitePlugin,
mockEnableSourceMapsPlugin,
mockNitroSourcemapExcludeSourcesPlugin,
]);
});

it('returns no plugins in development mode', () => {
Expand Down Expand Up @@ -86,7 +99,12 @@ describe('sentryTanstackStart()', () => {
sourcemaps: { disable: false },
});

expect(plugins).toEqual([mockSourceMapsConfigPlugin, mockSentryVitePlugin, mockEnableSourceMapsPlugin]);
expect(plugins).toEqual([
mockSourceMapsConfigPlugin,
mockSentryVitePlugin,
mockEnableSourceMapsPlugin,
mockNitroSourcemapExcludeSourcesPlugin,
]);
});
});

Expand Down
Loading