| 116 | } |
| 117 | |
| 118 | async shutdown(options: TelemetryShutdownOptions = {}): Promise<void> { |
| 119 | const sink = this.sink; |
| 120 | if (sink === null) return; |
| 121 | sink.stopPeriodicFlush(); |
| 122 | if (options.timeoutMs === undefined) { |
| 123 | await sink.flush(); |
| 124 | return; |
| 125 | } |
| 126 | const controller = new AbortController(); |
| 127 | const timer = setTimeout(() => { |
| 128 | controller.abort(); |
| 129 | }, options.timeoutMs); |
| 130 | timer.unref?.(); |
| 131 | try { |
| 132 | await sink.flush(controller.signal); |
| 133 | } catch { |
| 134 | sink.flushSync(); |
| 135 | } finally { |
| 136 | clearTimeout(timer); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | resetForTests(): void { |
| 141 | this.sink?.stopPeriodicFlush(); |