-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
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.
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) |
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.
.sort() is not pure and will mutate the array. I would recommend shallow cloning the array first and making this very explicit.
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.
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!
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.
I added a comment here (and also in the other place) to be explicit about this! :)
size-limit report 📦
|
To avoid too large payloads, we should only send up to 1000 spans.
We actually had two different problems here in browser and node:
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.