-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref: Collect child spans references via non-enumerable on Span object #10715
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
Changes from 6 commits
fd8ad0a
8e150aa
e760fe9
44d1670
ffd1208
55ab311
7883c03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -156,6 +156,10 @@ export function startInactiveSpan(context: StartSpanOptions): Span | undefined { | |||||
}); | ||||||
} | ||||||
|
||||||
if (parentSpan) { | ||||||
addChildSpanToSpan(parentSpan, span); | ||||||
} | ||||||
|
||||||
setCapturedScopesOnSpan(span, scope, isolationScope); | ||||||
|
||||||
return span; | ||||||
|
@@ -307,6 +311,10 @@ function createChildSpanOrTransaction( | |||||
}); | ||||||
} | ||||||
|
||||||
if (parentSpan) { | ||||||
addChildSpanToSpan(parentSpan, span); | ||||||
} | ||||||
|
||||||
setCapturedScopesOnSpan(span, scope, isolationScope); | ||||||
|
||||||
return span; | ||||||
|
@@ -330,6 +338,46 @@ function normalizeContext(context: StartSpanOptions): TransactionContext { | |||||
return context; | ||||||
} | ||||||
|
||||||
const CHILD_SPANS_FIELD = '_sentryChildSpans'; | ||||||
|
||||||
type SpanWithPotentialChildren = Span & { | ||||||
[CHILD_SPANS_FIELD]?: Set<Span>; | ||||||
}; | ||||||
|
||||||
/** | ||||||
* Adds an opaque child span reference to a span. | ||||||
*/ | ||||||
export function addChildSpanToSpan(span: SpanWithPotentialChildren, childSpan: Span): void { | ||||||
if (span[CHILD_SPANS_FIELD] && span[CHILD_SPANS_FIELD].size < 1000) { | ||||||
span[CHILD_SPANS_FIELD].add(childSpan); | ||||||
} else { | ||||||
span[CHILD_SPANS_FIELD] = new Set([childSpan]); | ||||||
} | ||||||
} | ||||||
|
||||||
/** | ||||||
* Obtains the entire span tree, meaning a span + all of its descendants for a particular span. | ||||||
*/ | ||||||
export function getSpanTree(span: SpanWithPotentialChildren): Span[] { | ||||||
const resultSet = new Set<Span>(); | ||||||
|
||||||
function recurse(span: SpanWithPotentialChildren): void { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I'd name this a bit more expressively here? |
||||||
if (resultSet.has(span)) { | ||||||
return; | ||||||
} else { | ||||||
resultSet.add(span); | ||||||
const childSpans = span[CHILD_SPANS_FIELD] ? Array.from(span[CHILD_SPANS_FIELD]) : []; | ||||||
for (const childSpan of childSpans) { | ||||||
recurse(childSpan); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
recurse(span); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
return Array.from(resultSet); | ||||||
} | ||||||
|
||||||
const SCOPE_ON_START_SPAN_FIELD = '_sentryScope'; | ||||||
const ISOLATION_SCOPE_ON_START_SPAN_FIELD = '_sentryIsolationScope'; | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.