Title: [@sentry/tracing][express] Span is lost for last middleware · Issue #3001 · getsentry/sentry-javascript · GitHub
Open Graph Title: [@sentry/tracing][express] Span is lost for last middleware · Issue #3001 · getsentry/sentry-javascript
X Title: [@sentry/tracing][express] Span is lost for last middleware · Issue #3001 · getsentry/sentry-javascript
Description: issue It happens because of event finish order. In handler: https://github.com/getsentry/sentry-javascript/blob/master/packages/node/src/handlers.ts#L65 In express https://github.com/getsentry/sentry-javascript/blob/master/packages/traci...
Open Graph Description: issue It happens because of event finish order. In handler: https://github.com/getsentry/sentry-javascript/blob/master/packages/node/src/handlers.ts#L65 In express https://github.com/getsentry/sent...
X Description: issue It happens because of event finish order. In handler: https://github.com/getsentry/sentry-javascript/blob/master/packages/node/src/handlers.ts#L65 In express https://github.com/getsentry/sent...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/3001
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[@sentry/tracing][express] Span is lost for last middleware","articleBody":"### issue\r\nIt happens because of event `finish` order.\r\nIn handler:\r\nhttps://github.com/getsentry/sentry-javascript/blob/master/packages/node/src/handlers.ts#L65\r\nIn express\r\nhttps://github.com/getsentry/sentry-javascript/blob/master/packages/tracing/src/integrations/express.ts#L121\r\n\r\nThe `handlers` listener fires before `express`, as result the last spin has been filtered in:\r\nhttps://github.com/getsentry/sentry-javascript/blob/master/packages/tracing/src/transaction.ts#L90\r\nbecause the last span still doesn't have the `endTimestamp`\r\n\r\n### 2 options to fix this issue:\r\n\r\n1. use `close` listener instead of `finish` in `handlers.ts`. The `close` event runs after `finish`.\r\n```ts\r\nres.once('close', () => {\r\n transaction.setHttpStatus(res.statusCode);\r\n transaction.finish();\r\n});\r\n```\r\n2. finish all spans if `transaction.finish();` runs\r\n```ts\r\nconst finishedSpans = this.spanRecorder ? this.spanRecorder.spans\r\n .reduce((spans, s) => {\r\n !s.endTimestamp && s.finish();\r\n s !== this && spans.push(s);\r\n\r\n return spans;\r\n }, []) : [];\r\n```\r\n\r\nLet me know which option is best for you.","author":{"url":"https://github.com/xr0master","@type":"Person","name":"xr0master"},"datePublished":"2020-10-25T15:16:10Z","url":"https://github.com/getsentry/sentry-javascript/issues/3001"}
| 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:e2089ede-ef60-066d-dc45-8c62de1f7a2c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8534:27DDD:4AADE0:66DC35:6B045537 |
| html-safe-nonce | 408243d0b0513618a0e9b5be1cf7f086ff2a840ade9b4555cd6aade767c00480 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTM0OjI3REREOjRBQURFMDo2NkRDMzU6NkIwNDU1MzciLCJ2aXNpdG9yX2lkIjoiNDkzOTE3MDQzNDY1OTkzMTQ0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 872a9dfbb94eac55dbf962ba3e0f5a1473f179782d8dce0a318d79f75c004c05 |
| hovercard-subject-tag | issue:729042888 |
| 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/3001/issue_layout |
| twitter:image | https://opengraph.githubassets.com/847caaae32acc826c1f5346549e1807bac18ceb4f572c9f10cb750c287d0c853/getsentry/sentry-javascript/issues/3001 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/847caaae32acc826c1f5346549e1807bac18ceb4f572c9f10cb750c287d0c853/getsentry/sentry-javascript/issues/3001 |
| og:image:alt | issue It happens because of event finish order. In handler: https://github.com/getsentry/sentry-javascript/blob/master/packages/node/src/handlers.ts#L65 In express https://github.com/getsentry/sent... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | xr0master |
| hostname | github.com |
| expected-hostname | github.com |
| None | 910ca0e260cfec6aff11407d8dc6a0d3a4cd381a2ec9ada56627b063426892a0 |
| 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 | e086f9b7e88322eb2b41885a6ad425b215737fa5 |
| 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