Skip to content
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

Allow to create spans as children of specific spans #12539

Closed
mydea opened this issue Jun 19, 2024 · 1 comment · Fixed by #12567
Closed

Allow to create spans as children of specific spans #12539

mydea opened this issue Jun 19, 2024 · 1 comment · Fixed by #12567

Comments

@mydea
Copy link
Member

mydea commented Jun 19, 2024

It is possible today, with the new APIs, to create a span as a child of a specific other span:

const child = Sentry.withActiveSpan(parent, () => Sentry.startInactiveSpan(...));

However, this is not super intuitive for users. We should provide some helper/utility/way to do this easier.

I see two main ways we could do this:

  1. Create a new method, like Sentry.startInactiveChildSpan(parent, spanOptions)
  2. Add an optional parentSpan option to all startSpan* methods:
Sentry.startSpan({ name: 'xxx', parentSpan: parent }, () => {});
const span = Sentry.startInactiveSpan({ name: 'xxx', parentSpan: parent });

I think I'd tend to the second option, and we should be able to implement this both for core as well as for otel.

@s1gr1d
Copy link
Member

s1gr1d commented Jun 19, 2024

I am also in favor of the 2nd option, as having too many APIs would make everything more complex to use (as you need to think of even more different APIs which do quite similar things).

@mydea mydea self-assigned this Jun 19, 2024
mydea added a commit that referenced this issue Jun 20, 2024
With this PR, you can now pass a `parentSpan` optionally to `startSpan*`
APIs to create a span as a child of a specific span:


```js
const span = Sentry.startInactiveSpan({ name: 'xxx', parentSpan: parent });

Sentry.startSpan({ name: 'xxx', parentSpan: parent }, () => {});

Sentry.startSpanManual({ name: 'xxx', parentSpan: parent }, () => {});
```

With this, it should be easier to understand how you can manually work
with spans in v8.

Closes #12539

ref #12566, which I
noticed while working on this. For now I just cast the span which should
be fine, but is not ideal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants