-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref(node): Improve span flushing #16577
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
base: develop
Are you sure you want to change the base?
Conversation
size-limit report 📦
|
this._flushTimeout = setTimeout(() => { | ||
this.flush(); | ||
}, 1); | ||
if (!localParentId || this._sentSpans.has(localParentId)) { |
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.
should we also run cleanup on sent spans here (the _flushSentSpanCache
method)?
The _sentSpans
is checked for both flush and export, but only cleaned up in flush.
}; | ||
type CallbackFunction = () => unknown; | ||
type DebounceOptions = { | ||
maxWait?: number; |
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.
maxWait
needs a comment.
const finishedSpans: ReadableSpan[] = this._finishedSpanBuckets.flatMap(bucket => | ||
bucket ? Array.from(bucket.spans) : [], | ||
); |
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.
The intermediate array creation + flatMap
usage is probably pretty expensive as well.
const finishedSpans: ReadableSpan[] = this._finishedSpanBuckets.flatMap(bucket => | |
bucket ? Array.from(bucket.spans) : [], | |
); | |
const finishedSpans: ReadableSpan[] = []; | |
for (const bucket of this._finishedSpanBuckets) { | |
if (bucket) { | |
for (const span of bucket.spans) { | |
finishedSpans.push(span); | |
} | |
} | |
} |
Follow up to #16416, slightly moving things around and making some small improvements to performance and logic (some not related to that PR but another improvement we noticed when BYK looked int this):
isSpanAlreadySent
has been called for every single span that ended, it is quite high impact, and meant a little bit of additional work (although it should not necessarily run too often, but still). Instead, we now simply check formap.has(id)
which should be good enough for what we want to achieve, IMHO. We still clean up the sent spans when flushing, so old stuff should still go away eventually.For this I moved the already existing
debounce
function from replay to core. We re-implement this in replay with a different setTimeout impl. which is needed for some angular stuff.