Added shutddown event to flush buffer and set content length (tracy-safe)