Skip to content

fix(tracing): Ensure sent spans are limited to 1000 #12252

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 2 commits into from
May 28, 2024
Merged

Conversation

mydea
Copy link
Member

@mydea mydea commented May 28, 2024

To avoid too large payloads, we should only send up to 1000 spans.

We actually had two different problems here in browser and node:

  1. In browser, we did limit to 1000, but we did so in an unfortunate way, which is to reset the set after 1000 spans. So if a span had 1010 children, only the last 10 would be send.
  2. In node, we just sent all spans.

I rewrote this to now consistently send the first 1000 spans of a transaction.

I decided to keep all spans (no matter the limit) on the internal parent-child map. Due to this this may grow a lot, but we can avoid inconsistent state (e.g. what happens if a span has a parent in the map, but the parent does not have the span as children, ...)
All of these should be garbage collected together ideally, so this should be fine hopefully.

To avoid too large payloads, we should only send up to 1000 spans.

We actually had two different problems here in browser and node:

1. In browser, we _did_ limit to 1000, but we did so in an unfortunate way, which is to reset the set after 1000 spans. So if a span had 1010 children, only the last 10 would be send.
2. In node, we just sent all spans.

I rewrote this to now consistently send the first 1000 spans of a transaction.
@mydea mydea requested review from lforst, Lms24 and andreiborza May 28, 2024 08:12
@mydea mydea self-assigned this May 28, 2024
transactionEvent.spans = spans;
transactionEvent.spans =
spans.length > MAX_SPAN_COUNT
? spans.sort((a, b) => a.start_timestamp - b.start_timestamp).slice(0, MAX_SPAN_COUNT)
Copy link
Contributor

Choose a reason for hiding this comment

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

.sort() is not pure and will mutate the array. I would recommend shallow cloning the array first and making this very explicit.

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 know, but here we already have a copy of an array that is not used anywhere else, so this is safe and "slightly more efficient". But I can leave a comment to make this clear!

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 added a comment here (and also in the other place) to be explicit about this! :)

Copy link
Contributor

github-actions bot commented May 28, 2024

size-limit report 📦

Path Size
@sentry/browser 21.78 KB (0%)
@sentry/browser (incl. Tracing) 32.8 KB (+0.04% 🔺)
@sentry/browser (incl. Tracing, Replay) 68.27 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 61.7 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay with Canvas) 72.33 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) 84.38 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback, metrics) 85.86 KB (+0.02% 🔺)
@sentry/browser (incl. metrics) 23.17 KB (0%)
@sentry/browser (incl. Feedback) 37.8 KB (0%)
@sentry/browser (incl. sendFeedback) 26.36 KB (0%)
@sentry/browser (incl. FeedbackAsync) 30.79 KB (0%)
@sentry/react 24.5 KB (0%)
@sentry/react (incl. Tracing) 35.83 KB (+0.04% 🔺)
@sentry/vue 25.76 KB (+0.1% 🔺)
@sentry/vue (incl. Tracing) 34.61 KB (+0.06% 🔺)
@sentry/svelte 21.92 KB (0%)
CDN Bundle 23.01 KB (0%)
CDN Bundle (incl. Tracing) 34.29 KB (+0.04% 🔺)
CDN Bundle (incl. Tracing, Replay) 68.09 KB (+0.02% 🔺)
CDN Bundle (incl. Tracing, Replay, Feedback) 73.11 KB (+0.03% 🔺)
CDN Bundle - uncompressed 67.88 KB (0%)
CDN Bundle (incl. Tracing) - uncompressed 101.74 KB (+0.07% 🔺)
CDN Bundle (incl. Tracing, Replay) - uncompressed 211.64 KB (+0.03% 🔺)
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 224.02 KB (+0.03% 🔺)
@sentry/nextjs (client) 35.15 KB (+0.04% 🔺)
@sentry/sveltekit (client) 33.4 KB (+0.03% 🔺)
@sentry/node 114.65 KB (+0.02% 🔺)
@sentry/aws-serverless 103.33 KB (+0.02% 🔺)

@mydea mydea merged commit 38bd57b into develop May 28, 2024
106 checks passed
@mydea mydea deleted the fn/span-limit branch May 28, 2024 08:49
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