* Evict pending spans older than STALE_SPAN_TTL_MS. * Mirrors the TTL cleanup pattern in sessionTracing.ts.
()
| 185 | * Mirrors the TTL cleanup pattern in sessionTracing.ts. |
| 186 | */ |
| 187 | function 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). |
no test coverage detected