Title: Sentry.logger.* ignores scope parameter in non-template string case · Issue #18318 · getsentry/sentry-javascript · GitHub
Open Graph Title: Sentry.logger.* ignores scope parameter in non-template string case · Issue #18318 · getsentry/sentry-javascript
X Title: Sentry.logger.* ignores scope parameter in non-template string case · Issue #18318 · 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/18318
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Sentry.logger.* ignores scope parameter in non-template string case","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\n10.25.0\n\n### Framework Version\n\n_No response_\n\n### Link to Sentry event\n\n_No response_\n\n### Reproduction Example/SDK Setup\n\n_No response_\n\n### Steps to Reproduce\n\nEnvironment\nPackage: @sentry/node (and @sentry/node-core)\n\nDescription\nWhen using Sentry.logger.info() (or other log methods) with a custom scope in a non-template string call, the scope parameter in the metadata object is ignored. This makes it impossible to use Sentry Logs with a manual NodeClient setup in shared environments (like VS Code Extension Host).\n\nSteps to reproduce\n```import { NodeClient, Scope } from '@sentry/node';\n\n// Manual client setup (recommended for shared environments)\nconst client = new NodeClient({ dsn: '...', enableLogs: true, ... });\nconst isolatedScope = new Scope();\nisolatedScope.setClient(client);\nclient.init();\n\n// Try to log with the isolated scope\nSentry.logger.info('Test message', { key: 'value' }, { scope: isolatedScope });\n// Expected: Log sent using isolatedScope's client\n// Actual: Log is NOT sent (scope is ignored, falls back to global scope which has no client)\n```\n\n\n\n### Expected Result\n\n// Expected: Log sent using isolatedScope's client\n\n### Actual Result\n\n// Actual: Log is NOT sent (scope is ignored, falls back to global scope which has no client)\n\n### Additional Context\n\nLikely Root Cause (found by AI)\nIn @sentry/node-core/src/logs/capture.ts, the captureLog function incorrectly accesses the scope:\n\n```\nfunction captureLog(level, ...args) {\n const [messageOrMessageTemplate, paramsOrAttributes, maybeAttributesOrMetadata, maybeMetadata] = args;\n if (Array.isArray(paramsOrAttributes)) {\n // Template string case (4 args): messageTemplate, params[], attributes, metadata\n core._INTERNAL_captureLog({ ... }, maybeMetadata?.scope); // ✅ Correct\n } else {\n // Non-template case (3 args): message, attributes, metadata\n core._INTERNAL_captureLog({ ... }, maybeMetadata?.scope); // ❌ BUG!\n }\n}\nfunction captureLog(level, ...args) { const [messageOrMessageTemplate, paramsOrAttributes, maybeAttributesOrMetadata, maybeMetadata] = args; if (Array.isArray(paramsOrAttributes)) { // Template string case (4 args): messageTemplate, params[], attributes, metadata core._INTERNAL_captureLog({ ... }, maybeMetadata?.scope); // ✅ Correct } else { // Non-template case (3 args): message, attributes, metadata core._INTERNAL_captureLog({ ... }, maybeMetadata?.scope); // ❌ BUG! }}\n```\n\nIn the non-template case:\nargs[2] (maybeAttributesOrMetadata) contains the metadata with { scope }\nargs[3] (maybeMetadata) is undefined\nThe code uses maybeMetadata?.scope which is undefined\n\n\n\nExpected Fix (Recommended by AI)\n```\n} else {\n core._INTERNAL_captureLog(\n { level, message: messageOrMessageTemplate, attributes: paramsOrAttributes },\n maybeAttributesOrMetadata?.scope, // Use the correct variable\n );\n}\n} else { core._INTERNAL_captureLog( { level, message: messageOrMessageTemplate, attributes: paramsOrAttributes }, maybeAttributesOrMetadata?.scope, // Use the correct variable );}\n```\n\nWorkaround\nUse _INTERNAL_captureLog directly:\n```\nimport { _INTERNAL_captureLog } from '@sentry/core';\n\n_INTERNAL_captureLog({ level: 'info', message: 'Test', attributes: {} }, isolatedScope);\nimport { _INTERNAL_captureLog } from '@sentry/core';_INTERNAL_captureLog({ level: 'info', message: 'Test', attributes: {} }, isolatedScope);\n``\n\nImpact\nThis bug prevents using Sentry Logs in any environment that requires a manual client setup with isolated scopes, such as:\nVS Code extensions (shared Extension Host process)\nServerless functions with multiple tenants\nAny application needing client isolation\n\n### Priority\n\n\u003csub>React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it.\u003c/sub>","author":{"url":"https://github.com/puneet-ekline","@type":"Person","name":"puneet-ekline"},"datePublished":"2025-11-25T01:41:09Z","url":"https://github.com/getsentry/sentry-javascript/issues/18318"}
| 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:15a7ac40-6850-babe-f4ed-235691bc4ab7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9FCA:1FD1:114ECD7:175FFE4:6B042FC3 |
| html-safe-nonce | 3a679edcfb54ac6c625293077c62425dc788b522e8213b49e20d12ed9212ceae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkNBOjFGRDE6MTE0RUNENzoxNzVGRkU0OjZCMDQyRkMzIiwidmlzaXRvcl9pZCI6IjI0Njc0NDIxMzkwNjg2NDEyMTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7609f7950410a747df67d064723722bc91a28a62f2674dc0cf6bd82dea080a64 |
| hovercard-subject-tag | issue:3661163291 |
| 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/18318/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2964fbcd2c0c07be4072f248fae0a6f1926d72f599c9d670ba5a712eef580c66/getsentry/sentry-javascript/issues/18318 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2964fbcd2c0c07be4072f248fae0a6f1926d72f599c9d670ba5a712eef580c66/getsentry/sentry-javascript/issues/18318 |
| 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 | puneet-ekline |
| 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