Title: Memory leak on Node 19/20 with `includeLocalVariables` enabled · Issue #14162 · getsentry/sentry-javascript · GitHub
Open Graph Title: Memory leak on Node 19/20 with `includeLocalVariables` enabled · Issue #14162 · getsentry/sentry-javascript
X Title: Memory leak on Node 19/20 with `includeLocalVariables` enabled · Issue #14162 · 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/14162
X: @github
Domain: github.com
IPv4 address: 140.82.113.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Memory leak on Node 19/20 with `includeLocalVariables` enabled","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 SDK are you using?\n\n@sentry/node\n\n### SDK Version\n\n8.36.0\n\n### Framework Version\n\nNode 19.9.0, also tested on Node 20.18.0\n\n### Link to Sentry event\n\nN/A\n\n### Reproduction Example/SDK Setup\n\n```js\nimport * as Sentry from \"@sentry/node\"\n\nimport api from \"@opentelemetry/api\"\n\n\n\nfunction trimData(data) {\n const size = JSON.stringify(data || \"\").length\n\n // Arbitrarily cut off massive payloads. Sentry silently drops events that are too large,\n // so trim them.\n // See https://github.com/getsentry/sentry-javascript/issues/3036#issuecomment-1066491190\n if (size > 200000) {\n return data?.slice(0, 200000)\n }\n\n return data\n}\n\nfunction checkIfSentryIgnore(url) {\n if (!url) return false\n\n for (const route of SENTRY_IGNORED_ROUTES) {\n if (typeof route === \"string\" && url.endsWith(route)) {\n return true\n } else if (route instanceof RegExp && route.test(url)) {\n return true\n }\n }\n}\n\n/**\n * Need to ignore long-running websockets.\n *\n * See: https://github.com/getsentry/sentry-javascript/issues/13412#issuecomment-2340434248\n */\nconst IGNORE_WEBSOCKETS = [\"infura\", \"ws\", \"alchemy\", \"ankr\", \"zora\"]\n\nSentry.init({\n dsn: \"snip\",\n\n // Disable entirely on non-production environments.\n enabled: true,\n debug: !!process.env.SENTRY_DEBUGGING,\n registerEsmLoaderHooks: { exclude: [/openai/] },\n includeLocalVariables: true,\n integrations: [\n Sentry.onUncaughtExceptionIntegration({\n exitEvenIfOtherHandlersAreRegistered: false,\n }),\n Sentry.expressIntegration(),\n Sentry.httpIntegration({\n ignoreOutgoingRequests(url, request) {\n console.log(\"SENTRY: should we ignore outgoing request?\", url)\n for (const route of IGNORE_WEBSOCKETS) {\n if (url.includes(route)) {\n console.log(\"SENTRY: Ignoring outgoing request\", url)\n return true\n }\n }\n\n console.log(\"SENTRY: Not ignoring outgoing request\", url)\n return false\n },\n }),\n ],\n\n release: process.env.COMMIT,\n environment: process.env.FLY_APP_NAME || \"development\",\n\n beforeSendTransaction(event) {\n console.log(\"SENTRY: beforeSendTransaction\", event)\n\n if (event.transaction === \"redis-connect\") {\n // Don't send the event to Sentry\n return null\n }\n\n console.log(\"SENTRY: Sending transaction\", event)\n\n return event\n },\n beforeSend: (event) => {\n console.log(\"SENTRY: beforeSend\", event)\n try {\n if (event.request?.data) {\n event.request.data = trimData(event.request.data)\n }\n if (event.message) {\n event.message = trimData(event.message)\n }\n\n return event\n } catch (e) {\n console.error(\"Error in Sentry beforeSend\", e, event)\n return event\n }\n },\n})\n\n```\n\n### Steps to Reproduce\n\nRun Node 19 or Node 20 with Sentry enabled in my specific setup. The memory gradually increases until an OOM occurs.\n\nThis graph shows when Node was updated from 18 to 19.9.0. No other code changes occurred.\n\n\n\n### Expected Result\n\nMemory does not gradually increase until an OOM occurs.\n\nThis graph shows when I disabled includeLocalVariables in the above Sentry.init: memory stops increasing. \n\n\n\n### Actual Result\n\nMemory increases gradually until it OOMs, if `includeLocalVariables` is enabled.\n\nIf Sentry is disabled entirely, or if the `includeLocalVariables` flag is disabled, then memory looks as expected.\n\nI originally suspected [this](https://github.com/getsentry/sentry-javascript/issues/13412#issuecomment-2340434248) was the issue, since we also use websockets and long-running requests, but after ignoring the requests and confirming via the console.logs that none of the long-running requests got spans created (with the issue still persisting), I tried disabling local variables and that fixed it.\n\nThese are (truncated) logs with trace GC enabled. It's not particularly showing much other than memory growth. [This](https://pastebin.com/ev5T1weD) shows with local variables enabled, and [this](https://pastebin.com/xmPUry35) is with it disabled.","author":{"url":"https://github.com/seeARMS","@type":"Person","name":"seeARMS"},"datePublished":"2024-11-02T04:00:49Z","url":"https://github.com/getsentry/sentry-javascript/issues/14162"}
| 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:543f5b09-abf7-47ec-117b-9a14e6df0178 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A530:298A98:27617D5:3399E33:6B042AC6 |
| html-safe-nonce | d7fb3d60b2b69b8d47e444712b5fd64273e092f302d3f74c18c4e655c07266e4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTMwOjI5OEE5ODoyNzYxN0Q1OjMzOTlFMzM6NkIwNDJBQzYiLCJ2aXNpdG9yX2lkIjoiNDE2Mzc2NzAwNzY1OTE3NDU5OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 01e2f46115be080df5490e8bbecebfe854458147ec2b7332835d00f12146a86e |
| hovercard-subject-tag | issue:2630183017 |
| 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/14162/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fe0761342821f4aa06aebc45ba772b08b894b449f3ed588fbbd12cd5839eedcf/getsentry/sentry-javascript/issues/14162 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fe0761342821f4aa06aebc45ba772b08b894b449f3ed588fbbd12cd5839eedcf/getsentry/sentry-javascript/issues/14162 |
| 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 | seeARMS |
| hostname | github.com |
| expected-hostname | github.com |
| None | b7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e |
| 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 | c3dd496c3da6ea6b77e69c09279d2b81604654f1 |
| 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