Skip to content

Commit 4535c08

Browse files
logaretmclaude
andcommitted
fix(elysia): improve span filtering for function handlers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 924cd63 commit 4535c08

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

packages/elysia/src/withElysia.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,18 @@ export function withElysia<T extends Elysia>(app: T, options?: Partial<ElysiaHan
9999
});
100100

101101
// Filter out the empty spans we marked above before sending the transaction,
102-
// then clear the set to avoid unbounded memory growth.
102+
// and delete matched IDs individually to avoid clearing IDs from concurrent transactions.
103103
client.on('beforeSendEvent', event => {
104104
if (event.type === 'transaction' && event.spans) {
105-
event.spans = event.spans.filter(span => !emptySpanIds.has(span.span_id));
106-
emptySpanIds.clear();
105+
event.spans = event.spans.filter(span => {
106+
if (!emptySpanIds.has(span.span_id)) {
107+
return true;
108+
}
109+
110+
emptySpanIds.delete(span.span_id);
111+
112+
return false;
113+
});
107114
}
108115
});
109116
}

0 commit comments

Comments
 (0)