#Span with parent null
4 messages · Page 1 of 1 (latest)
When you create a span with parentSpan: null and forceTransaction: true, Sentry will treat it as a transaction and display it as such in the UI:
const transaction = Sentry.startInactiveSpan({
name: "transaction",
forceTransaction: true,
parentSpan: null,
});
This is the correct approach to ensure a span is treated as a transaction, even if it is not the root span of an existing trace. This is documented in the migration guides and API docs for the new Sentry JavaScript SDK v8.x [source].
However, you are observing that some events still appear as spans under other transactions. This can happen due to how Sentry associates spans and transactions within a trace. If there is an existing active trace context (for example, from a page load or navigation), your new transaction may still share the same trace ID as the existing transaction, leading to multiple root transactions within the same trace. This is a known behavior and has been discussed in Sentry's GitHub issues. Specifically, even with forceTransaction: true, the SDK may group multiple root transactions under the same trace if they share the same propagation context, resulting in the "multiple root transactions" warning in the UI [source].
In summary:
- Setting
parentSpan: nullandforceTransaction: truedoes create a new transaction. - If there is an existing trace context, your new transaction may still be grouped under the same trace, causing some events to appear as spans of other transactions.
- This is expected behavior in the current SDK and is related to how trace IDs are managed and propagated.
If you want each transaction to be completely independent (not grouped under the same trace), you may need to ensure that a new trace context is started, but the current SDK does not provide a straightforward way to fully isolate traces in all scenarios. This limitation is acknowledged in the Sentry community discussions [source].
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@limber hazel Our robots are still learning and improving, please let us know if this response was correct by reacting below.