Skip to content

Commit cf811c1

Browse files
suhailopensourcenicohrubec
authored andcommitted
fix(v10/core): Store child span timeout handle in _childSpanTimeoutID
Backport of: #23429
1 parent e3db9fa commit cf811c1

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎packages/core/src/tracing/idleSpan.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export function startIdleSpan(startSpanOptions: StartSpanOptions, options: Parti
245245
*/
246246
function _restartChildSpanTimeout(endTimestamp?: number): void {
247247
_cancelChildSpanTimeout();
248-
_idleTimeoutID = setTimeout(() => {
248+
_childSpanTimeoutID = setTimeout(() => {
249249
if (!_finished && _autoFinishAllowed) {
250250
_finishReason = FINISH_REASON_HEARTBEAT_FAILED;
251251
span.end(endTimestamp);

‎packages/core/test/lib/tracing/idleSpan.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,29 @@ describe('startIdleSpan', () => {
765765
expect(spanToJSON(idleSpan).timestamp).toBeDefined();
766766
});
767767

768+
it('measures the idle timeout from the last child end, not from the auto-finish signal', () => {
769+
const idleSpan = startIdleSpan({ name: 'idle span' }, { disableAutoFinish: true, finalTimeout: 99_999 });
770+
const idleSpanId = idleSpan.spanContext().spanId;
771+
772+
const child = startInactiveSpan({ name: 'inner' });
773+
774+
vi.advanceTimersByTime(500);
775+
getClient()!.emit('idleSpanEnableAutoFinish', idleSpan);
776+
777+
vi.advanceTimersByTime(700);
778+
child!.end();
779+
780+
vi.advanceTimersByTime(TRACING_DEFAULTS.idleTimeout - 199);
781+
expect(spanToJSON(idleSpan).timestamp).toBeUndefined();
782+
783+
const lateChild = startInactiveSpan({ name: 'late' });
784+
expect(spanToJSON(lateChild!).parent_span_id).toBe(idleSpanId);
785+
786+
lateChild!.end();
787+
vi.advanceTimersByTime(TRACING_DEFAULTS.idleTimeout);
788+
expect(spanToJSON(idleSpan).timestamp).toBeDefined();
789+
});
790+
768791
it('times out at final timeout if disableAutoFinish=true', () => {
769792
const idleSpan = startIdleSpan({ name: 'idle span' }, { disableAutoFinish: true });
770793
expect(idleSpan).toBeDefined();

0 commit comments

Comments
 (0)