Skip to content

Add API to browser SDKs to set span active on scope #13807

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

Open
Lms24 opened this issue Sep 26, 2024 · 0 comments
Open

Add API to browser SDKs to set span active on scope #13807

Lms24 opened this issue Sep 26, 2024 · 0 comments
Labels
Improvement Package: browser Issues related to the Sentry Browser SDK

Comments

@Lms24
Copy link
Member

Lms24 commented Sep 26, 2024

Problem Statement

Currently there's no great way in browser SDKs to start a (root) span that's

  1. long-running, in the sense of not bound to a callback.
  2. active on the scope, in so far that child spans can be attached to the span.

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

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

const span1 = Sentry.startInactiveSpan(...);
Sentry.startSpan({name: "childOfSpan1", () => {....}};
span1.end();

// Result:
// span1 is its a root span w/o child span
// childOfSpan1 is a root span

Solution Brainstorm

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

const span1 = Sentry.startInactiveSpan(...);
Sentry.setSpanActiveOnCurrentScope(rootSpan);

Sentry.startSpan({name: "childOfSpan1", () => {....}};
span1.end();


// Result: 
// span1 is a root span
// childOfSpan1 is a child of span 1 (lol)

Out of scope for this issue

  • Nested child span hierarchy (currently not reliably possible in browser)
  • Exporting startIdleSpan
    • Making a startInactiveSpan- created span become active is the more versatile approach as opposed to idleSpans. We can think about exporting startIdleSpan additionally.
  • 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Package: browser Issues related to the Sentry Browser SDK
Projects
None yet
Development

No branches or pull requests

3 participants