Title: Tracing integration with express erases router metadata · Issue #5050 · getsentry/sentry-javascript · GitHub
Open Graph Title: Tracing integration with express erases router metadata · Issue #5050 · getsentry/sentry-javascript
X Title: Tracing integration with express erases router metadata · Issue #5050 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/5050
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Tracing integration with express erases router metadata","articleBody":"### Is there an existing issue for this?\n\n- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [X] I have reviewed the documentation https://docs.sentry.io/\n- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which package are you using?\n\n@sentry/node\n\n### SDK Version\n\n6.19.7\n\n### Framework Version\n\n6.19.7\n\n### Link to Sentry event\n\n_No response_\n\n### Steps to Reproduce\n\nIntegrate sentry with an existing express app. \r\nUse this to list routes:\r\n\r\n```js\r\nimport path from 'path'\r\n\r\nfunction getPathFromRegex(regexp) {\r\n return regexp\r\n .toString()\r\n .replace('/^', '')\r\n .replace('?(?=\\\\/|$)/i', '')\r\n .replace(/\\\\\\//g, '/')\r\n}\r\n\r\nfunction combineStacks(acc, stack) {\r\n if (stack.handle.stack) {\r\n const routerPath = getPathFromRegex(stack.regexp)\r\n return [\r\n ...acc,\r\n ...stack.handle.stack.map((stack) => ({ routerPath, ...stack })),\r\n ]\r\n }\r\n return [...acc, stack]\r\n}\r\n\r\nfunction getStacks(app) {\r\n // Express 3\r\n if (app.routes) {\r\n // convert to express 4\r\n return Object.keys(app.routes)\r\n .reduce((acc, method) => [...acc, ...app.routes[method]], [])\r\n .map((route) => ({ route: { stack: [route] } }))\r\n }\r\n\r\n // Express 4\r\n if (app._router && app._router.stack) {\r\n return app._router.stack.reduce(combineStacks, [])\r\n }\r\n\r\n // Express 4 Router\r\n if (app.stack) {\r\n return app.stack.reduce(combineStacks, [])\r\n }\r\n\r\n // Express 5\r\n if (app.router && app.router.stack) {\r\n return app.router.stack.reduce(combineStacks, [])\r\n }\r\n\r\n return []\r\n}\r\n\r\nfunction listRoutes(app) {\r\n const stacks = getStacks(app)\r\n const routes = []\r\n\r\n if (stacks) {\r\n for (const stack of stacks) {\r\n if (stack.route) {\r\n const routeLogged = {}\r\n for (const route of stack.route.stack) {\r\n const method = route.method ? route.method.toUpperCase() : null\r\n if (!routeLogged[method] && method) {\r\n const stackPath =\r\n stack.routerPath || route.path\r\n ? path.resolve(\r\n [stack.routerPath, stack.route.path, route.path]\r\n .filter((s) => !!s)\r\n .join('')\r\n )\r\n : stack.route.path\r\n routes.push({ verb: method, path: stackPath })\r\n routeLogged[method] = true\r\n }\r\n }\r\n }\r\n }\r\n }\r\n return routes\r\n}\r\n\r\nexport default listRoutes\r\n```\n\n### Expected Result\n\nroutes listed and returned\n\n### Actual Result\n\nafter integration with Sentry, all route information disappears.\r\n","author":{"url":"https://github.com/jondot","@type":"Person","name":"jondot"},"datePublished":"2022-05-07T16:11:17Z","url":"https://github.com/getsentry/sentry-javascript/issues/5050"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:97499d89-13f1-7f86-3440-4913c488adea |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A768:1567FF:62C9B3:85E95C:6B0441C3 |
| html-safe-nonce | f1ec35d85c54ffcf33a989fdd6667f76251356d4f72e1f4d71cbcac25ec78ba0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzY4OjE1NjdGRjo2MkM5QjM6ODVFOTVDOjZCMDQ0MUMzIiwidmlzaXRvcl9pZCI6IjQ5NjIxMzY4MTAyMDI2MTIxNjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 21afee0b2acaf005eb831bdb435b37f9c4ffa970936169e30b403e3fed9392eb |
| hovercard-subject-tag | issue:1228663829 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/5050/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8a0f01c3d53d6baaa80638c740f6568b3756a9f976bec17304ecaf52429c5ab0/getsentry/sentry-javascript/issues/5050 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8a0f01c3d53d6baaa80638c740f6568b3756a9f976bec17304ecaf52429c5ab0/getsentry/sentry-javascript/issues/5050 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jondot |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9185ccfefd80c1ff2d9ddcdb0cd2becf46b5a1efbbf30741a895e4bb8de25e64 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 06dc448a76fe4751ac1db26524aefa3aa3e889a8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width