-
-
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
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