MCPcopy
hub / github.com/codeaashu/claude-code / evictStaleSpans

Function evictStaleSpans

src/utils/telemetry/perfettoTracing.ts:187–209  ·  view source on GitHub ↗

* Evict pending spans older than STALE_SPAN_TTL_MS. * Mirrors the TTL cleanup pattern in sessionTracing.ts.

()

Source from the content-addressed store, hash-verified

185 * Mirrors the TTL cleanup pattern in sessionTracing.ts.
186 */
187function evictStaleSpans(): void {
188 const now = getTimestamp()
189 const ttlUs = STALE_SPAN_TTL_MS * 1000 // Convert ms to microseconds
190 for (const [spanId, span] of pendingSpans) {
191 if (now - span.startTime > ttlUs) {
192 // Emit an end event so the span shows up in the trace as incomplete
193 events.push({
194 name: span.name,
195 cat: span.category,
196 ph: 'E',
197 ts: now,
198 pid: span.agentInfo.processId,
199 tid: span.agentInfo.threadId,
200 args: {
201 ...span.args,
202 evicted: true,
203 duration_ms: (now - span.startTime) / 1000,
204 },
205 })
206 pendingSpans.delete(spanId)
207 }
208 }
209}
210
211/**
212 * Build the full trace document (Chrome Trace JSON format).

Callers 2

Calls 3

getTimestampFunction · 0.85
deleteMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected