René's URL Explorer Experiment


Title: Serverless Function Tracing Needs an Isolated Scope · Issue #3572 · getsentry/sentry-javascript · GitHub

Open Graph Title: Serverless Function Tracing Needs an Isolated Scope · Issue #3572 · getsentry/sentry-javascript

X Title: Serverless Function Tracing Needs an Isolated Scope · Issue #3572 · getsentry/sentry-javascript

Description: Review the documentation: https://docs.sentry.io/ Search for existing issues: https://github.com/getsentry/sentry-javascript/issues Use the latest release: https://github.com/getsentry/sentry-javascript/releases Provide a link to the aff...

Open Graph Description: Review the documentation: https://docs.sentry.io/ Search for existing issues: https://github.com/getsentry/sentry-javascript/issues Use the latest release: https://github.com/getsentry/sentry-javas...

X Description: Review the documentation: https://docs.sentry.io/ Search for existing issues: https://github.com/getsentry/sentry-javascript/issues Use the latest release: https://github.com/getsentry/sentry-javas...

Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/3572

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.3


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Serverless Function Tracing Needs an  Isolated Scope","articleBody":"\u003c!-- Requirements: please go through this checklist before opening a new issue -->\r\n\r\n- [x] Review the documentation: https://docs.sentry.io/\r\n- [x] Search for existing issues: https://github.com/getsentry/sentry-javascript/issues\r\n- [x] Use the latest release: https://github.com/getsentry/sentry-javascript/releases\r\n- [x] Provide a link to the affected event from your Sentry account: https://sentry.io/organizations/par-tech-inc/performance/tdp-log-processing:248e161ab69049b29769dbbe61ed5da6/?transaction=process_generator_sessions\r\n\r\n## Package + Version\r\n\r\n- [x] `@sentry/node` 6.3.6\r\n\r\n### Version:\r\n\r\n```\r\n6.3.6\r\n```\r\n\r\n## Description\r\n\r\nHere is my `withSentry` wrapper for Azure serverless Function invocations:\r\n\r\n```\r\nconst Sentry = require(\"@sentry/node\");\r\nconst Tracing = require(\"@sentry/tracing\");\r\nconst mongodb = require(\"mongodb\");\r\n\r\nconst config = require(\"../../config/sentry\");\r\n\r\nif (config.dsn) {\r\n    Sentry.init({\r\n        ...config,\r\n        integrations: [\r\n            // enable DB calls tracing\r\n            new Tracing.Integrations.Mongo({ useMongoose: true })\r\n            // new Tracing.Integrations.Mysql()  // No integration available for mysql2.\r\n        ]\r\n    });\r\n}\r\n\r\n/**\r\n * Add Sentry transaction information to outgoing messages.\r\n * @param {*} transaction\r\n * @param {*} results\r\n * @returns\r\n */\r\nconst propagateTransaction = (transaction, results) => {\r\n    if (results && transaction) {\r\n        for (const message of Object.values(results)) {\r\n            Object.assign(message, {\r\n                sentryParentSpanId: transaction.spanId,\r\n                sentryTraceId: transaction.traceId,\r\n                sentrySampled: transaction.sampled\r\n            });\r\n        }\r\n    }\r\n    return results;\r\n};\r\n\r\n/**\r\n * A higher order function which logs error data to Sentry.\r\n *\r\n * @param {*} callback          The actual function which might throw errors.\r\n */\r\nmodule.exports = callback => async (context, trigger, ...args) => {\r\n    let transaction;\r\n    if (config.dsn) {\r\n        // Define a transaction for performance tracking.\r\n        const transactionContext = {\r\n            op: \"serverless-task\",\r\n            name: context?.executionContext?.functionName || \"test-function\"\r\n        };\r\n        if (\"sentryParentSpanId\" in trigger) {\r\n            Object.assign(transactionContext, {\r\n                parentSpanId: trigger.sentryParentSpanId,\r\n                traceId: trigger.sentryTraceId,\r\n                sampled: trigger.sentrySampled\r\n            });\r\n        }\r\n        transaction = Sentry.startTransaction(transactionContext);\r\n\r\n        Sentry.configureScope(scope => {\r\n            scope.setSpan(transaction);\r\n            scope.setContext(\r\n                \"executionContext\",\r\n                context?.executionContext || {\r\n                    errorMessage:\r\n                        \"No executionContext defined.  This could be a notification from a test environment.\"\r\n                }\r\n            );\r\n            scope.setContext(\"functionTrigger\", trigger);\r\n        });\r\n    }\r\n\r\n    try {\r\n        return propagateTransaction(\r\n            transaction,\r\n            await callback(context, trigger, ...args)\r\n        );\r\n    } catch (error) {\r\n        if (config.dsn) {\r\n            Sentry.captureException(error, scope => {\r\n                scope.setContext(\r\n                    \"executionContext\",\r\n                    context?.executionContext || {\r\n                        errorMessage:\r\n                            \"No executionContext defined.  This could be a notification from a test environment.\"\r\n                    }\r\n                );\r\n                scope.setContext(\"functionTrigger\", trigger);\r\n                scope.setContext(\r\n                    \"theFullContext\",\r\n                    Object.assign(\r\n                        {},\r\n                        ...Object.keys(context).map(k => ({\r\n                            [k]: JSON.stringify(context[k])\r\n                        }))\r\n                    )\r\n                );\r\n            });\r\n            scope.setSpan(transaction);\r\n            await Sentry.flush();\r\n        }\r\n\r\n        throw error;\r\n    } finally {\r\n        await transaction?.finish();\r\n    }\r\n};\r\n```\r\n\r\nDefining an Azure Function like this: \r\n\r\n```\r\nmodule.exports = withSentry(processLogFile);\r\n```\r\n\r\nThis logs everything correctly for exceptions since the scope is set immediately before sending the log, but performance tracing associates DB children with the wrong span and other context.  This appears to be because the DB integrations use the span set on the scope.  Since we have a high volume application (on the order of 3400 invocations per minute), many function invocations run concurrently and, since `Sentry.configureScope()` configures the span in a global scope, logged child DB transactions are associated not with the invocation they actually ran during but instead with context of the function invocation that last called `Sentry.configureScope()`.  In these images, there are dozens of MongoDB calls associated with the *_sessions function even though the inserts are actually all called by the parent *_timeseries function:\r\n![image](https://user-images.githubusercontent.com/5413632/118860481-72351f80-b8a9-11eb-99a4-8ae75434729b.png)\r\n![image](https://user-images.githubusercontent.com/5413632/118860883-e2dc3c00-b8a9-11eb-8cce-e02249a524a5.png)\r\n\r\n","author":{"url":"https://github.com/derekrprice","@type":"Person","name":"derekrprice"},"datePublished":"2021-05-19T17:59:09Z","url":"https://github.com/getsentry/sentry-javascript/issues/3572"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:61965484-a817-9413-849d-7d510d0a3815
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDB56:3977D7:10D30F:170158:6B04B14D
html-safe-nonce1ee53a2e4b068e196b83f898c391bc1e3040ea57afb827e5f627d79a44cff149
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjU2OjM5NzdENzoxMEQzMEY6MTcwMTU4OjZCMDRCMTREIiwidmlzaXRvcl9pZCI6IjgxODYwOTAzMjUxNjk5NzU2MjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac08c85c270deceeca10b747b87de8c8336b09e389baace92e1f7f2bd2a579e546
hovercard-subject-tagissue:895728221
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/3572/issue_layout
twitter:imagehttps://opengraph.githubassets.com/1f134c96a05b5b60d3a2aaa93712af650c3866ed45e3035ec950f8584cb2ee8e/getsentry/sentry-javascript/issues/3572
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/1f134c96a05b5b60d3a2aaa93712af650c3866ed45e3035ec950f8584cb2ee8e/getsentry/sentry-javascript/issues/3572
og:image:altReview the documentation: https://docs.sentry.io/ Search for existing issues: https://github.com/getsentry/sentry-javascript/issues Use the latest release: https://github.com/getsentry/sentry-javas...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamederekrprice
hostnamegithub.com
expected-hostnamegithub.com
Nonef1d110ea058a0915c1d8aa3fc2069fa15801e128f591e5762525abe77490ecb1
turbo-cache-controlno-preview
go-importgithub.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git
octolytics-dimension-user_id1396951
octolytics-dimension-user_logingetsentry
octolytics-dimension-repository_id3328572
octolytics-dimension-repository_nwogetsentry/sentry-javascript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id3328572
octolytics-dimension-repository_network_root_nwogetsentry/sentry-javascript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseffa22a65e4c46d376940fe34b05e6a7e9c7fdb9b
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/getsentry/sentry-javascript/issues/3572#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-javascript%2Fissues%2F3572
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-javascript%2Fissues%2F3572
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=getsentry%2Fsentry-javascript
Reloadhttps://github.com/getsentry/sentry-javascript/issues/3572
Reloadhttps://github.com/getsentry/sentry-javascript/issues/3572
Reloadhttps://github.com/getsentry/sentry-javascript/issues/3572
getsentryhttps://github.com/getsentry
sentry-javascripthttps://github.com/getsentry/sentry-javascript
Codehttps://github.com/getsentry/sentry-javascript
Issues333 (333)https://github.com/getsentry/sentry-javascript/issues
Pull requests49 (49)https://github.com/getsentry/sentry-javascript/pulls
Discussionshttps://github.com/getsentry/sentry-javascript/discussions
Actionshttps://github.com/getsentry/sentry-javascript/actions
Security and quality7 (7)https://github.com/getsentry/sentry-javascript/security
Insightshttps://github.com/getsentry/sentry-javascript/insights
https://github.com/getsentry/sentry-javascript
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/3572
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/3572
Serverless Function Tracing Needs an Isolated Scopehttps://github.com/getsentry/sentry-javascript/issues/3572#top
https://github.com/derekrprice
derekrpricehttps://github.com/derekrprice
on May 19, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issue-895728221
https://docs.sentry.io/https://docs.sentry.io/
https://github.com/getsentry/sentry-javascript/issueshttps://github.com/getsentry/sentry-javascript/issues
https://github.com/getsentry/sentry-javascript/releaseshttps://github.com/getsentry/sentry-javascript/releases
https://sentry.io/organizations/par-tech-inc/performance/tdp-log-processing:248e161ab69049b29769dbbe61ed5da6/?transaction=process_generator_sessionshttps://sentry.io/organizations/par-tech-inc/performance/tdp-log-processing:248e161ab69049b29769dbbe61ed5da6/?transaction=process_generator_sessions
https://user-images.githubusercontent.com/5413632/118860481-72351f80-b8a9-11eb-99a4-8ae75434729b.png
https://user-images.githubusercontent.com/5413632/118860883-e2dc3c00-b8a9-11eb-8cce-e02249a524a5.png
derekrpricehttps://github.com/derekrprice
Status: Needs Triagehttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Status%3A%20Needs%20Triage%22
on May 19, 2021https://github.com/getsentry/sentry-javascript/issues/3572#event-4768394297
https://github.com/derekrprice
derekrpricehttps://github.com/derekrprice
on May 19, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-844352900
https://github.com/derekrprice
derekrpricehttps://github.com/derekrprice
on May 19, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-844377985
https://github.com/derekrprice
derekrpricehttps://github.com/derekrprice
on May 20, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-845237281
https://github.com/derekrprice
derekrpricehttps://github.com/derekrprice
on May 20, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-845237935
https://user-images.githubusercontent.com/5413632/119010197-ce5b7a80-b961-11eb-8cf2-799a3600c5d7.png
https://github.com/derekrprice
derekrpricehttps://github.com/derekrprice
on May 24, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-847023699
https://github.com/derekrprice
derekrpricehttps://github.com/derekrprice
on May 24, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-847039306
https://github.com/kamilogorek
kamilogorekhttps://github.com/kamilogorek
on May 25, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-847730269
https://github.com/getsentry/sentry-javascript/blob/master/packages/serverless/src/awslambda.ts#L267-L287https://github.com/getsentry/sentry-javascript/blob/master/packages/serverless/src/awslambda.ts#L267-L287
https://github.com/derekrprice
derekrpricehttps://github.com/derekrprice
on May 25, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-847954815
https://github.com/richardsimko
richardsimkohttps://github.com/richardsimko
on Sep 2, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-911851217
https://github.com/derekrprice
derekrpricehttps://github.com/derekrprice
on Sep 2, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-911872553
@richardsimkohttps://github.com/richardsimko
https://github.com/richardsimko
richardsimkohttps://github.com/richardsimko
on Sep 2, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-911879320
https://docs.sentry.io/platforms/javascript/enriching-events/scopes/#whats-a-scope-whats-a-hubhttps://docs.sentry.io/platforms/javascript/enriching-events/scopes/#whats-a-scope-whats-a-hub
https://github.com/derekrprice
derekrpricehttps://github.com/derekrprice
on Sep 2, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-911895239
https://github.com/CesarLanderos
CesarLanderoshttps://github.com/CesarLanderos
on Sep 10, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-916526941
@derekrpricehttps://github.com/derekrprice
https://nodejs.org/api/async_context.htmlhttps://nodejs.org/api/async_context.html
AbhiPrasadhttps://github.com/AbhiPrasad
Package: nodehttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Package%3A%20node%22
Type: Bughttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Type%3A%20Bug%22
on Oct 4, 2021https://github.com/getsentry/sentry-javascript/issues/3572#event-5403499699
getsantryhttps://github.com/apps/getsantry
Status: Untriagedhttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Status%3A%20Untriaged%22
on Oct 4, 2021https://github.com/getsentry/sentry-javascript/issues/3572#event-5403499789
https://github.com/andreialecu
andreialecuhttps://github.com/andreialecu
on Oct 19, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-946677008
#4071https://github.com/getsentry/sentry-javascript/issues/4071
https://github.com/derekrprice
derekrpricehttps://github.com/derekrprice
on Oct 19, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-946826973
@richardsimkohttps://github.com/richardsimko
#4071https://github.com/getsentry/sentry-javascript/issues/4071
https://github.com/apps/github-actions
github-actionshttps://github.com/apps/github-actions
on Nov 9, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-964275812
github-actionshttps://github.com/apps/github-actions
Status: Stalehttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Status%3A%20Stale%22
on Nov 9, 2021https://github.com/getsentry/sentry-javascript/issues/3572#event-5590707688
https://github.com/derekrprice
derekrpricehttps://github.com/derekrprice
on Nov 9, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-964368525
AbhiPrasadhttps://github.com/AbhiPrasad
Status: Backloghttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Status%3A%20Backlog%22
Status: Stalehttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Status%3A%20Stale%22
on Nov 11, 2021https://github.com/getsentry/sentry-javascript/issues/3572#event-5605035865
https://github.com/mattfysh
mattfyshhttps://github.com/mattfysh
on Dec 23, 2021https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-1000244736
HazAThttps://github.com/HazAT
Package: serverlesshttps://github.com/getsentry/sentry-javascript/issues?q=state%3Aopen%20label%3A%22Package%3A%20serverless%22
on Jan 25, 2023https://github.com/getsentry/sentry-javascript/issues/3572#event-8355670032
https://github.com/AbhiPrasad
AbhiPrasadhttps://github.com/AbhiPrasad
on Apr 14, 2023https://github.com/getsentry/sentry-javascript/issues/3572#issuecomment-1508338681
7.48.0https://github.com/getsentry/sentry-javascript/releases/tag/7.48.0
https://docs.sentry.io/platforms/node/configuration/async-context/https://docs.sentry.io/platforms/node/configuration/async-context/
AbhiPrasadhttps://github.com/AbhiPrasad
completedhttps://github.com/getsentry/sentry-javascript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Apr 14, 2023https://github.com/getsentry/sentry-javascript/issues/3572#event-9006766167
Sign up for freehttps://github.com/signup?return_to=https://github.com/getsentry/sentry-javascript/issues/3572
Sign in to commenthttps://github.com/login?return_to=https://github.com/getsentry/sentry-javascript/issues/3572
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.