fix(tracing): Ensure sent spans are limited to 1000#12252
Merged
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.
lforst
reviewed
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) |
Contributor
There was a problem hiding this comment.
.sort() is not pure and will mutate the array. I would recommend shallow cloning the array first and making this very explicit.
Member
Author
There was a problem hiding this comment.
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!
Member
Author
There was a problem hiding this comment.
I added a comment here (and also in the other place) to be explicit about this! :)
Contributor
size-limit report 📦
|
lforst
approved these changes
May 28, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.