Skip to content

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

Merged
merged 7 commits into from
Feb 20, 2024

Conversation

lforst
Copy link
Contributor

@lforst lforst commented Feb 19, 2024

Instead of relying on a transactions span recorder when starting spans we are tracking child spans via a non-enumerable on the parent span.

Copy link
Contributor

github-actions bot commented Feb 19, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 77.91 KB (+0.1% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 69.18 KB (+0.13% 🔺)
@sentry/browser (incl. Tracing, Replay with Canvas) - Webpack (gzipped) 73.11 KB (+0.13% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 62.76 KB (+0.15% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 33.36 KB (+0.25% 🔺)
@sentry/browser (incl. browserTracingIntegration) - Webpack (gzipped) 33.28 KB (+0.26% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 31.18 KB (0%)
@sentry/browser (incl. sendFeedback) - Webpack (gzipped) 31.18 KB (+0.01% 🔺)
@sentry/browser - Webpack (gzipped) 22.43 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 76.26 KB (+0.09% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 67.77 KB (+0.1% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 33.69 KB (+0.22% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 24.8 KB (+0.19% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 213.25 KB (+0.07% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 101.87 KB (+0.14% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 74.33 KB (+0.13% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 37 KB (+0.26% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 69.51 KB (+0.12% 🔺)
@sentry/react - Webpack (gzipped) 22.46 KB (+0.01% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 86.98 KB (+0.11% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 50.18 KB (+0.17% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 17.16 KB (+0.02% 🔺)

@lforst lforst changed the title ref: Collect child spans references via non-enumerable on Span obj ref: Collect child spans references via non-enumerable on Span object Feb 19, 2024
@lforst lforst marked this pull request as ready for review February 19, 2024 13:10
@lforst lforst requested a review from mydea February 19, 2024 13:10
@@ -401,6 +402,8 @@ export class SentrySpan implements SpanInterface {
childSpan.spanRecorder.add(childSpan);
}

addChildSpanReferenceToSpan(childSpan, this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: nit, but I think I would prefer an order of parent, child, for the arguments 🤔 Makes it a bit easier to reason about IMHO... also the reference is a bit redundant here I'd say, what about:

addChildSpanToSpan(span, childSpan);

but no strong feelings, I'm also OK with what is currently here!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

@lforst lforst requested a review from mydea February 19, 2024 15:58
@@ -401,6 +402,8 @@ export class SentrySpan implements SpanInterface {
childSpan.spanRecorder.add(childSpan);
}

addChildSpanToSpan(this, childSpan);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
addChildSpanToSpan(this, childSpan);
// For now, we capture this here as well in order to ensure backwards compatibility
// eventually this will only be captured in `startSpan` methods
addChildSpanToSpan(this, childSpan);

Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some small nits, but overall looks great to me 👍

export function getSpanTree(span: SpanWithPotentialChildren): Span[] {
const resultSet = new Set<Span>();

function recurse(span: SpanWithPotentialChildren): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function recurse(span: SpanWithPotentialChildren): void {
function addSpanChildren(span: SpanWithPotentialChildren): void {

I'd name this a bit more expressively here?

resultSet.add(span);
const childSpans = span[CHILD_SPANS_FIELD] ? Array.from(span[CHILD_SPANS_FIELD]) : [];
for (const childSpan of childSpans) {
recurse(childSpan);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
recurse(childSpan);
addSpanChildren(childSpan);

}
}

recurse(span);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
recurse(span);
addSpanChildren(span);

@lforst lforst merged commit 658d6d1 into develop Feb 20, 2024
@lforst lforst deleted the lforst-collect-child-spans branch February 20, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants