Skip to content

feat(node): Add ignoreLayers and ignoreLayersType options to express instrumentation #16556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

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']
    })
  ],
});

Copy link
Contributor

github-actions bot commented Jun 11, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.99 kB - -
@sentry/browser - with treeshaking flags 23.76 kB - -
@sentry/browser (incl. Tracing) 38.69 kB - -
@sentry/browser (incl. Tracing, Replay) 76.78 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.87 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 81.54 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 93.6 kB - -
@sentry/browser (incl. Feedback) 40.73 kB - -
@sentry/browser (incl. sendFeedback) 28.7 kB - -
@sentry/browser (incl. FeedbackAsync) 33.59 kB - -
@sentry/react 25.76 kB - -
@sentry/react (incl. Tracing) 40.67 kB - -
@sentry/vue 28.36 kB - -
@sentry/vue (incl. Tracing) 40.55 kB - -
@sentry/svelte 24.01 kB - -
CDN Bundle 25.48 kB - -
CDN Bundle (incl. Tracing) 38.77 kB - -
CDN Bundle (incl. Tracing, Replay) 74.64 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 80.1 kB - -
CDN Bundle - uncompressed 74.48 kB - -
CDN Bundle (incl. Tracing) - uncompressed 114.89 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 228.86 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 241.69 kB - -
@sentry/nextjs (client) 42.33 kB - -
@sentry/sveltekit (client) 39.17 kB - -
@sentry/node 150.51 kB +0.03% +35 B 🔺
@sentry/node - without tracing 98.35 kB - -
@sentry/aws-serverless 124.11 kB - -

View base workflow run

@AbhiPrasad AbhiPrasad requested review from a team, stephanie-anderson and s1gr1d 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
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
2 participants