Title: MongoDB Integration: find method not measured correctly. · Issue #4495 · getsentry/sentry-javascript · GitHub
Open Graph Title: MongoDB Integration: find method not measured correctly. · Issue #4495 · getsentry/sentry-javascript
X Title: MongoDB Integration: find method not measured correctly. · Issue #4495 · getsentry/sentry-javascript
Description: Official Sentry SDKs for JavaScript. Contribute to getsentry/sentry-javascript development by creating an account on GitHub.
Open Graph Description: Official Sentry SDKs for JavaScript. Contribute to getsentry/sentry-javascript development by creating an account on GitHub.
X Description: Official Sentry SDKs for JavaScript. Contribute to getsentry/sentry-javascript development by creating an account on GitHub.
Opengraph URL: https://github.com/getsentry/sentry-javascript
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"MongoDB Integration: find method not measured correctly. ","articleBody":"## Package + Version\r\n\r\n\"@sentry/node\": \"6.17.3\",\r\n\r\n## Description\r\n\r\nMongo's methods which return a Cursor doesn't measured correctly. \r\nLet's go thru an example: \r\n\r\n```typescript\r\nconst span = Sentry.getCurrentHub().getScope().getTransaction().startChild({\r\n op: 'fetching',\r\n description: 'Scenario Events'\r\n});\r\nconst response = await this.collection.find({ scenario_id: tripId }).sort({ st: 1 }).toArray();\r\nspan.finish();\r\n```\r\n\r\nThis will reported to the Sentry like this (this is example from our real app, so the op and description may vary): \r\n\r\n\r\nFirst row in a screenshot is an outer span, and second row is timing from integration. The actual time for query execution is showed in the first line. \r\n\r\n### Root Cause\r\nThe mongo's integration doesn't know anything about cursors. It's just trying to decorate all top level client async methods with instreumentation code. So in case of `find` method which is synchronously returning `FindCursor` instead of promise it's just measure time of this sync operation instead of query.\r\n\r\n```typescript\r\n// getsentry/sentry-javascript/packages/tracing/src/integrations/node/mongo.ts\r\n const maybePromise = orig.call(this, ...args) as Promise\u003cunknown>;\r\n if (isThenable(maybePromise)) {\r\n return maybePromise.then((res: unknown) => {\r\n span?.finish();\r\n return res;\r\n });\r\n } else {\r\n span?.finish();\r\n return maybePromise;\r\n }\r\n }\r\n```\r\n\r\n### Proposed Solution\r\nDecorate Async Cursor methods, or return wrapped Cursor with instrumentation. \r\n\r\n### Motivation\r\nIn our application we use find/findOne = 90/10 so built-in integration for mongo just don't work for a most of the cases","author":{"url":"https://github.com/timofei-iatsenko","@type":"Person","name":"timofei-iatsenko"},"datePublished":"2022-02-03T09:02:54Z","url":"https://github.com/getsentry/sentry-javascript/issues/4495"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:b15f5593-7974-ef1a-4b2d-05824d93bee2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E68C:35E323:B8E2C3:1037E8C:6B04386D |
| html-safe-nonce | f345c70d9f3e9d6291cf0c58b5eb4deb64d78175b6ecaf6b80e35e2f22d56056 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjhDOjM1RTMyMzpCOEUyQzM6MTAzN0U4Qzo2QjA0Mzg2RCIsInZpc2l0b3JfaWQiOiI3NDE3ODYxMTUxNDEwODk0OTU3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 3b74b75013a2362e5d7d9b012671dbc64b14168650eb932358cd882aa711d081 |
| hovercard-subject-tag | repository:3328572 |
| 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/getsentry/sentry-javascript/issues/4495 |
| twitter:image | https://repository-images.githubusercontent.com/3328572/1b73c77d-6488-4ece-9e12-e61d9eb2ac2b |
| twitter:card | summary_large_image |
| og:image | https://repository-images.githubusercontent.com/3328572/1b73c77d-6488-4ece-9e12-e61d9eb2ac2b |
| og:image:alt | Official Sentry SDKs for JavaScript. Contribute to getsentry/sentry-javascript development by creating an account on GitHub. |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9185ccfefd80c1ff2d9ddcdb0cd2becf46b5a1efbbf30741a895e4bb8de25e64 |
| turbo-cache-control | no-cache |
| 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