Skip to content

Commit ee0fa54

Browse files
committed
add unit tests
1 parent 410ca15 commit ee0fa54

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/browser/src/tracing/setSpanActive.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Span } from '@sentry/core';
2-
import { _INTERNAL_setSpanForScope, getActiveSpan, getCurrentScope } from '@sentry/core';
2+
import { _INTERNAL_setSpanForScope, addNonEnumerableProperty, getActiveSpan, getCurrentScope } from '@sentry/core';
33

44
/**
55
* Sets an inactive span active on the current scope.
@@ -40,6 +40,14 @@ import { _INTERNAL_setSpanForScope, getActiveSpan, getCurrentScope } from '@sent
4040
export function setSpanActive(span: Span): void {
4141
const maybePreviousActiveSpan = getActiveSpan();
4242

43+
// If the span is already active, there's no need to double-patch or set it again.
44+
// This also guards against users (for whatever reason) calling setSpanActive on SDK-started
45+
// idle spans like pageload or navigation spans. These will already be handled correctly by the SDK.
46+
// For nested situations, we have to double-patch to ensure we restore the correct previous span (see tests)
47+
if (maybePreviousActiveSpan === span) {
48+
return;
49+
}
50+
4351
const scope = getCurrentScope();
4452

4553
// Putting a small patch onto the span.end method to ensure we

0 commit comments

Comments
 (0)