Skip to content

Sentry throws error when passing routes as Express middleware ( use ) #9360

Closed
@etarhan

Description

@etarhan

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

7.74.1

Framework Version

Node v18.16.1, Express v4.18.2

Link to Sentry event

https://capdesk-org.sentry.io/issues/4568059536

SDK Setup

  Sentry.init({
    dsn: SENTRY_DSN,
    integrations: [
      new Sentry.Integrations.Http({ tracing: true }),
      new Sentry.Integrations.Express({
        app,
      }),
    ],
    environment: ENV,
    ignoreErrors: [],
  })

Steps to Reproduce

  1. When you provides routes to app.use, like so:
app.use(routes, frontendHandler)

With the frontendHandler basically serving static assets:

express.static(path.join(__dirname, '../../build'))
  1. And request any frontend route

Expected Result

Routes are served normally.

Actual Result

The following error gets thrown, crashing the express server:

TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at /Users/username/Code/reponame/node_modules/@sentry-internal/src/node/integrations/express.ts:439:1
    at Array.forEach (<anonymous>)
    at extractOriginalRoute (/Users/username/Code/reponame/node_modules/@sentry-internal/src/node/integrations/express.ts:439:1)
    at getLayerRoutePathInfo (/Users/username/Code/reponame/node_modules/@sentry-internal/tracing/cjs/node/integrations/express.js:409:13)
    at Function.process_params (/Users/username/Code/reponame/node_modules/@sentry-internal/src/node/integrations/express.ts:316:1)
    at next (/Users/username/Code/reponame/node_modules/express/lib/router/index.js:280:10)
    at Function.handle (/Users/username/Code/reponame/node_modules/express/lib/router/index.js:175:3)
    at router (/Users/username/Code/reponame/node_modules/express/lib/router/index.js:47:12)
    at /Users/username/Code/reponame/node_modules/@sentry-internal/src/node/integrations/express.ts:183:1
    at Layer.handle [as handle_request] (/Users/username/Code/reponame/node_modules/express/lib/router/layer.js:95:5)

Seems related to this commit. Using app.all instead works correctly, like so:

app.all(routes, frontendHandler)

Problem is that using all and use aren't exactly equivalent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nodeIssues related to the Sentry Node SDK

    Type

    No type

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions