Skip to content

feat(core): Replace idle transaction with idle span #9972

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

Closed
wants to merge 2 commits into from

Conversation

mydea
Copy link
Member

@mydea mydea commented Dec 22, 2023

This is a draft, replacing startIdleTransaction with startIdleSpan.

Missing for this is adding tests for this, but wanted to check first if the approach seems good to everyone.

Some notes:

  • I got rid of the onScope option, as we always put it on the scope right now. So no need to expose this for now.
  • This currently depends on "buggy" behavior of startSpanManual in regards to scope forking in Browser. But that's OK I guess This for now still uses scope.setSpan(), we may need to revisit this in v8, but should be OK for now
  • There are some things that still kind of expect a Transaction, API wise. For now I just guard there for this, which should generally be OK as we would still be created transactions under the hood if this is a root span. But it may be a subtle change...

@mydea mydea self-assigned this Dec 22, 2023
idleTimeout: number;
finalTimeout: number;
// TODO FN: Do we need this??
// customSamplingContext?: CustomSamplingContext;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a general thing that already came up - do we need to add this to startSpan somehow? 🤔

*/
export function startIdleSpan(options: IdleSpanOptions): Span | undefined {
// Activities store a list of active spans
const activities = new Map<string, boolean>();
Copy link
Member Author

Choose a reason for hiding this comment

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

Keeping this is a map instead of a POJO, makes cleanup etc. easier!


const FINISH_REASON_TAG = 'finishReason';

const FINISH_REASON_HEARTBEAT_FAILED = 'heartbeatFailed';
Copy link
Member Author

Choose a reason for hiding this comment

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

Rewrote this to proper constants instead of accessing array elements.


DEBUG_BUILD && logger.log('[Tracing] finishing idle span', new Date(endTimestamp * 1000).toISOString(), span.op);

childSpans.forEach(childSpan => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of looking at the spanRecorder of the transaction, we keep the child spans manually here.

}

client.on('spanStart', span => {
if (_finished) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of patching the span recorder, we hook into spanStart and check here if the new span is a (nested) child span of the idle span.

_popActivity(span.spanId);

if (span.spanId === spanId) {
endIdleSpan();
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of monkey-patching end, we instead trigger this here when we detect that we are ending the idle span.

Copy link
Contributor

github-actions bot commented Dec 22, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 75.74 KB (-0.2% 🔽)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 67.08 KB (-0.26% 🔽)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 60.69 KB (-0.31% 🔽)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.67 KB (-0.51% 🔽)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 30.39 KB (0%)
@sentry/browser - Webpack (gzipped) 22.09 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 73.07 KB (-0.32% 🔽)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 64.77 KB (-0.31% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 30.92 KB (-0.66% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped) 23.12 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 202.77 KB (-0.5% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 92.66 KB (-1.07% 🔽)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 68.58 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 33.78 KB (-0.85% 🔽)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 67.5 KB (-0.24% 🔽)
@sentry/react - Webpack (gzipped) 22.12 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 84.12 KB (-0.24% 🔽)
@sentry/nextjs Client - Webpack (gzipped) 48.74 KB (-0.44% 🔽)
@sentry-internal/feedback - Webpack (gzipped) 16.6 KB (0%)

Lms24 added a commit that referenced this pull request Jan 16, 2024
Deprecate the `spanRecorder` field on the `Span` class. For now
there's no replacement yet. I'm not entirely sure how we're going to
keep track of spans within the SDK. #9972 shows an alternative for
`IdleSpan` which no longer seems to rely on the `spanRecorder`. Another
possibility might be to make the recorder private which might be enough,
too.
@mydea mydea closed this Mar 5, 2024
@mydea mydea deleted the fn/browser-idleTransaction branch May 28, 2024 08:53
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.

1 participant