-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(browser): Add setActiveSpanInBrowser
to set an active span in the browser
#17714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
size-limit report 📦
|
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
setSpanActive
to create an active root span in the browsersetSpanActive
to set an active root span in the browser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it! Only one thing, the name - would it make sense to use a browser-specific naming to make it clearer this only exists there? not 100% sure, but something like:
Sentry.makeActiveSpanInBrowser(span)
Sentry.browserSetActiveSpan(span)
or something in this direction? Just wondering because I can see folks writing in "why is this not exported in node" etc 😅
970c2f0
to
f941afc
Compare
Yeah I get the point. I tried to come up with a name that's less "unergonomic" but it always sounds complicated. But maybe that's a good thing with this API though 😅 . Let's go with |
setSpanActive
to set an active root span in the browsersetActiveSpanInBrowser
to set an active root span in the browser
setActiveSpanInBrowser
to set an active root span in the browsersetActiveSpanInBrowser
to set an active span in the browser
…15007) <!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Adds documentation for `Sentry. setActiveSpanInBrowser(span)` which is added via getsentry/sentry-javascript#17714. To be merged only after the feature was released. This is still based on #15006 because I need the `availableSince` prop on the `SdkApi` component. closes https://linear.app/getsentry/issue/FE-608/docs-for-setspanactive ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/) --------- Co-authored-by: Shannon Anahata <shannon.anahata@gmail.com>
This PR adds a long-requested feature to the browser SDKs (only!): Making an inactive span active. We do this to enable use cases where having a span only being active in the callback is not practical (see #13495 for examples).
There are a couple of caveats to this feature:
setActiveSpanInBrowser
on a nested child span, will make that child span the active span as long as it is active. However, due toparentSpanIsAlwaysRootSpan
defaulting totrue
any child span of the active child span, will still be parented to the root span. By settingparentSpanIsAlwaysRootSpan: false
, the span hierarchy is respected and child spans are correctly parented to the active span. Note that this cannot be guaranteed to work perfectly, due to missing async context in the browser. See tests for theparentSpanIsAlwaysRootSpan
behaviour.Span
to be passed tosetActiveSpanInBrowser
.Technically,
setActiveSpanInBrowser
uses_setSpanForScope
which I decided to re-export from core as_INTERNAL_setSpanForScope
, similarly to how we do it with logs APIs.Usage
This example shows one of the most frequent use cases where having an active, callback-unbound span is useful:
closes #13495