Title: Add API to browser SDKs to set span active on scope · Issue #13807 · getsentry/sentry-javascript · GitHub
Open Graph Title: Add API to browser SDKs to set span active on scope · Issue #13807 · getsentry/sentry-javascript
X Title: Add API to browser SDKs to set span active on scope · Issue #13807 · getsentry/sentry-javascript
Description: Problem Statement Currently there's no great way in browser SDKs to start a (root) span that's long-running, in the sense of not bound to a callback. active on the scope, in so far that child spans can be attached to the span. Of course ...
Open Graph Description: Problem Statement Currently there's no great way in browser SDKs to start a (root) span that's long-running, in the sense of not bound to a callback. active on the scope, in so far that child spans...
X Description: Problem Statement Currently there's no great way in browser SDKs to start a (root) span that's long-running, in the sense of not bound to a callback. active on the scope, in so far that chi...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/13807
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add API to browser SDKs to set span active on scope","articleBody":"### Problem Statement\n\nCurrently there's no great way in browser SDKs to start a (root) span that's \n\n1. long-running, in the sense of not bound to a callback. \n2. active on the scope, in so far that child spans can be attached to the span.\n\nOf course there are workarounds for this problem (i.e. an async long-running callback that in conjunction with an outside of closure variable to access a span outside the callback) but they're far from intuitive and discoverable for users. \n\nThe only way to start a callback-less span at the moment is via `Sentry.startInactiveSpan`. The consequence of this behaviour is that you can't add child spans to this span, meaning the resulting root span/txn won't have any child spans:\n\n```js\nconst span1 = Sentry.startInactiveSpan(...);\nSentry.startSpan({name: \"childOfSpan1\", () => {....}};\nspan1.end();\n\n// Result:\n// span1 is its a root span w/o child span\n// childOfSpan1 is a root span\n```\n\n### Solution Brainstorm\n\nWe should export an API from browser SDKs that allows users to set a span active on the current scope. Naming and API details are subject of discussion but a workflow could look something like this:\n\n```js\nconst span1 = Sentry.startInactiveSpan(...);\nSentry.setSpanActiveOnCurrentScope(rootSpan);\n\nSentry.startSpan({name: \"childOfSpan1\", () => {....}};\nspan1.end();\n\n\n// Result: \n// span1 is a root span\n// childOfSpan1 is a child of span 1 (lol)\n```\n\n### Out of scope for this issue\n\n- Nested child span hierarchy (currently not reliably possible in browser)\n- Exporting `startIdleSpan`\n - Making a `startInactiveSpan`- created span become active is the more versatile approach as opposed to idleSpans. We can think about exporting `startIdleSpan` additionally. \n- Exporting a shim for this API in Node: We can do this on request but for now let's hold off from it and keep it browser-only. This API should and will never work in Node environments, so the only thing we can do is log a warning and no-op other than that.","author":{"url":"https://github.com/Lms24","@type":"Person","name":"Lms24"},"datePublished":"2024-09-26T09:12:42Z","url":"https://github.com/getsentry/sentry-javascript/issues/13807"}
| 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:486839bb-7c5a-caa6-770e-6a1c873ffa38 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB18:121D2B:1030EEC:157AB8E:6B051595 |
| html-safe-nonce | 088ffdb17ac2c19f2872bffdaca6d2745fe28d08a0cafdcc6469b95305e1053e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjE4OjEyMUQyQjoxMDMwRUVDOjE1N0FCOEU6NkIwNTE1OTUiLCJ2aXNpdG9yX2lkIjoiMzM1OTM5MjY3NzYyNzIzNzc4MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | afbac5cb1bde2588bf82c2d8af4712d75cecdb5e12f7471060534cd332761e90 |
| hovercard-subject-tag | issue:2549995093 |
| 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/13807/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2b6c1268bef1d95baad90cd48bfe1a538041991ea73c83ef8ca6610425140deb/getsentry/sentry-javascript/issues/13807 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2b6c1268bef1d95baad90cd48bfe1a538041991ea73c83ef8ca6610425140deb/getsentry/sentry-javascript/issues/13807 |
| og:image:alt | Problem Statement Currently there's no great way in browser SDKs to start a (root) span that's long-running, in the sense of not bound to a callback. active on the scope, in so far that child spans... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Lms24 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 854d880890b5e847b3fce9d1b31f032107baeddeebad2aa379c48aa4f1451f6b |
| 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 | 220e980097d94ce616d5d11fbd5316d208e3fc93 |
| 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