getsentry/sentry-javascript

Allow to create spans as children of specific spans

Closed this issue · 1 comments

mydea commented

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.

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