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

perf(export): do not allocate arrays if resource has no pending async attributes #4550

Merged
merged 4 commits into from
Mar 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
perf(eport): do not allocate arrays if resource has no pending async …
…attributes
  • Loading branch information
Samuron authored and Ievgen Makukh committed Mar 17, 2024
commit c5b52e270bac95f74f970283ecc875070b49c71c
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,24 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
);
}
});
const pendingResources = spans
.map(span => span.resource)
.filter(resource => resource.asyncAttributesPending);

let pendingResources: Array<Promise<void>> | null = null;
for (let i = 0, len = spans.length; i < len; i++) {
const span = spans[i];
if (
span.resource.asyncAttributesPending &&
span.resource.waitForAsyncAttributes
) {
pendingResources ??= [];
pendingResources.push(span.resource.waitForAsyncAttributes());
}
}

// Avoid scheduling a promise to make the behavior more predictable and easier to test
if (pendingResources.length === 0) {
if (pendingResources === null) {
doExport();
} else {
Promise.all(
pendingResources.map(
resource => resource.waitForAsyncAttributes?.()
)
).then(doExport, err => {
Promise.all(pendingResources).then(doExport, err => {
globalErrorHandler(err);
reject(err);
});
Expand Down