Skip to content

Tracing integration with express erases router metadata #5050

Description

@jondot

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/node

SDK Version

6.19.7

Framework Version

6.19.7

Link to Sentry event

No response

Steps to Reproduce

Integrate sentry with an existing express app.
Use this to list routes:

importpathfrom'path'functiongetPathFromRegex(regexp){returnregexp.toString().replace('/^','').replace('?(?=\\/|$)/i','').replace(/\\\//g,'/')}functioncombineStacks(acc,stack){if(stack.handle.stack){constrouterPath=getPathFromRegex(stack.regexp)return[
...acc,
...stack.handle.stack.map((stack)=>({ routerPath, ...stack})),]}return[...acc,stack]}functiongetStacks(app){// Express 3if(app.routes){// convert to express 4returnObject.keys(app.routes).reduce((acc,method)=>[...acc, ...app.routes[method]],[]).map((route)=>({route: {stack: [route]}}))}// Express 4if(app._router&&app._router.stack){returnapp._router.stack.reduce(combineStacks,[])}// Express 4 Routerif(app.stack){returnapp.stack.reduce(combineStacks,[])}// Express 5if(app.router&&app.router.stack){returnapp.router.stack.reduce(combineStacks,[])}return[]}functionlistRoutes(app){conststacks=getStacks(app)constroutes=[]if(stacks){for(conststackofstacks){if(stack.route){constrouteLogged={}for(constrouteofstack.route.stack){constmethod=route.method ? route.method.toUpperCase() : nullif(!routeLogged[method]&&method){conststackPath=stack.routerPath||route.path
? path.resolve([stack.routerPath,stack.route.path,route.path].filter((s)=>!!s).join(''))
: stack.route.pathroutes.push({verb: method,path: stackPath})routeLogged[method]=true}}}}}returnroutes}exportdefaultlistRoutes

Expected Result

routes listed and returned

Actual Result

after integration with Sentry, all route information disappears.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions