Description
Problem Statement
Hi there, I wanted to flag an issue where my deeper GraphQL queries take exponentially longer when using Sentry. This looks to be because Sentry logic ends up blocking the main thread
As you can see above, logic within @sentry/opentelemetry is taking up more than 50% of time on the main thread over the period of over 15s. With Sentry disabled, the same GraphQL request takes about 2 seconds.
Solution Brainstorm
System clock lookups
The following code is the worst offender
function shouldCleanupSpan(span, maxStartTimeOffsetSeconds) {
const cutoff = Date.now() / 1000 - maxStartTimeOffsetSeconds;
return core.spanTimeInputToSeconds(span.startTime) < cutoff;
}
Specifically the cutoff
assignment. I'd propose something like the following where there is only one system clock read for each call of _cleanupOldSpans
.
_cleanupOldSpans(spans = this._finishedSpans) {
// Get current time (once)
const currentEpoch = Math.floor(Date.now() / 1000);
this._finishedSpans = spans.filter(span => {
const shouldDrop = core.spanTimeInputToSeconds(span.startTime) < currentEpoch - this._timeout);
DEBUG_BUILD &&
shouldDrop &&
utils.logger.log(
`SpanExporter dropping span ${span.name} (${
span.spanContext().spanId
}) because it is pending for more than 5 minutes.`,
);
return !shouldDrop;
});
}
Metadata
Metadata
Assignees
Type
Projects
Status
Waiting for: Community