Skip to content

Conversation

@nicohrubec
Copy link
Member

@nicohrubec nicohrubec commented Jan 27, 2026

Depends on (i.e. do not review until the following PR is merged): #19001

This PR extends the autoInstrumentMiddleware option to support fine-grained control over which files are auto-instrumented. Previously, this option only supported a boolean setting. Now you can pass an object with an exclude array to selectively skip specific files from auto-instrumentation.

// vite.config.ts                                                                                                                                                                     
  import { sentryTanstackStart } from '@sentry/tanstackstart-react';                                                                                                                    
                                                                                                                                                                                        
  export default defineConfig({                                                                                                                                                         
    plugins: [                                                                                                                                                                          
      sentryTanstackStart({                                                                                                                                                             
        autoInstrumentMiddleware: {                                                                                                                                                     
          exclude: [                                                                                                                                                                                       
            /\.test\.tsx?$/,        // Skip test files                                                                                                                                  
          ],                                                                                                                                                                            
        },                                                                                                                                                                              
      }),                                                                                                                                                                               
    ],                                                                                                                                                                                  
  }); 

Closes #18985

@nicohrubec nicohrubec force-pushed the nh/ignore-files-from-auto-instrument branch from 2ca2145 to e0df795 Compare January 27, 2026 16:35
@nicohrubec nicohrubec force-pushed the nh/ignore-files-from-auto-instrument branch from e0df795 to e1276d9 Compare January 28, 2026 08:43
@nicohrubec nicohrubec force-pushed the nh/ignore-files-from-auto-instrument branch from e1276d9 to 864d5b0 Compare January 28, 2026 09:38
@nicohrubec nicohrubec marked this pull request as ready for review January 28, 2026 10:08
@github-actions
Copy link
Contributor

github-actions bot commented Jan 28, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,673 - 9,277 -7%
GET With Sentry 1,641 19% 1,793 -8%
GET With Sentry (error only) 6,045 70% 6,303 -4%
POST Baseline 1,173 - 1,199 -2%
POST With Sentry 569 49% 613 -7%
POST With Sentry (error only) 1,045 89% 1,064 -2%
MYSQL Baseline 3,324 - 3,382 -2%
MYSQL With Sentry 455 14% 507 -10%
MYSQL With Sentry (error only) 2,683 81% 2,727 -2%

View base workflow run

@nicohrubec nicohrubec self-assigned this Jan 30, 2026
@nicohrubec nicohrubec force-pushed the nh/ignore-files-from-auto-instrument branch from 86f5879 to 07f4f30 Compare January 30, 2026 12:14
@github-actions
Copy link
Contributor

github-actions bot commented Jan 30, 2026

Codecov Results 📊


Generated by Codecov Action

import type { Plugin } from 'vite';

type AutoInstrumentMiddlewareOptions = {
enabled?: boolean;
Copy link
Member Author

@nicohrubec nicohrubec Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an unnecessary option since we just don't add this plugin if it's not enabled, so I removed it

plugins.push(makeAutoInstrumentMiddlewarePlugin({ enabled: true, debug: options.debug }));
const autoInstrumentConfig = options.autoInstrumentMiddleware;
const isDisabled = autoInstrumentConfig === false;
const excludePatterns = typeof autoInstrumentConfig === 'object' ? autoInstrumentConfig.exclude : undefined;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The check typeof autoInstrumentConfig === 'object' is insufficient because typeof null is also 'object', which can cause a crash if autoInstrumentConfig is null.
Severity: MEDIUM

Suggested Fix

Update the conditional check to explicitly handle the null case by adding && autoInstrumentConfig !== null. The corrected line should be: const excludePatterns = typeof autoInstrumentConfig === 'object' && autoInstrumentConfig !== null ? autoInstrumentConfig.exclude : undefined;.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: packages/tanstackstart-react/src/vite/sentryTanstackStart.ts#L76

Potential issue: The code checks if `autoInstrumentConfig` is an object using `typeof
autoInstrumentConfig === 'object'`. However, in JavaScript, `typeof null` also evaluates
to `'object'`. If a user provides `null` for the `autoInstrumentMiddleware` option, for
instance through a dynamic JavaScript configuration, this check will pass. The
subsequent attempt to access `autoInstrumentConfig.exclude` will result in a `TypeError:
Cannot read property 'exclude' of null`, causing the Vite build process to crash. This
pattern is inconsistent with other parts of the codebase, which explicitly check for
`null` in similar situations.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

}) as PluginWithTransform;
const result = plugin.transform(createStartFile, '/app/routes/admin/start.ts');
expect(result).toBeNull();
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing integration or E2E tests for feat PR

Low Severity · Bugbot Rules

This feat PR adds the file exclude functionality for middleware auto-instrumentation but only includes unit tests. Per the review rules: "When reviewing a feat PR, check if the PR includes at least one integration or E2E test. If neither of the two are present, add a comment, recommending to add one." The existing E2E test suite at dev-packages/e2e-tests/test-applications/tanstackstart-react/ could be extended to verify the exclude patterns work correctly in a real build scenario.

Additional Locations (1)

Fix in Cursor Fix in Web

@nicohrubec nicohrubec requested a review from s1gr1d January 30, 2026 14:06
transform(code, id) {
if (!enabled) {
// Skip if not a TS/JS file
if (!/\.(ts|tsx|js|jsx|mjs|mts)$/.test(id)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: This was here before - still, maybe it makes more sense to have a path.extname(id) instead and check against this, it might be faster than regex or simply an endsWith (might be more effort, since this one only takes a string)

// file matches exclude patterns, skip
if (debug) {
// eslint-disable-next-line no-console
console.log(`[Sentry] Skipping auto-instrumentation for excluded file: ${id}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: I think this should be rather debug.log, where debug comes from @sentry/core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add configuration to exclude file patterns from middleware auto-instrumentation

3 participants