Skip to content
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

ref(opentelemetry): Avoid sampling work for non-root spans #15820

Merged
merged 2 commits into from
Mar 26, 2025

Conversation

mydea
Copy link
Member

@mydea mydea commented Mar 25, 2025

Related to #15725 (comment)

When a span is not a root span, we do not need to do sampling work for it. By reordering stuff in the shouldSample function, we should be able to save a bunch of operations for the vast majority of (non-root) spans.

I think this should be just fine!

@mydea mydea requested review from lforst and AbhiPrasad March 25, 2025 10:39
@mydea mydea self-assigned this Mar 25, 2025
@mydea mydea changed the title ref: Avoid sampling work for non-root spans ref(opentelemetry): Avoid sampling work for non-root spans Mar 25, 2025
// We only sample based on parameters (like tracesSampleRate or tracesSampler) for root spans (which is done in sampleSpan).
// Non-root-spans simply inherit the sampling decision from their parent.
if (!isRootSpan) {
return wrapSamplingDecision({
Copy link
Member

Choose a reason for hiding this comment

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

Don't we have to run this._client.emit('beforeSampling' for this as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so, we only use this (today) in Next.js, where I assume this is for root spans:

// There are situations where the Next.js Node.js server forwards requests for the Edge Runtime server (e.g. in
    // middleware) and this causes spans for Sentry ingest requests to be created. These are not exempt from our tracing
    // because we didn't get the chance to do `suppressTracing`, since this happens outside of userland.
    // We need to drop these spans.

cc @lforst ?

Copy link
Member

Choose a reason for hiding this comment

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

Looks fine to me! If you want to confirm you can look at the dumps from the E2E tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean all the tests are passing, I would assume something would fail if this breaks it :) (and sampling should not be applied to child spans anyhow, so this should be fine!)

@mydea mydea force-pushed the fn/streamline-sampling-spans branch from a1f2f91 to f47b0d8 Compare March 26, 2025 09:58
@mydea mydea merged commit ef2f35d into develop Mar 26, 2025
103 of 104 checks passed
@mydea mydea deleted the fn/streamline-sampling-spans branch March 26, 2025 16:17
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.

3 participants