(newSink: AnalyticsSink)
| 93 | * the default command) without coordination. |
| 94 | */ |
| 95 | export function attachAnalyticsSink(newSink: AnalyticsSink): void { |
| 96 | if (sink !== null) { |
| 97 | return |
| 98 | } |
| 99 | sink = newSink |
| 100 | |
| 101 | // Drain the queue asynchronously to avoid blocking startup |
| 102 | if (eventQueue.length > 0) { |
| 103 | const queuedEvents = [...eventQueue] |
| 104 | eventQueue.length = 0 |
| 105 | |
| 106 | // Log queue size for ants to help debug analytics initialization timing |
| 107 | if (process.env.USER_TYPE === 'ant') { |
| 108 | sink.logEvent('analytics_sink_attached', { |
| 109 | queued_event_count: queuedEvents.length, |
| 110 | }) |
| 111 | } |
| 112 | |
| 113 | queueMicrotask(() => { |
| 114 | for (const event of queuedEvents) { |
| 115 | if (event.async) { |
| 116 | void sink!.logEventAsync(event.eventName, event.metadata) |
| 117 | } else { |
| 118 | sink!.logEvent(event.eventName, event.metadata) |
| 119 | } |
| 120 | } |
| 121 | }) |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Log an event to analytics backends (synchronous) |
no outgoing calls
no test coverage detected