Skip to content

Conversation

@AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Jun 11, 2025

This PR adds two new options to the Express integration: ignoreLayers and ignoreLayersType, bringing it to feature parity with the underlying OpenTelemetry instrumentation.

resolves #16555

Changes

  • Added ignoreLayers option to ignore specific Express layers based on their path
  • Added ignoreLayersType option to ignore specific Express layers based on their type
  • Added comprehensive tests for both options
  • Updated JSDoc documentation with usage examples

Usage

Ignore layers by path

The ignoreLayers option accepts an array of elements that can be:

  • string for full match of the path
  • RegExp for partial match of the path
  • function in the form of (path) => boolean for custom logic
const Sentry = require('@sentry/node');

Sentry.init({
  integrations: [
    Sentry.expressIntegration({
      ignoreLayers: [
        '/health',              // Ignore exact path
        /^\/internal/,          // Ignore paths starting with /internal
        (path) => path.includes('admin') // Custom logic
      ]
    })
  ],
});

Ignore layers by type

The ignoreLayersType option accepts an array of the following strings:

  • router - for express.Router()
  • middleware - for middleware functions
  • request_handler - for request handlers (anything that's not a router or middleware)
const Sentry = require('@sentry/node');

Sentry.init({
  integrations: [
    Sentry.expressIntegration({
      ignoreLayersType: ['middleware'] // Ignore all middleware spans
    })
  ],
});

Combining both options

Both options can be used together:

const Sentry = require('@sentry/node');

Sentry.init({
  integrations: [
    Sentry.expressIntegration({
      ignoreLayers: ['/health', '/metrics', /^\/internal/],
      ignoreLayersType: ['middleware']
    })
  ],
});

@github-actions
Copy link
Contributor

github-actions bot commented Jun 11, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.88 kB - -
@sentry/browser - with treeshaking flags 22.35 kB - -
@sentry/browser (incl. Tracing) 39.75 kB - -
@sentry/browser (incl. Tracing, Replay) 77.88 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.61 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 82.58 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 94.68 kB - -
@sentry/browser (incl. Feedback) 40.58 kB - -
@sentry/browser (incl. sendFeedback) 28.56 kB - -
@sentry/browser (incl. FeedbackAsync) 33.46 kB - -
@sentry/react 25.61 kB - -
@sentry/react (incl. Tracing) 41.72 kB - -
@sentry/vue 28.31 kB - -
@sentry/vue (incl. Tracing) 41.53 kB - -
@sentry/svelte 23.9 kB - -
CDN Bundle 25.18 kB - -
CDN Bundle (incl. Tracing) 39.44 kB - -
CDN Bundle (incl. Tracing, Replay) 75.44 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 80.91 kB - -
CDN Bundle - uncompressed 73.54 kB - -
CDN Bundle (incl. Tracing) - uncompressed 116.99 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 231.18 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 243.99 kB - -
@sentry/nextjs (client) 43.32 kB - -
@sentry/sveltekit (client) 40.2 kB - -
@sentry/node 167.62 kB +0.02% +21 B 🔺
@sentry/node - without tracing 100.3 kB - -
@sentry/aws-serverless 128.41 kB - -

View base workflow run

@AbhiPrasad AbhiPrasad requested review from a team, s1gr1d and stephanie-anderson and removed request for a team June 11, 2025 18:06
@AbhiPrasad AbhiPrasad self-assigned this Jun 11, 2025
@AbhiPrasad AbhiPrasad marked this pull request as ready for review June 11, 2025 18:07
@AbhiPrasad AbhiPrasad marked this pull request as draft July 7, 2025 15:23
@eliliam
Copy link

eliliam commented Aug 12, 2025

Until this is merged, is there any workaround to disable the Express middlewares from the default list while keeping all other default middlewares?

@AbhiPrasad
Copy link
Member Author

@eliliam you can use our new ignoreSpans config introduced with 10.2.0: https://github.com/getsentry/sentry-javascript/releases/tag/10.2.0

@AbhiPrasad AbhiPrasad closed this Sep 10, 2025
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.

Update express integration to be able to ignore layers like router or middleware spans

4 participants